-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcell.go
71 lines (56 loc) · 1.1 KB
/
cell.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
package bento
import (
"github.com/metafates/bento/internal/bit"
"github.com/muesli/termenv"
)
type Cell struct {
Symbol string
Fg, Bg Color
Modifier Modifier
Skip bool
}
func NewEmptyCell() Cell {
return NewCell(" ")
}
func NewCell(symbol string) Cell {
return Cell{
Symbol: symbol,
Fg: ResetColor{},
Bg: ResetColor{},
Skip: false,
}
}
func (c *Cell) SetSymbol(symbol string) *Cell {
c.Symbol = symbol
return c
}
func (c *Cell) AppendSymbol(symbol string) *Cell {
c.Symbol += symbol
return c
}
func (c *Cell) SetFg(color termenv.Color) *Cell {
c.Fg = color
return c
}
func (c *Cell) SetBg(color termenv.Color) *Cell {
c.Bg = color
return c
}
func (c *Cell) SetStyle(style Style) *Cell {
if style.Foreground.IsSet() {
c.Fg = style.Foreground.Color()
}
if style.Background.IsSet() {
c.Bg = style.Background.Color()
}
c.Modifier = bit.Union(c.Modifier, style.addModifier)
c.Modifier = bit.Difference(c.Modifier, style.subModifier)
return c
}
func (c *Cell) Reset() {
c.Symbol = " "
c.Skip = false
c.Fg = ResetColor{}
c.Bg = ResetColor{}
c.Modifier = 0
}