Commit 132cc54772

132cc5477278c3d68fbd510d3a4d10c468985afd

parent: 0a4302b649

Unsigned

Wraient <wraient.911@gmail.com> · 2024-10-22 11:35 UTC

Add: ExitCurd()

Layout: unified · split

internal/curd.go +9 −4
@@ -79,6 +79,11 @@ func RestoreScreen() {
79 fmt.Print("\033[?1049l") // Switch back to the main screen buffer 79 fmt.Print("\033[?1049l") // Switch back to the main screen buffer
80} 80}
81 81
82func ExitCurd() {
83 RestoreScreen()
84 os.Exit(0)
85}
86
82func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAnimes *[]Anime, logFile string) { 87func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAnimes *[]Anime, logFile string) {
83 var err error 88 var err error
84 89
@@ -91,10 +96,10 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni
91 // Select anime to watch (Anilist) 96 // Select anime to watch (Anilist)
92 anilistSelectedOption, err := DynamicSelect(animeListMap) 97 anilistSelectedOption, err := DynamicSelect(animeListMap)
93 if anilistSelectedOption.Key == "-1" || anilistSelectedOption.Label == "quit" { 98 if anilistSelectedOption.Key == "-1" || anilistSelectedOption.Label == "quit" {
94 os.Exit(0) 99 ExitCurd()
95 } 100 }
96 if anilistSelectedOption.Label == "add_new" { // Todo: Add new anime 101 if anilistSelectedOption.Label == "add_new" { // Todo: Add new anime
97 os.Exit(0) 102 ExitCurd()
98 } 103 }
99 userQuery := anilistSelectedOption.Label 104 userQuery := anilistSelectedOption.Label
100 anime.AnilistId, err = strconv.Atoi(anilistSelectedOption.Key) 105 anime.AnilistId, err = strconv.Atoi(anilistSelectedOption.Key)
@@ -127,7 +132,7 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni
127 } 132 }
128 if len(animeList) == 0 { 133 if len(animeList) == 0 {
129 fmt.Println("No results found.") 134 fmt.Println("No results found.")
130 os.Exit(0) 135 ExitCurd()
131 } 136 }
132 137
133 // find anime in animeList 138 // find anime in animeList
@@ -139,7 +144,7 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni
139 selectedAllanimeAnime, err := DynamicSelect(animeList) 144 selectedAllanimeAnime, err := DynamicSelect(animeList)
140 if err != nil { 145 if err != nil {
141 fmt.Println("No anime available") 146 fmt.Println("No anime available")
142 os.Exit(0) 147 ExitCurd()
143 } 148 }
144 anime.AllanimeId = selectedAllanimeAnime.Key 149 anime.AllanimeId = selectedAllanimeAnime.Key
145 } 150 }