Debian Codegraph @

wrap.go

raw
1 //
2 // Copyright (c) 2016-2022 The Aurora Authors. All rights reserved.
3 // This program is free software. It comes without any warranty,
4 // to the extent permitted by applicable law. You can redistribute
5 // it and/or modify it under the terms of the Unlicense. See LICENSE
6 // file for more details or see below.
7 //
8
9 //
10 // This is free and unencumbered software released into the public domain.
11 //
12 // Anyone is free to copy, modify, publish, use, compile, sell, or
13 // distribute this software, either in source code form or as a compiled
14 // binary, for any purpose, commercial or non-commercial, and by any
15 // means.
16 //
17 // In jurisdictions that recognize copyright laws, the author or authors
18 // of this software dedicate any and all copyright interest in the
19 // software to the public domain. We make this dedication for the benefit
20 // of the public at large and to the detriment of our heirs and
21 // successors. We intend this dedication to be an overt act of
22 // relinquishment in perpetuity of all present and future rights to this
23 // software under copyright law.
24 //
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
28 // IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
29 // OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
30 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
31 // OTHER DEALINGS IN THE SOFTWARE.
32 //
33 // For more information, please refer to <http://unlicense.org/>
34 //
35
36 package aurora
37
38 // DefaultColorizer is global colorizer that used for package root color
39 // methods.
40 var DefaultColorizer = New(WithColors(true), WithHyperlinks(true))
41
42 // Colorize wraps given value into Value with given colors. For example
43 //
44 // var s = Colorize("some", BlueFg|GreenBg|BoldFm)
45 //
46 // returns a Value with blue foreground, green background and bold. Unlike
47 // functions like Red/BgBlue/Bold etc. This function clears all previous colors
48 // and formats. Thus
49 //
50 // var s = Colorize(Red("some"), BgBlue)
51 //
52 // clears red color from value.
53 func Colorize(arg interface{}, color Color) Value {
54 return DefaultColorizer.Colorize(arg, color)
55 }
56
57 // Reset wraps given argument returning Value without formats, colors and links.
58 func Reset(arg interface{}) Value {
59 return DefaultColorizer.Reset(arg)
60 }
61
62 // Clear wraps given argument returning Value without formats and colors. But
63 // preserving links.
64 func Clear(arg interface{}) Value {
65 return DefaultColorizer.Clear(arg)
66 }
67
68 //
69 // Formats
70 //
71
72 // Bold or increased intensity (1).
73 func Bold(arg interface{}) Value {
74 return DefaultColorizer.Bold(arg)
75 }
76
77 // Faint decreases intensity (2). The Faint rejects the Bold.
78 func Faint(arg interface{}) Value {
79 return DefaultColorizer.Faint(arg)
80 }
81
82 // DoublyUnderline or Bold off, double-underline per ECMA-48 (21).
83 func DoublyUnderline(arg interface{}) Value {
84 return DefaultColorizer.DoublyUnderline(arg)
85 }
86
87 // Fraktur is rarely supported (20).
88 func Fraktur(arg interface{}) Value {
89 return DefaultColorizer.Fraktur(arg)
90 }
91
92 // Italic is not widely supported, sometimes treated as inverse (3).
93 func Italic(arg interface{}) Value {
94 return DefaultColorizer.Italic(arg)
95 }
96
97 // Underline (4).
98 func Underline(arg interface{}) Value {
99 return DefaultColorizer.Underline(arg)
100 }
101
102 // SlowBlink makes text blink less than 150 per minute (5).
103 func SlowBlink(arg interface{}) Value {
104 return DefaultColorizer.SlowBlink(arg)
105 }
106
107 // RapidBlink makes text blink 150+ per minute. It is not widely supported (6).
108 func RapidBlink(arg interface{}) Value {
109 return DefaultColorizer.RapidBlink(arg)
110 }
111
112 // Blink is alias for the SlowBlink.
113 func Blink(arg interface{}) Value {
114 return DefaultColorizer.Blink(arg)
115 }
116
117 // Reverse video, swap foreground and background colors (7).
118 func Reverse(arg interface{}) Value {
119 return DefaultColorizer.Reverse(arg)
120 }
121
122 // Inverse is alias for the Reverse
123 func Inverse(arg interface{}) Value {
124 return DefaultColorizer.Inverse(arg)
125 }
126
127 // Conceal hides text, preserving an ability to select the text and copy it. It
128 // is not widely supported (8).
129 func Conceal(arg interface{}) Value {
130 return DefaultColorizer.Conceal(arg)
131 }
132
133 // Hidden is alias for the Conceal
134 func Hidden(arg interface{}) Value {
135 return DefaultColorizer.Hidden(arg)
136 }
137
138 // CrossedOut makes characters legible, but marked for deletion (9).
139 func CrossedOut(arg interface{}) Value {
140 return DefaultColorizer.CrossedOut(arg)
141 }
142
143 // StrikeThrough is alias for the CrossedOut.
144 func StrikeThrough(arg interface{}) Value {
145 return DefaultColorizer.StrikeThrough(arg)
146 }
147
148 // Framed (51).
149 func Framed(arg interface{}) Value {
150 return DefaultColorizer.Framed(arg)
151 }
152
153 // Encircled (52).
154 func Encircled(arg interface{}) Value {
155 return DefaultColorizer.Encircled(arg)
156 }
157
158 // Overlined (53).
159 func Overlined(arg interface{}) Value {
160 return DefaultColorizer.Overlined(arg)
161 }
162
163 //
164 // Foreground colors
165 //
166 //
167
168 // Black foreground color (30)
169 func Black(arg interface{}) Value {
170 return DefaultColorizer.Black(arg)
171 }
172
173 // Red foreground color (31)
174 func Red(arg interface{}) Value {
175 return DefaultColorizer.Red(arg)
176 }
177
178 // Green foreground color (32)
179 func Green(arg interface{}) Value {
180 return DefaultColorizer.Green(arg)
181 }
182
183 // Yellow foreground color (33)
184 func Yellow(arg interface{}) Value {
185 return DefaultColorizer.Yellow(arg)
186 }
187
188 // Blue foreground color (34)
189 func Blue(arg interface{}) Value {
190 return DefaultColorizer.Blue(arg)
191 }
192
193 // Magenta foreground color (35)
194 func Magenta(arg interface{}) Value {
195 return DefaultColorizer.Magenta(arg)
196 }
197
198 // Cyan foreground color (36)
199 func Cyan(arg interface{}) Value {
200 return DefaultColorizer.Cyan(arg)
201 }
202
203 // White foreground color (37)
204 func White(arg interface{}) Value {
205 return DefaultColorizer.White(arg)
206 }
207
208 //
209 // Bright foreground colors
210 //
211
212 // BrightBlack foreground color (90)
213 func BrightBlack(arg interface{}) Value {
214 return DefaultColorizer.BrightBlack(arg)
215 }
216
217 // BrightRed foreground color (91)
218 func BrightRed(arg interface{}) Value {
219 return DefaultColorizer.BrightRed(arg)
220 }
221
222 // BrightGreen foreground color (92)
223 func BrightGreen(arg interface{}) Value {
224 return DefaultColorizer.BrightGreen(arg)
225 }
226
227 // BrightYellow foreground color (93)
228 func BrightYellow(arg interface{}) Value {
229 return DefaultColorizer.BrightYellow(arg)
230 }
231
232 // BrightBlue foreground color (94)
233 func BrightBlue(arg interface{}) Value {
234 return DefaultColorizer.BrightBlue(arg)
235 }
236
237 // BrightMagenta foreground color (95)
238 func BrightMagenta(arg interface{}) Value {
239 return DefaultColorizer.BrightMagenta(arg)
240 }
241
242 // BrightCyan foreground color (96)
243 func BrightCyan(arg interface{}) Value {
244 return DefaultColorizer.BrightCyan(arg)
245 }
246
247 // BrightWhite foreground color (97)
248 func BrightWhite(arg interface{}) Value {
249 return DefaultColorizer.BrightWhite(arg)
250 }
251
252 //
253 // Other
254 //
255
256 // Index of pre-defined 8-bit foreground color from 0 to 255 (38;5;n).
257 //
258 // 0- 7: standard colors (as in ESC [ 30–37 m)
259 // 8- 15: high intensity colors (as in ESC [ 90–97 m)
260 // 16-231: 6 × 6 × 6 cube (216 colors): 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5)
261 // 232-255: grayscale from black to white in 24 steps
262 func Index(n ColorIndex, arg interface{}) Value {
263 return DefaultColorizer.Index(n, arg)
264 }
265
266 // Gray from 0 to 24.
267 func Gray(n GrayIndex, arg interface{}) Value {
268 return DefaultColorizer.Gray(n, arg)
269 }
270
271 //
272 // Background colors
273 //
274 //
275
276 // BgBlack background color (40)
277 func BgBlack(arg interface{}) Value {
278 return DefaultColorizer.BgBlack(arg)
279 }
280
281 // BgRed background color (41)
282 func BgRed(arg interface{}) Value {
283 return DefaultColorizer.BgRed(arg)
284 }
285
286 // BgGreen background color (42)
287 func BgGreen(arg interface{}) Value {
288 return DefaultColorizer.BgGreen(arg)
289 }
290
291 // BgYellow background color (43)
292 func BgYellow(arg interface{}) Value {
293 return DefaultColorizer.BgYellow(arg)
294 }
295
296 // BgBlue background color (44)
297 func BgBlue(arg interface{}) Value {
298 return DefaultColorizer.BgBlue(arg)
299 }
300
301 // BgMagenta background color (45)
302 func BgMagenta(arg interface{}) Value {
303 return DefaultColorizer.BgMagenta(arg)
304 }
305
306 // BgCyan background color (46)
307 func BgCyan(arg interface{}) Value {
308 return DefaultColorizer.BgCyan(arg)
309 }
310
311 // BgWhite background color (47)
312 func BgWhite(arg interface{}) Value {
313 return DefaultColorizer.BgWhite(arg)
314 }
315
316 //
317 // Bright background colors
318 //
319
320 // BgBrightBlack background color (100)
321 func BgBrightBlack(arg interface{}) Value {
322 return DefaultColorizer.BgBrightBlack(arg)
323 }
324
325 // BgBrightRed background color (101)
326 func BgBrightRed(arg interface{}) Value {
327 return DefaultColorizer.BgBrightRed(arg)
328 }
329
330 // BgBrightGreen background color (102)
331 func BgBrightGreen(arg interface{}) Value {
332 return DefaultColorizer.BgBrightGreen(arg)
333 }
334
335 // BgBrightYellow background color (103)
336 func BgBrightYellow(arg interface{}) Value {
337 return DefaultColorizer.BgBrightYellow(arg)
338 }
339
340 // BgBrightBlue background color (104)
341 func BgBrightBlue(arg interface{}) Value {
342 return DefaultColorizer.BgBrightBlue(arg)
343 }
344
345 // BgBrightMagenta background color (105)
346 func BgBrightMagenta(arg interface{}) Value {
347 return DefaultColorizer.BgBrightMagenta(arg)
348 }
349
350 // BgBrightCyan background color (106)
351 func BgBrightCyan(arg interface{}) Value {
352 return DefaultColorizer.BgBrightCyan(arg)
353 }
354
355 // BgBrightWhite background color (107)
356 func BgBrightWhite(arg interface{}) Value {
357 return DefaultColorizer.BgBrightWhite(arg)
358 }
359
360 //
361 // Other
362 //
363
364 // BgIndex of 8-bit pre-defined background color from 0 to 255 (48;5;n).
365 //
366 // 0- 7: standard colors (as in ESC [ 40–47 m)
367 // 8- 15: high intensity colors (as in ESC [100–107 m)
368 // 16-231: 6 × 6 × 6 cube (216 colors): 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5)
369 // 232-255: grayscale from black to white in 24 steps
370 func BgIndex(n ColorIndex, arg interface{}) Value {
371 return DefaultColorizer.BgIndex(n, arg)
372 }
373
374 // BgGray from 0 to 24.
375 func BgGray(n GrayIndex, arg interface{}) Value {
376 return DefaultColorizer.BgGray(n, arg)
377 }
378
379 //
380 // Hyperlinks feature
381 //
382
383 // Hyperlink with given target and parameters. If hyperlinks feature is
384 // disabled, then the 'arg' argument dropped and the 'target' used instead
385 // inheriting all colors and format from the 'arg' (if it's a Colored).
386 //
387 // See https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
388 // for details about the hyperlinks feature.
389 //
390 // The Hyperlink doesn't escape the target and the params. They should be
391 // checked and escaped before.
392 //
393 // See also HyperlinkID function.
394 //
395 // For a simple example
396 //
397 // au.Hyperlink("Example", "http://example.com")
398 //
399 // and an example with ID
400 //
401 // au.Hyperlink("Example", "http://example.com", aurora.HyperlinkID("10"))
402 func Hyperlink(arg interface{}, target string, params ...HyperlinkParam) Value {
403 return DefaultColorizer.Hyperlink(arg, target, params...)
404 }
405
406 // HyperlinkTarget of the argument if it's a Value.
407 func HyperlinkTarget(arg interface{}) (target string) {
408 return DefaultColorizer.HyperlinkTarget(arg)
409 }
410
411 // HyperlinkParams of the argument if it's a Value.
412 func HyperlinkParams(arg interface{}) (params []HyperlinkParam) {
413 return DefaultColorizer.HyperlinkParams(arg)
414 }
415
416 // Sprintf allows to use Value as format. For example
417 //
418 // var v = Sprintf(Red("total: +3.5f points"), Blue(3.14))
419 //
420 // In this case "total:" and "points" will be red, but
421 // 3.14 will be blue. But, in another example
422 //
423 // var v = Sprintf(Red("total: +3.5f points"), 3.14)
424 //
425 // full string will be red. And no way to clear 3.14 to default format and
426 // color.
427 //
428 // It applies own configurations to all given Values.
429 func Sprintf(format interface{}, args ...interface{}) string {
430 return DefaultColorizer.Sprintf(format, args...)
431 }