diff options
author | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-06-15 12:59:22 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-06-15 12:59:22 +0530 |
commit | ab3db8a4ca89293ce0928177e8845d622f13755f (patch) | |
tree | e5331856b39b43cfea422f806aa046b0925e92e4 /ui/episodes.go | |
parent | 5eb7a3cd41826fccdc432d049dd85a31b4b56073 (diff) |
added pretty template for TextInput
Diffstat (limited to 'ui/episodes.go')
-rw-r--r-- | ui/episodes.go | 37 |
1 files changed, 36 insertions, 1 deletions
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) +} |