summaryrefslogtreecommitdiff
path: root/vendor/github.com/morikuni/aec/sgr.go
blob: 0ba3464e6dbdc6457ea191f2cee43d685b23effb (plain)
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
package aec

import (
	"fmt"
)

// RGB3Bit is a 3bit RGB color.
type RGB3Bit uint8

// RGB8Bit is a 8bit RGB color.
type RGB8Bit uint8

func newSGR(n uint) ANSI {
	return newAnsi(fmt.Sprintf(esc+"%dm", n))
}

// NewRGB3Bit create a RGB3Bit from given RGB.
func NewRGB3Bit(r, g, b uint8) RGB3Bit {
	return RGB3Bit((r >> 7) | ((g >> 6) & 0x2) | ((b >> 5) & 0x4))
}

// NewRGB8Bit create a RGB8Bit from given RGB.
func NewRGB8Bit(r, g, b uint8) RGB8Bit {
	return RGB8Bit(16 + 36*(r/43) + 6*(g/43) + b/43)
}

// Color3BitF set the foreground color of text.
func Color3BitF(c RGB3Bit) ANSI {
	return newAnsi(fmt.Sprintf(esc+"%dm", c+30))
}

// Color3BitB set the background color of text.
func Color3BitB(c RGB3Bit) ANSI {
	return newAnsi(fmt.Sprintf(esc+"%dm", c+40))
}

// Color8BitF set the foreground color of text.
func Color8BitF(c RGB8Bit) ANSI {
	return newAnsi(fmt.Sprintf(esc+"38;5;%dm", c))
}

// Color8BitB set the background color of text.
func Color8BitB(c RGB8Bit) ANSI {
	return newAnsi(fmt.Sprintf(esc+"48;5;%dm", c))
}

// FullColorF set the foreground color of text.
func FullColorF(r, g, b uint8) ANSI {
	return newAnsi(fmt.Sprintf(esc+"38;2;%d;%d;%dm", r, g, b))
}

// FullColorB set the foreground color of text.
func FullColorB(r, g, b uint8) ANSI {
	return newAnsi(fmt.Sprintf(esc+"48;2;%d;%d;%dm", r, g, b))
}

// Style
var (
	// Bold set the text style to bold or increased intensity.
	Bold ANSI

	// Faint set the text style to faint.
	Faint ANSI

	// Italic set the text style to italic.
	Italic ANSI

	// Underline set the text style to underline.
	Underline ANSI

	// BlinkSlow set the text style to slow blink.
	BlinkSlow ANSI

	// BlinkRapid set the text style to rapid blink.
	BlinkRapid ANSI

	// Inverse swap the foreground color and background color.
	Inverse ANSI

	// Conceal set the text style to conceal.
	Conceal ANSI

	// CrossOut set the text style to crossed out.
	CrossOut ANSI

	// Frame set the text style to framed.
	Frame ANSI

	// Encircle set the text style to encircled.
	Encircle ANSI

	// Overline set the text style to overlined.
	Overline ANSI
)

// Foreground color of text.
var (
	// DefaultF is the default color of foreground.
	DefaultF ANSI

	// Normal color
	BlackF   ANSI
	RedF     ANSI
	GreenF   ANSI
	YellowF  ANSI
	BlueF    ANSI
	MagentaF ANSI
	CyanF    ANSI
	WhiteF   ANSI

	// Light color
	LightBlackF   ANSI
	LightRedF     ANSI
	LightGreenF   ANSI
	LightYellowF  ANSI
	LightBlueF    ANSI
	LightMagentaF ANSI
	LightCyanF    ANSI
	LightWhiteF   ANSI
)

// Background color of text.
var (
	// DefaultB is the default color of background.
	DefaultB ANSI

	// Normal color
	BlackB   ANSI
	RedB     ANSI
	GreenB   ANSI
	YellowB  ANSI
	BlueB    ANSI
	MagentaB ANSI
	CyanB    ANSI
	WhiteB   ANSI

	// Light color
	LightBlackB   ANSI
	LightRedB     ANSI
	LightGreenB   ANSI
	LightYellowB  ANSI
	LightBlueB    ANSI
	LightMagentaB ANSI
	LightCyanB    ANSI
	LightWhiteB   ANSI
)

func init() {
	Bold = newSGR(1)
	Faint = newSGR(2)
	Italic = newSGR(3)
	Underline = newSGR(4)
	BlinkSlow = newSGR(5)
	BlinkRapid = newSGR(6)
	Inverse = newSGR(7)
	Conceal = newSGR(8)
	CrossOut = newSGR(9)

	BlackF = newSGR(30)
	RedF = newSGR(31)
	GreenF = newSGR(32)
	YellowF = newSGR(33)
	BlueF = newSGR(34)
	MagentaF = newSGR(35)
	CyanF = newSGR(36)
	WhiteF = newSGR(37)

	DefaultF = newSGR(39)

	BlackB = newSGR(40)
	RedB = newSGR(41)
	GreenB = newSGR(42)
	YellowB = newSGR(43)
	BlueB = newSGR(44)
	MagentaB = newSGR(45)
	CyanB = newSGR(46)
	WhiteB = newSGR(47)

	DefaultB = newSGR(49)

	Frame = newSGR(51)
	Encircle = newSGR(52)
	Overline = newSGR(53)

	LightBlackF = newSGR(90)
	LightRedF = newSGR(91)
	LightGreenF = newSGR(92)
	LightYellowF = newSGR(93)
	LightBlueF = newSGR(94)
	LightMagentaF = newSGR(95)
	LightCyanF = newSGR(96)
	LightWhiteF = newSGR(97)

	LightBlackB = newSGR(100)
	LightRedB = newSGR(101)
	LightGreenB = newSGR(102)
	LightYellowB = newSGR(103)
	LightBlueB = newSGR(104)
	LightMagentaB = newSGR(105)
	LightCyanB = newSGR(106)
	LightWhiteB = newSGR(107)
}