1
0
mirror of https://github.com/go-task/task.git synced 2025-11-23 22:24:45 +02:00
Files
task/internal/tui/list.go
2025-10-02 14:20:33 -03:00

44 lines
827 B
Go

package tui
import (
"fmt"
"github.com/charmbracelet/bubbles/v2/list"
"github.com/charmbracelet/bubbles/v2/spinner"
tea "github.com/charmbracelet/bubbletea/v2"
)
type listModel struct {
spinner spinner.Model
list list.Model
selectedIndex int
isLoading bool
}
func newListModel() listModel {
return listModel{
spinner: newSpinner(),
list: list.New([]list.Item{}, list.NewDefaultDelegate(), 0, 0),
isLoading: true,
}
}
func (m listModel) Init() tea.Cmd {
return m.spinner.Tick
}
func (m listModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
m.spinner, cmd = m.spinner.Update(msg)
return m, cmd
}
func (m listModel) View() string {
switch {
case m.isLoading:
return fmt.Sprintf("%s %s", m.spinner.View(), "Loading tasks...")
default:
return "todo!"
}
}