Skip to content

Commit

Permalink
fix(Tui): using a pointer to struct fixing the select error, and fix the
Browse files Browse the repository at this point in the history
cursor bug
  • Loading branch information
KitsuneSemCalda committed Jan 27, 2024
1 parent f53bf7d commit ae58606
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Tui/searchlabel.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func GetAnimeName() string {
message.ErrorMessage(err.Error())
return ""
}
case <-time.After(time.Second * 10): // Timeout after 10 seconds
p.Send(tea.KeyMsg{Type: tea.KeyCtrlC}) // Send Ctrl+C to the program
case <-time.After(time.Second * 10):
p.Send(tea.KeyMsg{Type: tea.KeyCtrlC})
}
if m.done {
return m.choice
Expand Down
14 changes: 7 additions & 7 deletions Tui/selectAnime.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ type selectAnimeModel struct {
err error
}

func (m selectAnimeModel) Init() tea.Cmd {
func (m *selectAnimeModel) Init() tea.Cmd {
return tea.Batch(tea.ClearScreen)
}

func (m selectAnimeModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m *selectAnimeModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.Type {
Expand All @@ -37,15 +37,14 @@ func (m selectAnimeModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.KeyEnter:
m.choice = m.cursor
return m, tea.Quit

case tea.KeyCtrlC:
os.Exit(0)
}
}
return m, nil
}

func (m selectAnimeModel) View() string {
func (m *selectAnimeModel) View() string {
cursorStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("#00FF00")).Bold(true)
listStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("#FFFFFF"))
s := listStyle.Render("Select the anime:\n")
Expand All @@ -60,21 +59,22 @@ func (m selectAnimeModel) View() string {
}

func SelectAnimes(animes []structure.Anime) int {
m := selectAnimeModel{animes: animes}
m := &selectAnimeModel{animes: animes} // Use um ponteiro para o modelo
p := tea.NewProgram(m)

c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
tea.ClearScreen() // Clean up the terminal's state
tea.ClearScreen()
tea.ShowCursor()
os.Exit(0)
}()

if _, err := p.Run(); err != nil {
if err := p.Start(); err != nil {
message.ErrorMessage(err.Error())
return -1
}

return m.choice
}

0 comments on commit ae58606

Please sign in to comment.