diff options
author | Vidhu Kant Sharma <vidhukant@protonmail.ch> | 2022-06-15 00:08:39 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@protonmail.ch> | 2022-06-15 00:08:39 +0530 |
commit | 028632de277704fe4576e732d4997daa70f25f60 (patch) | |
tree | 343137fc2b19cb7c9568324a9529218ca6065e49 /ui/status.go | |
parent | 5ac21806f34a7c88d2685420d53cbd585f4b4f3d (diff) |
added color coding and error handling + other visual appeal
Diffstat (limited to 'ui/status.go')
-rw-r--r-- | ui/status.go | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/ui/status.go b/ui/status.go index 762bfd8..661abe1 100644 --- a/ui/status.go +++ b/ui/status.go @@ -20,8 +20,10 @@ package ui import ( "strings" - "log" + "fmt" + "os" "github.com/MikunoNaka/macli/mal" + a "github.com/MikunoNaka/MAL2Go/anime" p "github.com/manifoldco/promptui" ) @@ -31,7 +33,7 @@ type StatusOption struct { } // only search animes probably only now -func StatusMenu(animeId int) { +func StatusMenu(anime a.Anime) { options := []StatusOption { {"Watching", "watching"}, {"Completed", "completed"}, @@ -40,11 +42,21 @@ func StatusMenu(animeId int) { {"Plan to Watch", "plan_to_watch"}, } + // highlight current status (if any) + animeStatus := anime.MyListStatus.Status + if animeStatus != "" { + for i := range options { + if options[i].Status == animeStatus { + options[i].Label = options[i].Label + " \x1b[35m\U00002714\x1b[0m" + } + } + } + template := &p.SelectTemplates { Label: "{{ .Label }}", Active: "{{ .Label | magenta }}", Inactive: "{{ .Label }}", - Selected: "{{ .Label }}", + Selected: "{{ .Label | cyan }}", } // returns true if input == anime title @@ -54,8 +66,13 @@ func StatusMenu(animeId int) { return strings.Contains(status, input) } + promptLabel := "Set Status: " + if anime.MyListStatus.Status != "" { + promptLabel = promptLabel + "(current - " + anime.MyListStatus.Status + ")" + } + prompt := p.Select { - Label: "Set Status:", + Label: promptLabel, Items: options, Templates: template, Searcher: searcher, @@ -64,9 +81,9 @@ func StatusMenu(animeId int) { res, _, err := prompt.Run() if err != nil { - log.Println(err) - return + fmt.Println("Error running status prompt.", err.Error()) + os.Exit(1) } - mal.SetStatus(animeId, options[res].Status) + mal.SetStatus(anime.Id, options[res].Status) } |