/
terminal.go
59 lines (47 loc) · 1.42 KB
/
terminal.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
package render
import (
"fmt"
"github.com/nsf/termbox-go"
"github.com/siggy/bbox/bbox/color"
)
type Terminal struct{}
func InitTerminal() *Terminal {
return &Terminal{}
}
// TODO: dry up
func (t *Terminal) TBprint(x, y int, msg string) {
for _, c := range msg {
termbox.SetCell(x, y, c, termbox.ColorDefault, termbox.ColorDefault)
x++
}
}
func (t *Terminal) Render(state State) {
t.TBprint(0, 10, fmt.Sprintf("______render.State:_%+v______", state))
for row := 0; row < ROWS; row++ {
for col := 0; col < COLUMNS; col++ {
// clear everything
for i := 0; i < COLS_PER_BEAT; i++ {
termbox.SetCell(col*COLS_PER_BEAT+i, row, ' ', termbox.ColorBlack, termbox.ColorBlack)
}
fgColor := termbox.ColorBlack
rune := ' '
if state.LEDs[row][col] == color.Make(0, 0, 0, 127) {
fgColor = termbox.ColorWhite
rune = 'X'
} else if state.LEDs[row][col] == color.Make(127, 0, 0, 0) {
fgColor = termbox.ColorRed
rune = 'O'
} else if state.LEDs[row][col] == color.Make(250, 143, 94, 0) {
// ceottk
fgColor = termbox.ColorYellow
rune = 'X'
}
if state.Transitions[row][col].Color == color.Make(0, 0, 0, 127) {
location := int(COLS_PER_BEAT * state.Transitions[row][col].Location)
termbox.SetCell(col*COLS_PER_BEAT+location, row, 'X', termbox.ColorBlack, termbox.ColorWhite)
}
termbox.SetCell(col*COLS_PER_BEAT, row, rune, termbox.ColorBlack, fgColor)
}
}
termbox.Flush()
}