diff --git a/main.go b/main.go index 0f6e9fa..01d2c29 100644 --- a/main.go +++ b/main.go @@ -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)