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

60 lines
898 B
Go

package tui
import (
tea "github.com/charmbracelet/bubbletea/v2"
)
type page int
const (
pageList = iota + 1
)
type mainModel struct {
page page
listPage listModel
isQuitting bool
}
func newMainModel() mainModel {
return mainModel{
page: pageList,
listPage: newListModel(),
}
}
func (m mainModel) Init() tea.Cmd {
return m.listPage.Init()
}
func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "ctrl+c", "ctrl+q":
m.isQuitting = true
return m, tea.Quit
}
}
switch m.page {
case pageList:
model, cmd := m.listPage.Update(msg)
m.listPage = model.(listModel)
return m, cmd
}
return m, nil
}
func (m mainModel) View() string {
switch {
case m.isQuitting:
return "Quitting..."
case m.page == pageList:
return m.listPage.View()
default:
return "..."
}
}