-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathboard.go
More file actions
92 lines (84 loc) · 2.07 KB
/
Copy pathboard.go
File metadata and controls
92 lines (84 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"github.com/charmbracelet/bubbles/v2/help"
"github.com/charmbracelet/bubbles/v2/key"
tea "github.com/charmbracelet/bubbletea/v2"
"github.com/charmbracelet/lipgloss/v2"
)
type EditFormMsg struct {
title string
description string
index int
column column
}
type NewFormMsg struct {
index int
column column
}
type Board struct {
help help.Model
loaded bool
focused status
cols []column
quitting bool
}
func NewBoard() *Board {
help := help.New()
help.ShowAll = true
return &Board{help: help, focused: todo}
}
func (m *Board) Init() tea.Cmd {
return nil
}
func (m *Board) Update(msg tea.Msg) (*Board, tea.Cmd) {
var cmd tea.Cmd
var cmds []tea.Cmd
switch msg := msg.(type) {
case tea.WindowSizeMsg:
m.help.Width = msg.Width - margin
for i := range m.cols {
m.cols[i], cmd = m.cols[i].Update(msg)
cmds = append(cmds, cmd)
}
m.loaded = true
return m, tea.Batch(cmds...)
case ReturnBoardMsg:
if !msg.abort {
return m, m.cols[m.focused].Set(msg.form.index, msg.form.CreateTask())
}
case moveMsg:
return m, m.cols[m.focused.getNext()].Set(APPEND, msg.Task)
case tea.KeyMsg:
switch {
case key.Matches(msg, keys.Quit):
m.quitting = true
return m, tea.Quit
case key.Matches(msg, keys.Left):
m.cols[m.focused].Blur()
m.focused = m.focused.getPrev()
m.cols[m.focused].Focus()
case key.Matches(msg, keys.Right):
m.cols[m.focused].Blur()
m.focused = m.focused.getNext()
m.cols[m.focused].Focus()
}
}
m.cols[m.focused], cmd = m.cols[m.focused].Update(msg)
return m, cmd
}
// Changing to pointer receiver to get back to this model after adding a new task via the form... Otherwise I would need to pass this model along to the form and it becomes highly coupled to the other models.
func (m *Board) View() string {
if m.quitting {
return ""
}
if !m.loaded {
return "loading..."
}
board := lipgloss.JoinHorizontal(
lipgloss.Left,
m.cols[todo].View(),
m.cols[inProgress].View(),
m.cols[done].View(),
)
return lipgloss.JoinVertical(lipgloss.Left, board, m.help.View(keys))
}