-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswim_lane.go
112 lines (92 loc) · 2.63 KB
/
swim_lane.go
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package main
import (
"log"
"github.com/charmbracelet/bubbles/list"
"github.com/charmbracelet/lipgloss"
"github.com/gobeam/stringy"
)
const (
divisor = len(status_strings) + 1
horizontalPad = 2
verticalPad = 1
bordersize = 1
)
// Styles
var (
columnStyle = lipgloss.NewStyle().
Padding(verticalPad, horizontalPad)
focusedStyle = lipgloss.NewStyle().
Padding(verticalPad, horizontalPad).
Border(lipgloss.RoundedBorder()).
BorderForeground(highlightColor)
listTitleStyle = lipgloss.NewStyle().
Background(grey).
Foreground(highlightColor).
Padding(0, 1)
listFocusItemStyle = lipgloss.NewStyle().
Foreground(highlightColor).
Bold(true).
Border(lipgloss.NormalBorder(), false, false, false, true).
BorderForeground(highlightColor).
Padding(0, 0, 0, 1)
listFocusItemDescStyle = listFocusItemStyle.Copy().
Foreground(highlightColor)
)
type SwimLane struct {
title string
focused bool
list list.Model
laneStatus status
}
func (s *SwimLane) Focus() {
s.focused = true
}
func (s *SwimLane) Blur() {
s.focused = false
}
// w should be the available width of the current view port (minus other UI)
func (s *SwimLane) SetWidth(w int) {
hOffset := (horizontalPad * 2) + (bordersize * 2)
s.list.SetHeight(w - hOffset)
}
// h should be the available height of the current view port (minus other UI)
func (s *SwimLane) SetHeight(h int) {
vOffset := (verticalPad * 2) + (bordersize * 2)
s.list.SetHeight(h - vOffset)
}
// This will create a new list, meant to be rendered next to N number of other lists,
// where N is equal to the number total lists. This number is passed in as a divisor.
func (s *SwimLane) Init(width int, height int, project int, status status) SwimLane {
s.laneStatus = status
title := stringy.New(status.String()).Title()
s.title = title
// Fetch items from the DB
taskDB := GetDB()
defer taskDB.db.Close()
tasks, err := taskDB.GetByStatus(status, project)
if err != nil {
log.Fatal(err)
}
var items []list.Item
for _, task := range tasks {
items = append(items, task)
}
vOffset := (verticalPad * 2) + (bordersize * 2)
hOffset := (horizontalPad * 2) + (bordersize * 2)
d := list.NewDefaultDelegate()
d.Styles.SelectedTitle = listFocusItemStyle
d.Styles.SelectedDesc = listFocusItemDescStyle
s.list = list.New([]list.Item{}, d, (width/numStatus)-hOffset, height-vOffset)
s.list.Title = title
s.list.SetItems(items)
s.list.SetShowHelp(false)
// Set styles
s.list.Styles.Title = listTitleStyle
return *s
}
func (s *SwimLane) View() string {
if s.focused {
return focusedStyle.Render(s.list.View())
}
return columnStyle.Render(s.list.View())
}