63 lines
1021 B
Go
63 lines
1021 B
Go
package gui
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
)
|
|
|
|
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."
|
|
cmd := tea.EnterAltScreen
|
|
return cmd
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|
|
|
|
func (m *model) View() string {
|
|
if m.mode == Draw {
|
|
return m.viewDraw()
|
|
} else if m.mode == Create {
|
|
return m.viewCreate()
|
|
} else {
|
|
return m.viewSelect()
|
|
}
|
|
}
|
|
|
|
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)
|
|
} else {
|
|
return m.updateSelect(msg)
|
|
}
|
|
}
|
|
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)
|
|
}
|
|
}
|