@@ -11,46 +11,70 @@ pub fn format_esc(code string) string {
11
11
return '\x1b [${code} m'
12
12
}
13
13
14
+ // format returns ANSI escape coded `msg` formatted with a preceding
15
+ // `open` and a succeeding `close`.
16
+ // For instance, `format('hi', '9', '29')` returns `'\x1b[9mhi\x1b[29m'`,
17
+ // or 'hi' with strikethrough, where `'\x1b[9m'` represents
18
+ // crossed out/strikethrough text and `'\x1b[29m'` turns off strikethrough.
14
19
pub fn format (msg string , open string , close string ) string {
15
20
return '\x1b [${open} m${msg} \x1b [${close} m'
16
21
}
17
22
23
+ // format_rgb returns ANSI escape coded `msg` formatted with a preceding
24
+ // `open`, a succeeding `close` and the provided RGB colors `r`, `g`, and `b`.
18
25
pub fn format_rgb (r int , g int , b int , msg string , open string , close string ) string {
19
26
return '\x1b [${open} ;2;${r} ;${g} ;${b} m${msg} \x1b [${close} m'
20
27
}
21
28
29
+ // rbg returns the `msg` with the foreground in the specified RGB color
30
+ // For example, `rgb(0, 255, 0, 'hi')` returns the `'hi'` string in
31
+ // lime color.
22
32
pub fn rgb (r int , g int , b int , msg string ) string {
23
33
return format_rgb (r, g, b, msg, '38' , '39' )
24
34
}
25
35
36
+ // bg_rgb returns the `msg` with the background in the specified RGB color.
37
+ // For example, `bg_rgb(255, 0, 0, 'hi')` returns the text `'hi'` in
38
+ // red color.
26
39
pub fn bg_rgb (r int , g int , b int , msg string ) string {
27
40
return format_rgb (r, g, b, msg, '48' , '49' )
28
41
}
29
42
43
+ // hex returns the `msg` with the foreground in the specified `hex` color
44
+ // For example, `rgb(255, 'hi')` returns the `'hi'` string in
45
+ // blue color, which is `(0, 0, 255)` in RGB.
30
46
pub fn hex (hex int , msg string ) string {
31
47
return format_rgb (hex >> 16 , hex >> 8 & 0xFF , hex & 0xFF , msg, '38' , '39' )
32
48
}
33
49
50
+ // hex returns the `msg` with the background in the specified `hex` color
51
+ // For example, `bg_rgb(255, 'hi')` returns the `'hi'` string in
52
+ // a background of blue color, which is `(0, 0, 255)` in RGB.
34
53
pub fn bg_hex (hex int , msg string ) string {
35
54
return format_rgb (hex >> 16 , hex >> 8 & 0xFF , hex & 0xFF , msg, '48' , '49' )
36
55
}
37
56
57
+ // reset resets all formatting for `msg`.
38
58
pub fn reset (msg string ) string {
39
59
return format (msg, '0' , '0' )
40
60
}
41
61
62
+ // bold returns the given `msg` in bold.
42
63
pub fn bold (msg string ) string {
43
64
return format (msg, '1' , '22' )
44
65
}
45
66
67
+ // dim returns the dimmed `msg`.
46
68
pub fn dim (msg string ) string {
47
69
return format (msg, '2' , '22' )
48
70
}
49
71
72
+ // italic returns the given `msg` in italic.
50
73
pub fn italic (msg string ) string {
51
74
return format (msg, '3' , '23' )
52
75
}
53
76
77
+ // underline returns the underlined `msg`.
54
78
pub fn underline (msg string ) string {
55
79
return format (msg, '4' , '24' )
56
80
}
@@ -66,146 +90,182 @@ pub fn rapid_blink(msg string) string {
66
90
return format (msg, '6' , '26' )
67
91
}
68
92
93
+ // inverse inverses the given `msg`.
69
94
pub fn inverse (msg string ) string {
70
95
return format (msg, '7' , '27' )
71
96
}
72
97
98
+ // hidden hides the given `msg`.
73
99
pub fn hidden (msg string ) string {
74
100
return format (msg, '8' , '28' )
75
101
}
76
102
103
+ // strikethrough returns the given `msg` in strikethrough.
77
104
pub fn strikethrough (msg string ) string {
78
105
return format (msg, '9' , '29' )
79
106
}
80
107
108
+ // black formats the `msg` in black.
81
109
pub fn black (msg string ) string {
82
110
return format (msg, '30' , '39' )
83
111
}
84
112
113
+ // red formats the `msg` in red.
85
114
pub fn red (msg string ) string {
86
115
return format (msg, '31' , '39' )
87
116
}
88
117
118
+ // green formats the `msg` in green.
89
119
pub fn green (msg string ) string {
90
120
return format (msg, '32' , '39' )
91
121
}
92
122
123
+ // yellow formats the `msg` in yellow.
93
124
pub fn yellow (msg string ) string {
94
125
return format (msg, '33' , '39' )
95
126
}
96
127
128
+ // blue formats the `msg` in blue.
97
129
pub fn blue (msg string ) string {
98
130
return format (msg, '34' , '39' )
99
131
}
100
132
133
+ // magenta formats the `msg` in magenta.
101
134
pub fn magenta (msg string ) string {
102
135
return format (msg, '35' , '39' )
103
136
}
104
137
138
+ // cyan formats the `msg` in cyan.
105
139
pub fn cyan (msg string ) string {
106
140
return format (msg, '36' , '39' )
107
141
}
108
142
143
+ // white formats the `msg` in white.
109
144
pub fn white (msg string ) string {
110
145
return format (msg, '37' , '39' )
111
146
}
112
147
148
+ // bg_black formats the `msg` in black background.
113
149
pub fn bg_black (msg string ) string {
114
150
return format (msg, '40' , '49' )
115
151
}
116
152
153
+ // bg_red formats the `msg` in red background.
117
154
pub fn bg_red (msg string ) string {
118
155
return format (msg, '41' , '49' )
119
156
}
120
157
158
+ // bg_green formats the `msg` in green background.
121
159
pub fn bg_green (msg string ) string {
122
160
return format (msg, '42' , '49' )
123
161
}
124
162
163
+ // bg_yellow formats the `msg` in yellow background.
125
164
pub fn bg_yellow (msg string ) string {
126
165
return format (msg, '43' , '49' )
127
166
}
128
167
168
+ // bg_blue formats the `msg` in blue background.
129
169
pub fn bg_blue (msg string ) string {
130
170
return format (msg, '44' , '49' )
131
171
}
132
172
173
+ // bg_magenta formats the `msg` in magenta background.
133
174
pub fn bg_magenta (msg string ) string {
134
175
return format (msg, '45' , '49' )
135
176
}
136
177
178
+ // bg_cyan formats the `msg` in cyan background.
137
179
pub fn bg_cyan (msg string ) string {
138
180
return format (msg, '46' , '49' )
139
181
}
140
182
183
+ // bg_white formats the `msg` in white background.
141
184
pub fn bg_white (msg string ) string {
142
185
return format (msg, '47' , '49' )
143
186
}
144
187
188
+ // gray formats the `msg` in gray (equivalent to `bright_black`).
145
189
pub fn gray (msg string ) string {
146
190
return bright_black (msg)
147
191
}
148
192
193
+ // bright_black formats the `msg` in bright black.
149
194
pub fn bright_black (msg string ) string {
150
195
return format (msg, '90' , '39' )
151
196
}
152
197
198
+ // bright_red formats the `msg` in bright red.
153
199
pub fn bright_red (msg string ) string {
154
200
return format (msg, '91' , '39' )
155
201
}
156
202
203
+ // bright_green formats the `msg` in bright green.
157
204
pub fn bright_green (msg string ) string {
158
205
return format (msg, '92' , '39' )
159
206
}
160
207
208
+ // bright_yellow formats the `msg` in bright yellow.
161
209
pub fn bright_yellow (msg string ) string {
162
210
return format (msg, '93' , '39' )
163
211
}
164
212
213
+ // bright_blue formats the `msg` in bright blue.
165
214
pub fn bright_blue (msg string ) string {
166
215
return format (msg, '94' , '39' )
167
216
}
168
217
218
+ // bright_magenta formats the `msg` in bright magenta.
169
219
pub fn bright_magenta (msg string ) string {
170
220
return format (msg, '95' , '39' )
171
221
}
172
222
223
+ // bright_cyan formats the `msg` in bright cyan.
173
224
pub fn bright_cyan (msg string ) string {
174
225
return format (msg, '96' , '39' )
175
226
}
176
227
228
+ // bright_white formats the `msg` in bright white.
177
229
pub fn bright_white (msg string ) string {
178
230
return format (msg, '97' , '39' )
179
231
}
180
232
233
+ // bright_bg_black formats the `msg` in bright black background.
181
234
pub fn bright_bg_black (msg string ) string {
182
235
return format (msg, '100' , '49' )
183
236
}
184
237
238
+ // bright_bg_red formats the `msg` in bright red background.
185
239
pub fn bright_bg_red (msg string ) string {
186
240
return format (msg, '101' , '49' )
187
241
}
188
242
243
+ // bright_bg_green formats the `msg` in bright green background.
189
244
pub fn bright_bg_green (msg string ) string {
190
245
return format (msg, '102' , '49' )
191
246
}
192
247
248
+ // bright_bg_yellow formats the `msg` in bright yellow background.
193
249
pub fn bright_bg_yellow (msg string ) string {
194
250
return format (msg, '103' , '49' )
195
251
}
196
252
253
+ // bright_bg_blue formats the `msg` in bright blue background.
197
254
pub fn bright_bg_blue (msg string ) string {
198
255
return format (msg, '104' , '49' )
199
256
}
200
257
258
+ // bright_bg_magenta formats the `msg` in bright magenta background.
201
259
pub fn bright_bg_magenta (msg string ) string {
202
260
return format (msg, '105' , '49' )
203
261
}
204
262
263
+ // bright_bg_cyan formats the `msg` in bright cyan background.
205
264
pub fn bright_bg_cyan (msg string ) string {
206
265
return format (msg, '106' , '49' )
207
266
}
208
267
268
+ // bright_bg_white formats the `msg` in bright white background.
209
269
pub fn bright_bg_white (msg string ) string {
210
270
return format (msg, '107' , '49' )
211
271
}
0 commit comments