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] +}