-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtake_list_widget.go
96 lines (75 loc) · 1.75 KB
/
take_list_widget.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
package main
import (
"fmt"
"image"
"sync"
"github.com/mum4k/termdash/cell"
"github.com/mum4k/termdash/private/canvas"
"github.com/mum4k/termdash/private/canvas/buffer"
"github.com/mum4k/termdash/terminal/terminalapi"
"github.com/mum4k/termdash/widgetapi"
)
type TakeListWidget struct {
mu sync.Mutex
}
func (w *TakeListWidget) Draw(cvs *canvas.Canvas, meta *widgetapi.Meta) error {
w.mu.Lock()
defer w.mu.Unlock()
cur := image.Point{
X: 0,
Y: 0,
}
width := cvs.Area().Dx()
for i, Take := range currentSession.Doc.GetChunk(int(selectedChunk)).Takes {
color := cell.ColorWhite
symbolRune := ' '
if Take.Mark == Good {
color = GOOD_COLOR
symbolRune = '✓'
} else if Take.Mark == Bad {
color = BAD_COLOR
symbolRune = '✗'
}
symbol := buffer.NewCell(symbolRune, cell.FgColor(color))
if i == selectedTake {
color = SELECT_COLOR
}
cells := buffer.NewCells(fmt.Sprintf("Take %d", i), cell.FgColor(color))
header := []*buffer.Cell{
buffer.NewCell('[', cell.FgColor(cell.ColorWhite)),
symbol,
buffer.NewCell(']', cell.FgColor(cell.ColorWhite)),
}
for _, cell := range header {
cvs.SetCell(cur, cell.Rune, cell.Opts)
cur.X += 1
}
cur.X += 1
lim := clamp(width-cur.X, cur.X, len(cells))
if lim < 0 {
lim = 0
}
for _, cell := range cells[:lim] {
cvs.SetCell(cur, cell.Rune, cell.Opts)
cur.X += 1
}
cur.Y += 1
cur.X = 0
}
return nil
}
func (w *TakeListWidget) Keyboard(k *terminalapi.Keyboard) error {
w.mu.Lock()
defer w.mu.Unlock()
return nil
}
func (w *TakeListWidget) Mouse(m *terminalapi.Mouse) error {
w.mu.Lock()
defer w.mu.Unlock()
return nil
}
func (w *TakeListWidget) Options() widgetapi.Options {
w.mu.Lock()
defer w.mu.Unlock()
return widgetapi.Options{}
}