-
Notifications
You must be signed in to change notification settings - Fork 2
/
sgrattrs.go
119 lines (109 loc) · 1.55 KB
/
sgrattrs.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package tinyterm
import (
"image/color"
)
const (
SGRReset = iota
SGRBold
SGRFaint
SGRItalic
SGRUnderline
SGRSlowBlink
SGRRapidBlink
SGRReverseVideo
SGRConceal
SGRCrossedOut
SGRPrimaryFont
SGRAltFont1
SGRAltFont2
SGRAltFont3
SGRAltFont4
SGRAltFont5
SGRAltFont6
SGRAltFont7
SGRAltFont8
SGRAltFont9
SGRFraktur
SGRDoubleUnderline
SGRNormal
SGRNotItalicNotFraktur
SGRUnderlineOff
SGRBlinkOff
SGRInverseOff
SGRReveal
SGRNotCrossedOut
_
SGRFgBlack
SGRFgRed
SGRFgGreen
SGRFgYellow
SGRFgBlue
SGRFgMagenta
SGRFgCyan
SGRFgWhite
SGRSetFgColor
SGRDefaultFgColor
SGRBgBlack
SGRBgRed
SGRBgGreen
SGRBgYellow
SGRBgBlue
SGRBgMagenta
SGRBgCyan
SGRBgWhite
SGRSetBgColor
SGRDefaultBgColor
SGRFramed
SGREncircled
SGROverlined
SGRIdeogramUnderline
SGRIdeogramDblUnderline
SGRIdeogramOverline
SGRIdeogramStress
SGRIdeogramAttrOff
)
type Color uint8
const (
ColorBlack Color = iota
ColorRed
ColorGreen
ColorYellow
ColorBlue
ColorMagenta
ColorCyan
ColorWhite
ColorBrBlack
ColorBrRed
ColorBrGreen
ColorBrYellow
ColorBrBlue
ColorBrMagenta
ColorBrCyan
ColorBrWhite
)
type sgrAttrs struct {
fg Color
bg Color
attrs uint8
fgcol color.RGBA
bgcol color.RGBA
}
func (a *sgrAttrs) setFG(c Color) {
a.fg = c
a.fgcol = a.calcColor(c).calcRGBA()
}
func (a *sgrAttrs) setBG(c Color) {
a.bg = c
a.bgcol = a.calcColor(c).calcRGBA()
}
func (a *sgrAttrs) calcColor(c Color) Color {
if c < 8 && a.attrs&SGRBold > 0 {
c += 8
}
return c
}
func (a *sgrAttrs) reset() {
a.attrs = 0
a.setFG(ColorBrWhite)
a.setBG(ColorBlack)
}