mirror of
https://github.com/go-task/task.git
synced 2025-11-23 22:24:45 +02:00
feat: getting starting with a tui
This commit is contained in:
59
internal/tui/main.go
Normal file
59
internal/tui/main.go
Normal file
@@ -0,0 +1,59 @@
|
||||
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 "..."
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user