-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
impl (adding a tui functions using prompt-ui): add a layer from searc…
…h animes and select between they
- Loading branch information
1 parent
80eae83
commit e513058
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
} |