From 028632de277704fe4576e732d4997daa70f25f60 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Wed, 15 Jun 2022 00:08:39 +0530 Subject: added color coding and error handling + other visual appeal --- ui/actions.go | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'ui/actions.go') diff --git a/ui/actions.go b/ui/actions.go index 77afae7..7db5a96 100644 --- a/ui/actions.go +++ b/ui/actions.go @@ -20,35 +20,44 @@ package ui import ( "strings" - "log" + "fmt" + "os" p "github.com/manifoldco/promptui" - // mal "github.com/MikunoNaka/macli/mal" + a "github.com/MikunoNaka/MAL2Go/anime" ) type Action struct { Label string Description string - Method func(int) + Method func(a.Anime) } // only search animes probably only now -func ActionMenu() func(animeId int) { +func ActionMenu(animeIsAdded bool) func(a.Anime) { // TODO: load promptLength from config promptLength := 5 options := []Action { {"Set Status", "Set status for an anime (watching, dropped, etc)", StatusMenu}, - {"Set Episodes", "Set number of episodes watched", StatusMenu}, + {"Set Episodes", "Set number of episodes watched", EpisodeInput}, {"Set Score", "Set score", StatusMenu}, {"Set Rewatching", "Set if rewatching", StatusMenu}, {"Set Times Rewatched", "Set number of times rewatched", StatusMenu}, } + // if anime not in list + if animeIsAdded { + options = append( + options, + Action{"Delete Anime", "Delete Anime From Your MyAnimeList List.", StatusMenu}, + ) + } + template := &p.SelectTemplates { Label: "{{ .Label }}", Active: "{{ .Label | magenta }} {{ .Description | faint }}", Inactive: "{{ .Label }}", - Selected: "{{ .Label }}", + Selected: "{{ .Label | magenta }}", Details: ` ------------------- {{ .Description }} @@ -72,8 +81,8 @@ func ActionMenu() func(animeId int) { res, _, err := prompt.Run() if err != nil { - log.Println(err) - return nil + fmt.Println("Error running actions menu.", err.Error()) + os.Exit(1) } return options[res].Method -- cgit v1.2.3