-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuffer.go
More file actions
72 lines (59 loc) · 1.13 KB
/
Copy pathbuffer.go
File metadata and controls
72 lines (59 loc) · 1.13 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
package terminux
import "fmt"
type cell struct {
char rune
fg uint32
bg uint32
}
type cellBuffer struct {
cells [][]*cell
width, height int
}
func newCell(char rune, fg, bg uint32) *cell {
return &cell{char, fg, bg}
}
func newCellEmpty() *cell {
return &cell{
char: ' ',
}
}
func newCellBuffer(w, h int) *cellBuffer {
buf := make([][]*cell, h)
for i := range h {
buf[i] = make([]*cell, w)
}
return &cellBuffer{
buf, w, h,
}
}
func (cb *cellBuffer) clear() {
for y := range cb.height {
for x := range cb.width {
cb.cells[y][x] = newCellEmpty()
}
}
}
func (cb *cellBuffer) getCell(x, y int) *cell {
return cb.cells[y][x]
}
func (cb *cellBuffer) setCell(x, y int, cell *cell) {
cb.cells[y][x] = cell
}
func (cb *cell) equal(other *cell) bool {
if other == nil {
return false
}
return cb.char == other.char &&
cb.fg == other.fg &&
cb.bg == other.bg
}
func attachColor(char rune, styles ...uint32) string {
styleString := ""
for i, s := range styles {
if i > 0 {
styleString += ";"
}
styleString += fmt.Sprintf("%d", s)
}
return fmt.Sprintf("\033[%sm%c\033[0m", styleString, char)
}