From ab3db8a4ca89293ce0928177e8845d622f13755f Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Wed, 15 Jun 2022 12:59:22 +0530 Subject: added pretty template for TextInput --- ui/status.go | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 5 deletions(-) (limited to 'ui/status.go') diff --git a/ui/status.go b/ui/status.go index 661abe1..11fe5d8 100644 --- a/ui/status.go +++ b/ui/status.go @@ -24,6 +24,7 @@ import ( "os" "github.com/MikunoNaka/macli/mal" a "github.com/MikunoNaka/MAL2Go/anime" + m "github.com/MikunoNaka/MAL2Go/manga" p "github.com/manifoldco/promptui" ) @@ -32,8 +33,7 @@ type StatusOption struct { Status string } -// only search animes probably only now -func StatusMenu(anime a.Anime) { +func AnimeStatusMenu(anime a.Anime) { options := []StatusOption { {"Watching", "watching"}, {"Completed", "completed"}, @@ -67,8 +67,63 @@ func StatusMenu(anime a.Anime) { } promptLabel := "Set Status: " - if anime.MyListStatus.Status != "" { - promptLabel = promptLabel + "(current - " + anime.MyListStatus.Status + ")" + if animeStatus != "" { + promptLabel = promptLabel + "(current - " + animeStatus + ")" + } + + prompt := p.Select { + Label: promptLabel, + Items: options, + Templates: template, + Searcher: searcher, + Size: 5, + } + + res, _, err := prompt.Run() + if err != nil { + fmt.Println("Error running status prompt.", err.Error()) + os.Exit(1) + } + + mal.SetAnimeStatus(anime.Id, options[res].Status) +} + +func MangaStatusMenu(manga m.Manga) { + options := []StatusOption { + {"Reading", "reading"}, + {"Completed", "completed"}, + {"On Hold", "on_hold"}, + {"Dropped", "dropped"}, + {"Plan to Read", "plan_to_read"}, + } + + // highlight current status (if any) + mangaStatus := manga.MyListStatus.Status + if mangaStatus != "" { + for i := range options { + if options[i].Status == mangaStatus { + options[i].Label = options[i].Label + " \x1b[35m\U00002714\x1b[0m" + } + } + } + + template := &p.SelectTemplates { + Label: "{{ .Label }}", + Active: "{{ .Label | magenta }}", + Inactive: "{{ .Label }}", + Selected: "{{ .Label | cyan }}", + } + + // returns true if input == anime title + searcher := func(input string, index int) bool { + status := strings.Replace(strings.ToLower(options[index].Label), " ", "", -1) + input = strings.Replace(strings.ToLower(input), " ", "", -1) + return strings.Contains(status, input) + } + + promptLabel := "Set Status: " + if mangaStatus != "" { + promptLabel = promptLabel + "(current - " + mangaStatus + ")" } prompt := p.Select { @@ -85,5 +140,5 @@ func StatusMenu(anime a.Anime) { os.Exit(1) } - mal.SetStatus(anime.Id, options[res].Status) + mal.SetMangaStatus(manga.Id, options[res].Status) } -- cgit v1.2.3