This commit is contained in:
Tyrel Souza 2022-10-07 23:18:25 -04:00
parent 844922cb37
commit 9bfc4e9e1b

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." // Just return `nil`, which means "no I/O right now, please."
return nil 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 { if m.mode == Draw {
return m.updateDraw(msg) return m.updateDraw(msg)
} }
@ -53,7 +53,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m.updateSelect(msg) 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) { switch msg := msg.(type) {
// Is it a key press? // Is it a key press?
@ -72,7 +72,7 @@ func (m model) updateDraw(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, nil return m, nil
} }
func (m model) switchMode(mode Mode) { func (m *model) switchMode(mode Mode) {
// TODO: initialization stuff // TODO: initialization stuff
switch mode { switch mode {
case Select: 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) { switch msg := msg.(type) {
// Is it a key press? // Is it a key press?
@ -126,7 +126,7 @@ func (m model) updateSelect(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, nil return m, nil
} }
func (m model) cardListToString() string { func (m *model) cardListToString() string {
s := "" s := ""
for i, card := range m.cards { for i, card := range m.cards {
if _, ok := m.selected[i]; ok { if _, ok := m.selected[i]; ok {
@ -135,7 +135,7 @@ func (m model) cardListToString() string {
} }
return s return s
} }
func (m model) View() string { func (m *model) View() string {
if m.mode == Draw { if m.mode == Draw {
return m.viewDraw() return m.viewDraw()
} }
@ -143,7 +143,7 @@ func (m model) View() string {
return m.viewSelect() return m.viewSelect()
} }
func (m model) viewDraw() string { func (m *model) viewDraw() string {
s := "Draw Mode:\n\n" s := "Draw Mode:\n\n"
s += m.cardListToString() s += m.cardListToString()
@ -151,7 +151,7 @@ func (m model) viewDraw() string {
return s return s
} }
func (m model) viewSelect() string { func (m *model) viewSelect() string {
s := "Select cards to query:\n\n" s := "Select cards to query:\n\n"
// Iterate over our choices // Iterate over our choices
@ -174,14 +174,15 @@ func (m model) viewSelect() string {
} }
// The footer // 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 // Send the UI for rendering
return s return s
} }
func main() { func main() {
p := tea.NewProgram(initialModel()) initial := initialModel()
p := tea.NewProgram(&initial)
if err := p.Start(); err != nil { if err := p.Start(); err != nil {
fmt.Printf("Alas, there's been an error: %v", err) fmt.Printf("Alas, there's been an error: %v", err)
os.Exit(1) os.Exit(1)