Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Tui): using a pointer to struct fixing the select error, and fix the #7

Merged
merged 1 commit into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading