itor/gui/gui.go

63 lines
1021 B
Go
Raw Normal View History

2022-10-09 03:09:19 +00:00
package gui
import (
"fmt"
"os"
2022-10-09 03:46:15 +00:00
tea "github.com/charmbracelet/bubbletea"
2022-10-09 03:09:19 +00:00
)
type Mode int64
const (
Select Mode = iota
Create
Draw
)
func (m *model) Init() tea.Cmd {
// Just return `nil`, which means "no I/O right now, please."
2022-10-09 05:21:00 +00:00
cmd := tea.EnterAltScreen
return cmd
2022-10-09 03:09:19 +00:00
}
func (m *model) switchMode(mode Mode) {
// TODO: initialization stuff
switch mode {
case Select:
m.mode = Select
case Draw:
m.mode = Draw
case Create:
m.mode = Create
}
}
2022-10-09 03:18:46 +00:00
func (m *model) View() string {
if m.mode == Draw {
return m.viewDraw()
} else if m.mode == Create {
return m.viewCreate()
2022-10-09 05:21:00 +00:00
} else {
return m.viewSelect()
2022-10-09 03:18:46 +00:00
}
}
func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if m.mode == Draw {
return m.updateDraw(msg)
} else if m.mode == Create {
return m.updateCreate(msg)
2022-10-09 05:21:00 +00:00
} else {
return m.updateSelect(msg)
2022-10-09 03:18:46 +00:00
}
}
2022-10-09 03:09:19 +00:00
func Run() {
initial := initialModel()
p := tea.NewProgram(&initial)
if err := p.Start(); err != nil {
fmt.Printf("Alas, there's been an error: %v", err)
os.Exit(1)
}
}