Skip to content

Commit

Permalink
impl (adding a tui functions using prompt-ui): add a layer from searc…
Browse files Browse the repository at this point in the history
…h animes and select between they
  • Loading branch information
KitsuneSemCalda committed Aug 25, 2024
1 parent 80eae83 commit e513058
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
30 changes: 30 additions & 0 deletions internal/Tui/search_anime.go
Original file line number Diff line number Diff line change
@@ -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)
}
27 changes: 27 additions & 0 deletions internal/Tui/select_anime.go
Original file line number Diff line number Diff line change
@@ -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]
}

0 comments on commit e513058

Please sign in to comment.