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/episodes.go | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'ui/episodes.go') diff --git a/ui/episodes.go b/ui/episodes.go index 53c1cb9..d4c3791 100644 --- a/ui/episodes.go +++ b/ui/episodes.go @@ -25,7 +25,7 @@ import ( "errors" "github.com/MikunoNaka/macli/mal" a "github.com/MikunoNaka/MAL2Go/anime" - // m "github.com/MikunoNaka/MAL2Go/manga" + m "github.com/MikunoNaka/MAL2Go/manga" p "github.com/manifoldco/promptui" ) @@ -63,3 +63,38 @@ func EpisodeInput(anime a.Anime) { mal.SetEpisodes(anime.Id, res) } + +func ChapterInput(manga m.Manga) { + validate := func(input string) error { + if _, err := strconv.ParseFloat(input, 64); err != nil { + return errors.New("Input must be a number.") + } + return nil + } + + template := &p.PromptTemplates { + Valid: "\x1b[0m{{ . | magenta }}", + Invalid: "\x1b[0m{{ . | magenta }}\x1b[31m ", + Success: "{{ . | cyan }}", + } + + prompt := p.Prompt { + Label: "Set Chapter Number: ", + Templates: template, + Validate: validate, + } + + // print current chapter number if any + chNum := manga.MyListStatus.ChaptersRead + if chNum != 0 { + fmt.Printf("\x1b[33mYou currently have read %d chapters.\n\x1b[0m", chNum) + } + + res, err := prompt.Run() + if err != nil { + fmt.Println("Error Running chapter input Prompt.", err.Error()) + os.Exit(1) + } + + mal.SetChapters(manga.Id, res) +} -- cgit v1.2.3