Skip to content

Commit b69f941

Browse files
authored
term: add missing documentation for all public functions in colors.v (#17033)
1 parent d850d3c commit b69f941

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

vlib/term/colors.v

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,70 @@ pub fn format_esc(code string) string {
1111
return '\x1b[${code}m'
1212
}
1313

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.
1419
pub fn format(msg string, open string, close string) string {
1520
return '\x1b[${open}m${msg}\x1b[${close}m'
1621
}
1722

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`.
1825
pub fn format_rgb(r int, g int, b int, msg string, open string, close string) string {
1926
return '\x1b[${open};2;${r};${g};${b}m${msg}\x1b[${close}m'
2027
}
2128

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.
2232
pub fn rgb(r int, g int, b int, msg string) string {
2333
return format_rgb(r, g, b, msg, '38', '39')
2434
}
2535

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.
2639
pub fn bg_rgb(r int, g int, b int, msg string) string {
2740
return format_rgb(r, g, b, msg, '48', '49')
2841
}
2942

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.
3046
pub fn hex(hex int, msg string) string {
3147
return format_rgb(hex >> 16, hex >> 8 & 0xFF, hex & 0xFF, msg, '38', '39')
3248
}
3349

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.
3453
pub fn bg_hex(hex int, msg string) string {
3554
return format_rgb(hex >> 16, hex >> 8 & 0xFF, hex & 0xFF, msg, '48', '49')
3655
}
3756

57+
// reset resets all formatting for `msg`.
3858
pub fn reset(msg string) string {
3959
return format(msg, '0', '0')
4060
}
4161

62+
// bold returns the given `msg` in bold.
4263
pub fn bold(msg string) string {
4364
return format(msg, '1', '22')
4465
}
4566

67+
// dim returns the dimmed `msg`.
4668
pub fn dim(msg string) string {
4769
return format(msg, '2', '22')
4870
}
4971

72+
// italic returns the given `msg` in italic.
5073
pub fn italic(msg string) string {
5174
return format(msg, '3', '23')
5275
}
5376

77+
// underline returns the underlined `msg`.
5478
pub fn underline(msg string) string {
5579
return format(msg, '4', '24')
5680
}
@@ -66,146 +90,182 @@ pub fn rapid_blink(msg string) string {
6690
return format(msg, '6', '26')
6791
}
6892

93+
// inverse inverses the given `msg`.
6994
pub fn inverse(msg string) string {
7095
return format(msg, '7', '27')
7196
}
7297

98+
// hidden hides the given `msg`.
7399
pub fn hidden(msg string) string {
74100
return format(msg, '8', '28')
75101
}
76102

103+
// strikethrough returns the given `msg` in strikethrough.
77104
pub fn strikethrough(msg string) string {
78105
return format(msg, '9', '29')
79106
}
80107

108+
// black formats the `msg` in black.
81109
pub fn black(msg string) string {
82110
return format(msg, '30', '39')
83111
}
84112

113+
// red formats the `msg` in red.
85114
pub fn red(msg string) string {
86115
return format(msg, '31', '39')
87116
}
88117

118+
// green formats the `msg` in green.
89119
pub fn green(msg string) string {
90120
return format(msg, '32', '39')
91121
}
92122

123+
// yellow formats the `msg` in yellow.
93124
pub fn yellow(msg string) string {
94125
return format(msg, '33', '39')
95126
}
96127

128+
// blue formats the `msg` in blue.
97129
pub fn blue(msg string) string {
98130
return format(msg, '34', '39')
99131
}
100132

133+
// magenta formats the `msg` in magenta.
101134
pub fn magenta(msg string) string {
102135
return format(msg, '35', '39')
103136
}
104137

138+
// cyan formats the `msg` in cyan.
105139
pub fn cyan(msg string) string {
106140
return format(msg, '36', '39')
107141
}
108142

143+
// white formats the `msg` in white.
109144
pub fn white(msg string) string {
110145
return format(msg, '37', '39')
111146
}
112147

148+
// bg_black formats the `msg` in black background.
113149
pub fn bg_black(msg string) string {
114150
return format(msg, '40', '49')
115151
}
116152

153+
// bg_red formats the `msg` in red background.
117154
pub fn bg_red(msg string) string {
118155
return format(msg, '41', '49')
119156
}
120157

158+
// bg_green formats the `msg` in green background.
121159
pub fn bg_green(msg string) string {
122160
return format(msg, '42', '49')
123161
}
124162

163+
// bg_yellow formats the `msg` in yellow background.
125164
pub fn bg_yellow(msg string) string {
126165
return format(msg, '43', '49')
127166
}
128167

168+
// bg_blue formats the `msg` in blue background.
129169
pub fn bg_blue(msg string) string {
130170
return format(msg, '44', '49')
131171
}
132172

173+
// bg_magenta formats the `msg` in magenta background.
133174
pub fn bg_magenta(msg string) string {
134175
return format(msg, '45', '49')
135176
}
136177

178+
// bg_cyan formats the `msg` in cyan background.
137179
pub fn bg_cyan(msg string) string {
138180
return format(msg, '46', '49')
139181
}
140182

183+
// bg_white formats the `msg` in white background.
141184
pub fn bg_white(msg string) string {
142185
return format(msg, '47', '49')
143186
}
144187

188+
// gray formats the `msg` in gray (equivalent to `bright_black`).
145189
pub fn gray(msg string) string {
146190
return bright_black(msg)
147191
}
148192

193+
// bright_black formats the `msg` in bright black.
149194
pub fn bright_black(msg string) string {
150195
return format(msg, '90', '39')
151196
}
152197

198+
// bright_red formats the `msg` in bright red.
153199
pub fn bright_red(msg string) string {
154200
return format(msg, '91', '39')
155201
}
156202

203+
// bright_green formats the `msg` in bright green.
157204
pub fn bright_green(msg string) string {
158205
return format(msg, '92', '39')
159206
}
160207

208+
// bright_yellow formats the `msg` in bright yellow.
161209
pub fn bright_yellow(msg string) string {
162210
return format(msg, '93', '39')
163211
}
164212

213+
// bright_blue formats the `msg` in bright blue.
165214
pub fn bright_blue(msg string) string {
166215
return format(msg, '94', '39')
167216
}
168217

218+
// bright_magenta formats the `msg` in bright magenta.
169219
pub fn bright_magenta(msg string) string {
170220
return format(msg, '95', '39')
171221
}
172222

223+
// bright_cyan formats the `msg` in bright cyan.
173224
pub fn bright_cyan(msg string) string {
174225
return format(msg, '96', '39')
175226
}
176227

228+
// bright_white formats the `msg` in bright white.
177229
pub fn bright_white(msg string) string {
178230
return format(msg, '97', '39')
179231
}
180232

233+
// bright_bg_black formats the `msg` in bright black background.
181234
pub fn bright_bg_black(msg string) string {
182235
return format(msg, '100', '49')
183236
}
184237

238+
// bright_bg_red formats the `msg` in bright red background.
185239
pub fn bright_bg_red(msg string) string {
186240
return format(msg, '101', '49')
187241
}
188242

243+
// bright_bg_green formats the `msg` in bright green background.
189244
pub fn bright_bg_green(msg string) string {
190245
return format(msg, '102', '49')
191246
}
192247

248+
// bright_bg_yellow formats the `msg` in bright yellow background.
193249
pub fn bright_bg_yellow(msg string) string {
194250
return format(msg, '103', '49')
195251
}
196252

253+
// bright_bg_blue formats the `msg` in bright blue background.
197254
pub fn bright_bg_blue(msg string) string {
198255
return format(msg, '104', '49')
199256
}
200257

258+
// bright_bg_magenta formats the `msg` in bright magenta background.
201259
pub fn bright_bg_magenta(msg string) string {
202260
return format(msg, '105', '49')
203261
}
204262

263+
// bright_bg_cyan formats the `msg` in bright cyan background.
205264
pub fn bright_bg_cyan(msg string) string {
206265
return format(msg, '106', '49')
207266
}
208267

268+
// bright_bg_white formats the `msg` in bright white background.
209269
pub fn bright_bg_white(msg string) string {
210270
return format(msg, '107', '49')
211271
}

0 commit comments

Comments
 (0)