This commit is contained in:
Tyrel Souza 2022-10-07 23:18:25 -04:00
parent 844922cb37
commit 9bfc4e9e1b
1 changed files with 12 additions and 11 deletions

23
main.go
View File

@ -41,11 +41,11 @@ func initialModel() model {
}
}
func (m model) Init() tea.Cmd {
func (m *model) Init() tea.Cmd {
// Just return `nil`, which means "no I/O right now, please."
return nil
}
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if m.mode == Draw {
return m.updateDraw(msg)
}
@ -53,7 +53,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m.updateSelect(msg)
}
func (m model) updateDraw(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m *model) updateDraw(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
// Is it a key press?
@ -72,7 +72,7 @@ func (m model) updateDraw(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, nil
}
func (m model) switchMode(mode Mode) {
func (m *model) switchMode(mode Mode) {
// TODO: initialization stuff
switch mode {
case Select:
@ -84,7 +84,7 @@ func (m model) switchMode(mode Mode) {
}
}
func (m model) updateSelect(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m *model) updateSelect(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
// Is it a key press?
@ -126,7 +126,7 @@ func (m model) updateSelect(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, nil
}
func (m model) cardListToString() string {
func (m *model) cardListToString() string {
s := ""
for i, card := range m.cards {
if _, ok := m.selected[i]; ok {
@ -135,7 +135,7 @@ func (m model) cardListToString() string {
}
return s
}
func (m model) View() string {
func (m *model) View() string {
if m.mode == Draw {
return m.viewDraw()
}
@ -143,7 +143,7 @@ func (m model) View() string {
return m.viewSelect()
}
func (m model) viewDraw() string {
func (m *model) viewDraw() string {
s := "Draw Mode:\n\n"
s += m.cardListToString()
@ -151,7 +151,7 @@ func (m model) viewDraw() string {
return s
}
func (m model) viewSelect() string {
func (m *model) viewSelect() string {
s := "Select cards to query:\n\n"
// Iterate over our choices
@ -174,14 +174,15 @@ func (m model) viewSelect() string {
}
// The footer
s += "\nPress d to Draw.\nPress q to quit.\n"
s += "\nPress c to Create (_unimplemented_).\nPress d to Draw.\nPress q to quit.\n"
// Send the UI for rendering
return s
}
func main() {
p := tea.NewProgram(initialModel())
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)