diff options
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) +} |