From e513058ab74fe6ff9171e7aaa43e340de2728229 Mon Sep 17 00:00:00 2001 From: KitsuneSemCalda Date: Sun, 25 Aug 2024 17:44:05 -0300 Subject: [PATCH] impl (adding a tui functions using prompt-ui): add a layer from search animes and select between they --- internal/Tui/search_anime.go | 30 ++++++++++++++++++++++++++++++ internal/Tui/select_anime.go | 27 +++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 internal/Tui/search_anime.go create mode 100644 internal/Tui/select_anime.go diff --git a/internal/Tui/search_anime.go b/internal/Tui/search_anime.go new file mode 100644 index 0000000..fd31ab1 --- /dev/null +++ b/internal/Tui/search_anime.go @@ -0,0 +1,30 @@ +package tui + +import ( + "fmt" + "strings" + + message "animatic-v2/internal/Message" + + "github.com/manifoldco/promptui" +) + +func nameformatter(animeName string) string { + loweredName := strings.ToLower(animeName) + spacelessName := strings.ReplaceAll(loweredName, " ", "-") + return spacelessName +} + +func SearchAnime(Debug bool) string { + prompt := promptui.Prompt{ + Label: "Write the anime name from be searched", + } + + animeName, err := prompt.Run() + + if err != nil && Debug { + message.ErrorMessage(fmt.Sprintf("Occured an unknown error in %s\n", err.Error())) + } + + return nameformatter(animeName) +} diff --git a/internal/Tui/select_anime.go b/internal/Tui/select_anime.go new file mode 100644 index 0000000..b0e80fb --- /dev/null +++ b/internal/Tui/select_anime.go @@ -0,0 +1,27 @@ +package tui + +import ( + "animatic-v2/internal/Structures" + + "github.com/manifoldco/promptui" +) + +func GetAnimeListName(animeList []Structures.Anime) []string { + var animeName []string + for _, r := range animeList { + animeName = append(animeName, r.Name) + } + + return animeName +} + +func SelectAnimes(animeList []Structures.Anime) Structures.Anime { + prompt := promptui.Select{ + Label: "Select the anime from be downloaded", + Items: GetAnimeListName(animeList), + } + + selected, _, _ := prompt.Run() + + return animeList[selected] +}