From ae586067f0ec2f32c631bc028427b727bc3e4f43 Mon Sep 17 00:00:00 2001 From: KitsuneSemCalda Date: Fri, 26 Jan 2024 23:11:16 -0300 Subject: [PATCH] fix(Tui): using a pointer to struct fixing the select error, and fix the cursor bug --- Tui/searchlabel.go | 4 ++-- Tui/selectAnime.go | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Tui/searchlabel.go b/Tui/searchlabel.go index 6506205..24d312a 100644 --- a/Tui/searchlabel.go +++ b/Tui/searchlabel.go @@ -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 diff --git a/Tui/selectAnime.go b/Tui/selectAnime.go index 9c42a39..0c05200 100644 --- a/Tui/selectAnime.go +++ b/Tui/selectAnime.go @@ -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 { @@ -37,7 +37,6 @@ 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) } @@ -45,7 +44,7 @@ func (m selectAnimeModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { 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") @@ -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 }