-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcell.go
More file actions
48 lines (40 loc) · 812 Bytes
/
cell.go
File metadata and controls
48 lines (40 loc) · 812 Bytes
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
package runal
import (
"fmt"
"github.com/charmbracelet/x/ansi"
)
type Cell struct {
Char string
Foreground string
Background string
}
func (cll Cell) write(c *Canvas, x, y, _, _ int) {
if c.outOfBounds(x, y) {
return
}
c.write(cll.private(), x, y, 1)
}
func (cll Cell) private() cell {
return cell{
char: []rune(cll.Char)[0],
foreground: color(cll.Foreground),
background: color(cll.Background),
}
}
type cell struct {
char rune
padChar rune
foreground ansi.Color
background ansi.Color
}
func (c cell) public() Cell {
return Cell{
Char: string(c.char),
Foreground: colorToString(c.foreground),
Background: colorToString(c.background),
}
}
func colorToString(c ansi.Color) string {
r, g, b, _ := c.RGBA()
return fmt.Sprintf("#%d%d%d", r, g, b)
}