ahmedelgabri 8.0.4 → 8.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,976 @@
1
+ "use strict";
2
+ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
3
+ // This module is browser compatible.
4
+ // A module to print ANSI terminal colors. Inspired by chalk, kleur, and colors
5
+ // on npm.
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || function (mod) {
23
+ if (mod && mod.__esModule) return mod;
24
+ var result = {};
25
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
26
+ __setModuleDefault(result, mod);
27
+ return result;
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.setColorEnabled = setColorEnabled;
31
+ exports.getColorEnabled = getColorEnabled;
32
+ exports.reset = reset;
33
+ exports.bold = bold;
34
+ exports.dim = dim;
35
+ exports.italic = italic;
36
+ exports.underline = underline;
37
+ exports.inverse = inverse;
38
+ exports.hidden = hidden;
39
+ exports.strikethrough = strikethrough;
40
+ exports.black = black;
41
+ exports.red = red;
42
+ exports.green = green;
43
+ exports.yellow = yellow;
44
+ exports.blue = blue;
45
+ exports.magenta = magenta;
46
+ exports.cyan = cyan;
47
+ exports.white = white;
48
+ exports.gray = gray;
49
+ exports.brightBlack = brightBlack;
50
+ exports.brightRed = brightRed;
51
+ exports.brightGreen = brightGreen;
52
+ exports.brightYellow = brightYellow;
53
+ exports.brightBlue = brightBlue;
54
+ exports.brightMagenta = brightMagenta;
55
+ exports.brightCyan = brightCyan;
56
+ exports.brightWhite = brightWhite;
57
+ exports.bgBlack = bgBlack;
58
+ exports.bgRed = bgRed;
59
+ exports.bgGreen = bgGreen;
60
+ exports.bgYellow = bgYellow;
61
+ exports.bgBlue = bgBlue;
62
+ exports.bgMagenta = bgMagenta;
63
+ exports.bgCyan = bgCyan;
64
+ exports.bgWhite = bgWhite;
65
+ exports.bgBrightBlack = bgBrightBlack;
66
+ exports.bgBrightRed = bgBrightRed;
67
+ exports.bgBrightGreen = bgBrightGreen;
68
+ exports.bgBrightYellow = bgBrightYellow;
69
+ exports.bgBrightBlue = bgBrightBlue;
70
+ exports.bgBrightMagenta = bgBrightMagenta;
71
+ exports.bgBrightCyan = bgBrightCyan;
72
+ exports.bgBrightWhite = bgBrightWhite;
73
+ exports.rgb8 = rgb8;
74
+ exports.bgRgb8 = bgRgb8;
75
+ exports.rgb24 = rgb24;
76
+ exports.bgRgb24 = bgRgb24;
77
+ exports.stripAnsiCode = stripAnsiCode;
78
+ /**
79
+ * String formatters and utilities for dealing with ANSI color codes.
80
+ *
81
+ * > [!IMPORTANT]
82
+ * > If printing directly to the console, it's recommended to style console
83
+ * > output using CSS (guide
84
+ * > {@linkcode https://developer.mozilla.org/en-US/docs/Web/API/console#styling_console_output | here}).
85
+ *
86
+ * This module supports `NO_COLOR` environmental variable disabling any coloring
87
+ * if `NO_COLOR` is set.
88
+ *
89
+ * ```ts no-assert
90
+ * import {
91
+ * bgBlue,
92
+ * bgRgb24,
93
+ * bgRgb8,
94
+ * bold,
95
+ * italic,
96
+ * red,
97
+ * rgb24,
98
+ * rgb8,
99
+ * } from "@std/fmt/colors";
100
+ *
101
+ * console.log(bgBlue(italic(red(bold("Hello, World!")))));
102
+ *
103
+ * // also supports 8bit colors
104
+ *
105
+ * console.log(rgb8("Hello, World!", 42));
106
+ *
107
+ * console.log(bgRgb8("Hello, World!", 42));
108
+ *
109
+ * // and 24bit rgb
110
+ *
111
+ * console.log(rgb24("Hello, World!", {
112
+ * r: 41,
113
+ * g: 42,
114
+ * b: 43,
115
+ * }));
116
+ *
117
+ * console.log(bgRgb24("Hello, World!", {
118
+ * r: 41,
119
+ * g: 42,
120
+ * b: 43,
121
+ * }));
122
+ * ```
123
+ *
124
+ * @module
125
+ */
126
+ // deno-lint-ignore no-explicit-any
127
+ const dntShim = __importStar(require("../../../../../_dnt.shims.js"));
128
+ const { Deno } = dntShim.dntGlobalThis;
129
+ const noColor = typeof Deno?.noColor === "boolean"
130
+ ? Deno.noColor
131
+ : false;
132
+ let enabled = !noColor;
133
+ /**
134
+ * Enable or disable text color when styling.
135
+ *
136
+ * `@std/fmt/colors` automatically detects NO_COLOR environmental variable
137
+ * and disables text color. Use this API only when the automatic detection
138
+ * doesn't work.
139
+ *
140
+ * @example Usage
141
+ * ```ts no-assert
142
+ * import { setColorEnabled } from "@std/fmt/colors";
143
+ *
144
+ * // Disable text color
145
+ * setColorEnabled(false);
146
+ *
147
+ * // Enable text color
148
+ * setColorEnabled(true);
149
+ * ```
150
+ *
151
+ * @param value The boolean value to enable or disable text color
152
+ */
153
+ function setColorEnabled(value) {
154
+ if (Deno?.noColor) {
155
+ return;
156
+ }
157
+ enabled = value;
158
+ }
159
+ /**
160
+ * Get whether text color change is enabled or disabled.
161
+ *
162
+ * @example Usage
163
+ * ```ts no-assert
164
+ * import { getColorEnabled } from "@std/fmt/colors";
165
+ *
166
+ * console.log(getColorEnabled()); // true if enabled, false if disabled
167
+ * ```
168
+ * @returns `true` if text color is enabled, `false` otherwise
169
+ */
170
+ function getColorEnabled() {
171
+ return enabled;
172
+ }
173
+ /**
174
+ * Builds color code
175
+ * @param open
176
+ * @param close
177
+ */
178
+ function code(open, close) {
179
+ return {
180
+ open: `\x1b[${open.join(";")}m`,
181
+ close: `\x1b[${close}m`,
182
+ regexp: new RegExp(`\\x1b\\[${close}m`, "g"),
183
+ };
184
+ }
185
+ /**
186
+ * Applies color and background based on color code and its associated text
187
+ * @param str The text to apply color settings to
188
+ * @param code The color code to apply
189
+ */
190
+ function run(str, code) {
191
+ return enabled
192
+ ? `${code.open}${str.replace(code.regexp, code.open)}${code.close}`
193
+ : str;
194
+ }
195
+ /**
196
+ * Reset the text modified.
197
+ *
198
+ * @example Usage
199
+ * ```ts no-assert
200
+ * import { reset } from "@std/fmt/colors";
201
+ *
202
+ * console.log(reset("Hello, world!"));
203
+ * ```
204
+ *
205
+ * @param str The text to reset
206
+ * @returns The text with reset color
207
+ */
208
+ function reset(str) {
209
+ return run(str, code([0], 0));
210
+ }
211
+ /**
212
+ * Make the text bold.
213
+ *
214
+ * @example Usage
215
+ * ```ts no-assert
216
+ * import { bold } from "@std/fmt/colors";
217
+ *
218
+ * console.log(bold("Hello, world!"));
219
+ * ```
220
+ *
221
+ * @param str The text to make bold
222
+ * @returns The bold text
223
+ */
224
+ function bold(str) {
225
+ return run(str, code([1], 22));
226
+ }
227
+ /**
228
+ * The text emits only a small amount of light.
229
+ *
230
+ * @example Usage
231
+ * ```ts no-assert
232
+ * import { dim } from "@std/fmt/colors";
233
+ *
234
+ * console.log(dim("Hello, world!"));
235
+ * ```
236
+ *
237
+ * @param str The text to dim
238
+ * @returns The dimmed text
239
+ *
240
+ * Warning: Not all terminal emulators support `dim`.
241
+ * For compatibility across all terminals, use {@linkcode gray} or {@linkcode brightBlack} instead.
242
+ */
243
+ function dim(str) {
244
+ return run(str, code([2], 22));
245
+ }
246
+ /**
247
+ * Make the text italic.
248
+ *
249
+ * @example Usage
250
+ * ```ts no-assert
251
+ * import { italic } from "@std/fmt/colors";
252
+ *
253
+ * console.log(italic("Hello, world!"));
254
+ * ```
255
+ *
256
+ * @param str The text to make italic
257
+ * @returns The italic text
258
+ */
259
+ function italic(str) {
260
+ return run(str, code([3], 23));
261
+ }
262
+ /**
263
+ * Make the text underline.
264
+ *
265
+ * @example Usage
266
+ * ```ts no-assert
267
+ * import { underline } from "@std/fmt/colors";
268
+ *
269
+ * console.log(underline("Hello, world!"));
270
+ * ```
271
+ *
272
+ * @param str The text to underline
273
+ * @returns The underlined text
274
+ */
275
+ function underline(str) {
276
+ return run(str, code([4], 24));
277
+ }
278
+ /**
279
+ * Invert background color and text color.
280
+ *
281
+ * @example Usage
282
+ * ```ts no-assert
283
+ * import { inverse } from "@std/fmt/colors";
284
+ *
285
+ * console.log(inverse("Hello, world!"));
286
+ * ```
287
+ *
288
+ * @param str The text to invert its color
289
+ * @returns The inverted text
290
+ */
291
+ function inverse(str) {
292
+ return run(str, code([7], 27));
293
+ }
294
+ /**
295
+ * Make the text hidden.
296
+ *
297
+ * @example Usage
298
+ * ```ts no-assert
299
+ * import { hidden } from "@std/fmt/colors";
300
+ *
301
+ * console.log(hidden("Hello, world!"));
302
+ * ```
303
+ *
304
+ * @param str The text to hide
305
+ * @returns The hidden text
306
+ */
307
+ function hidden(str) {
308
+ return run(str, code([8], 28));
309
+ }
310
+ /**
311
+ * Put horizontal line through the center of the text.
312
+ *
313
+ * @example Usage
314
+ * ```ts no-assert
315
+ * import { strikethrough } from "@std/fmt/colors";
316
+ *
317
+ * console.log(strikethrough("Hello, world!"));
318
+ * ```
319
+ *
320
+ * @param str The text to strike through
321
+ * @returns The text with horizontal line through the center
322
+ */
323
+ function strikethrough(str) {
324
+ return run(str, code([9], 29));
325
+ }
326
+ /**
327
+ * Set text color to black.
328
+ *
329
+ * @example Usage
330
+ * ```ts no-assert
331
+ * import { black } from "@std/fmt/colors";
332
+ *
333
+ * console.log(black("Hello, world!"));
334
+ * ```
335
+ *
336
+ * @param str The text to make black
337
+ * @returns The black text
338
+ */
339
+ function black(str) {
340
+ return run(str, code([30], 39));
341
+ }
342
+ /**
343
+ * Set text color to red.
344
+ *
345
+ * @example Usage
346
+ * ```ts no-assert
347
+ * import { red } from "@std/fmt/colors";
348
+ *
349
+ * console.log(red("Hello, world!"));
350
+ * ```
351
+ *
352
+ * @param str The text to make red
353
+ * @returns The red text
354
+ */
355
+ function red(str) {
356
+ return run(str, code([31], 39));
357
+ }
358
+ /**
359
+ * Set text color to green.
360
+ *
361
+ * @example Usage
362
+ * ```ts no-assert
363
+ * import { green } from "@std/fmt/colors";
364
+ *
365
+ * console.log(green("Hello, world!"));
366
+ * ```
367
+ *
368
+ * @param str The text to make green
369
+ * @returns The green text
370
+ */
371
+ function green(str) {
372
+ return run(str, code([32], 39));
373
+ }
374
+ /**
375
+ * Set text color to yellow.
376
+ *
377
+ * @example Usage
378
+ * ```ts no-assert
379
+ * import { yellow } from "@std/fmt/colors";
380
+ *
381
+ * console.log(yellow("Hello, world!"));
382
+ * ```
383
+ *
384
+ * @param str The text to make yellow
385
+ * @returns The yellow text
386
+ */
387
+ function yellow(str) {
388
+ return run(str, code([33], 39));
389
+ }
390
+ /**
391
+ * Set text color to blue.
392
+ *
393
+ * @example Usage
394
+ * ```ts no-assert
395
+ * import { blue } from "@std/fmt/colors";
396
+ *
397
+ * console.log(blue("Hello, world!"));
398
+ * ```
399
+ *
400
+ * @param str The text to make blue
401
+ * @returns The blue text
402
+ */
403
+ function blue(str) {
404
+ return run(str, code([34], 39));
405
+ }
406
+ /**
407
+ * Set text color to magenta.
408
+ *
409
+ * @example Usage
410
+ * ```ts no-assert
411
+ * import { magenta } from "@std/fmt/colors";
412
+ *
413
+ * console.log(magenta("Hello, world!"));
414
+ * ```
415
+ *
416
+ * @param str The text to make magenta
417
+ * @returns The magenta text
418
+ */
419
+ function magenta(str) {
420
+ return run(str, code([35], 39));
421
+ }
422
+ /**
423
+ * Set text color to cyan.
424
+ *
425
+ * @example Usage
426
+ * ```ts no-assert
427
+ * import { cyan } from "@std/fmt/colors";
428
+ *
429
+ * console.log(cyan("Hello, world!"));
430
+ * ```
431
+ *
432
+ * @param str The text to make cyan
433
+ * @returns The cyan text
434
+ */
435
+ function cyan(str) {
436
+ return run(str, code([36], 39));
437
+ }
438
+ /**
439
+ * Set text color to white.
440
+ *
441
+ * @example Usage
442
+ * ```ts no-assert
443
+ * import { white } from "@std/fmt/colors";
444
+ *
445
+ * console.log(white("Hello, world!"));
446
+ * ```
447
+ *
448
+ * @param str The text to make white
449
+ * @returns The white text
450
+ */
451
+ function white(str) {
452
+ return run(str, code([37], 39));
453
+ }
454
+ /**
455
+ * Set text color to gray.
456
+ *
457
+ * @example Usage
458
+ * ```ts no-assert
459
+ * import { gray } from "@std/fmt/colors";
460
+ *
461
+ * console.log(gray("Hello, world!"));
462
+ * ```
463
+ *
464
+ * @param str The text to make gray
465
+ * @returns The gray text
466
+ */
467
+ function gray(str) {
468
+ return brightBlack(str);
469
+ }
470
+ /**
471
+ * Set text color to bright black.
472
+ *
473
+ * @example Usage
474
+ * ```ts no-assert
475
+ * import { brightBlack } from "@std/fmt/colors";
476
+ *
477
+ * console.log(brightBlack("Hello, world!"));
478
+ * ```
479
+ *
480
+ * @param str The text to make bright black
481
+ * @returns The bright black text
482
+ */
483
+ function brightBlack(str) {
484
+ return run(str, code([90], 39));
485
+ }
486
+ /**
487
+ * Set text color to bright red.
488
+ *
489
+ * @example Usage
490
+ * ```ts no-assert
491
+ * import { brightRed } from "@std/fmt/colors";
492
+ *
493
+ * console.log(brightRed("Hello, world!"));
494
+ * ```
495
+ *
496
+ * @param str The text to make bright red
497
+ * @returns The bright red text
498
+ */
499
+ function brightRed(str) {
500
+ return run(str, code([91], 39));
501
+ }
502
+ /**
503
+ * Set text color to bright green.
504
+ *
505
+ * @example Usage
506
+ * ```ts no-assert
507
+ * import { brightGreen } from "@std/fmt/colors";
508
+ *
509
+ * console.log(brightGreen("Hello, world!"));
510
+ * ```
511
+ *
512
+ * @param str The text to make bright green
513
+ * @returns The bright green text
514
+ */
515
+ function brightGreen(str) {
516
+ return run(str, code([92], 39));
517
+ }
518
+ /**
519
+ * Set text color to bright yellow.
520
+ *
521
+ * @example Usage
522
+ * ```ts no-assert
523
+ * import { brightYellow } from "@std/fmt/colors";
524
+ *
525
+ * console.log(brightYellow("Hello, world!"));
526
+ * ```
527
+ *
528
+ * @param str The text to make bright yellow
529
+ * @returns The bright yellow text
530
+ */
531
+ function brightYellow(str) {
532
+ return run(str, code([93], 39));
533
+ }
534
+ /**
535
+ * Set text color to bright blue.
536
+ *
537
+ * @example Usage
538
+ * ```ts no-assert
539
+ * import { brightBlue } from "@std/fmt/colors";
540
+ *
541
+ * console.log(brightBlue("Hello, world!"));
542
+ * ```
543
+ *
544
+ * @param str The text to make bright blue
545
+ * @returns The bright blue text
546
+ */
547
+ function brightBlue(str) {
548
+ return run(str, code([94], 39));
549
+ }
550
+ /**
551
+ * Set text color to bright magenta.
552
+ *
553
+ * @example Usage
554
+ * ```ts no-assert
555
+ * import { brightMagenta } from "@std/fmt/colors";
556
+ *
557
+ * console.log(brightMagenta("Hello, world!"));
558
+ * ```
559
+ *
560
+ * @param str The text to make bright magenta
561
+ * @returns The bright magenta text
562
+ */
563
+ function brightMagenta(str) {
564
+ return run(str, code([95], 39));
565
+ }
566
+ /**
567
+ * Set text color to bright cyan.
568
+ *
569
+ * @example Usage
570
+ * ```ts no-assert
571
+ * import { brightCyan } from "@std/fmt/colors";
572
+ *
573
+ * console.log(brightCyan("Hello, world!"));
574
+ * ```
575
+ *
576
+ * @param str The text to make bright cyan
577
+ * @returns The bright cyan text
578
+ */
579
+ function brightCyan(str) {
580
+ return run(str, code([96], 39));
581
+ }
582
+ /**
583
+ * Set text color to bright white.
584
+ *
585
+ * @example Usage
586
+ * ```ts no-assert
587
+ * import { brightWhite } from "@std/fmt/colors";
588
+ *
589
+ * console.log(brightWhite("Hello, world!"));
590
+ * ```
591
+ *
592
+ * @param str The text to make bright white
593
+ * @returns The bright white text
594
+ */
595
+ function brightWhite(str) {
596
+ return run(str, code([97], 39));
597
+ }
598
+ /**
599
+ * Set background color to black.
600
+ *
601
+ * @example Usage
602
+ * ```ts no-assert
603
+ * import { bgBlack } from "@std/fmt/colors";
604
+ *
605
+ * console.log(bgBlack("Hello, world!"));
606
+ * ```
607
+ *
608
+ * @param str The text to make its background black
609
+ * @returns The text with black background
610
+ */
611
+ function bgBlack(str) {
612
+ return run(str, code([40], 49));
613
+ }
614
+ /**
615
+ * Set background color to red.
616
+ *
617
+ * @example Usage
618
+ * ```ts no-assert
619
+ * import { bgRed } from "@std/fmt/colors";
620
+ *
621
+ * console.log(bgRed("Hello, world!"));
622
+ * ```
623
+ *
624
+ * @param str The text to make its background red
625
+ * @returns The text with red background
626
+ */
627
+ function bgRed(str) {
628
+ return run(str, code([41], 49));
629
+ }
630
+ /**
631
+ * Set background color to green.
632
+ *
633
+ * @example Usage
634
+ * ```ts no-assert
635
+ * import { bgGreen } from "@std/fmt/colors";
636
+ *
637
+ * console.log(bgGreen("Hello, world!"));
638
+ * ```
639
+ *
640
+ * @param str The text to make its background green
641
+ * @returns The text with green background
642
+ */
643
+ function bgGreen(str) {
644
+ return run(str, code([42], 49));
645
+ }
646
+ /**
647
+ * Set background color to yellow.
648
+ *
649
+ * @example Usage
650
+ * ```ts no-assert
651
+ * import { bgYellow } from "@std/fmt/colors";
652
+ *
653
+ * console.log(bgYellow("Hello, world!"));
654
+ * ```
655
+ *
656
+ * @param str The text to make its background yellow
657
+ * @returns The text with yellow background
658
+ */
659
+ function bgYellow(str) {
660
+ return run(str, code([43], 49));
661
+ }
662
+ /**
663
+ * Set background color to blue.
664
+ *
665
+ * @example Usage
666
+ * ```ts no-assert
667
+ * import { bgBlue } from "@std/fmt/colors";
668
+ *
669
+ * console.log(bgBlue("Hello, world!"));
670
+ * ```
671
+ *
672
+ * @param str The text to make its background blue
673
+ * @returns The text with blue background
674
+ */
675
+ function bgBlue(str) {
676
+ return run(str, code([44], 49));
677
+ }
678
+ /**
679
+ * Set background color to magenta.
680
+ *
681
+ * @example Usage
682
+ * ```ts no-assert
683
+ * import { bgMagenta } from "@std/fmt/colors";
684
+ *
685
+ * console.log(bgMagenta("Hello, world!"));
686
+ * ```
687
+ *
688
+ * @param str The text to make its background magenta
689
+ * @returns The text with magenta background
690
+ */
691
+ function bgMagenta(str) {
692
+ return run(str, code([45], 49));
693
+ }
694
+ /**
695
+ * Set background color to cyan.
696
+ *
697
+ * @example Usage
698
+ * ```ts no-assert
699
+ * import { bgCyan } from "@std/fmt/colors";
700
+ *
701
+ * console.log(bgCyan("Hello, world!"));
702
+ * ```
703
+ *
704
+ * @param str The text to make its background cyan
705
+ * @returns The text with cyan background
706
+ */
707
+ function bgCyan(str) {
708
+ return run(str, code([46], 49));
709
+ }
710
+ /**
711
+ * Set background color to white.
712
+ *
713
+ * @example Usage
714
+ * ```ts no-assert
715
+ * import { bgWhite } from "@std/fmt/colors";
716
+ *
717
+ * console.log(bgWhite("Hello, world!"));
718
+ * ```
719
+ *
720
+ * @param str The text to make its background white
721
+ * @returns The text with white background
722
+ */
723
+ function bgWhite(str) {
724
+ return run(str, code([47], 49));
725
+ }
726
+ /**
727
+ * Set background color to bright black.
728
+ *
729
+ * @example Usage
730
+ * ```ts no-assert
731
+ * import { bgBrightBlack } from "@std/fmt/colors";
732
+ *
733
+ * console.log(bgBrightBlack("Hello, world!"));
734
+ * ```
735
+ *
736
+ * @param str The text to make its background bright black
737
+ * @returns The text with bright black background
738
+ */
739
+ function bgBrightBlack(str) {
740
+ return run(str, code([100], 49));
741
+ }
742
+ /**
743
+ * Set background color to bright red.
744
+ *
745
+ * @example Usage
746
+ * ```ts no-assert
747
+ * import { bgBrightRed } from "@std/fmt/colors";
748
+ *
749
+ * console.log(bgBrightRed("Hello, world!"));
750
+ * ```
751
+ *
752
+ * @param str The text to make its background bright red
753
+ * @returns The text with bright red background
754
+ */
755
+ function bgBrightRed(str) {
756
+ return run(str, code([101], 49));
757
+ }
758
+ /**
759
+ * Set background color to bright green.
760
+ *
761
+ * @example Usage
762
+ * ```ts no-assert
763
+ * import { bgBrightGreen } from "@std/fmt/colors";
764
+ *
765
+ * console.log(bgBrightGreen("Hello, world!"));
766
+ * ```
767
+ *
768
+ * @param str The text to make its background bright green
769
+ * @returns The text with bright green background
770
+ */
771
+ function bgBrightGreen(str) {
772
+ return run(str, code([102], 49));
773
+ }
774
+ /**
775
+ * Set background color to bright yellow.
776
+ *
777
+ * @example Usage
778
+ * ```ts no-assert
779
+ * import { bgBrightYellow } from "@std/fmt/colors";
780
+ *
781
+ * console.log(bgBrightYellow("Hello, world!"));
782
+ * ```
783
+ *
784
+ * @param str The text to make its background bright yellow
785
+ * @returns The text with bright yellow background
786
+ */
787
+ function bgBrightYellow(str) {
788
+ return run(str, code([103], 49));
789
+ }
790
+ /**
791
+ * Set background color to bright blue.
792
+ *
793
+ * @example Usage
794
+ * ```ts no-assert
795
+ * import { bgBrightBlue } from "@std/fmt/colors";
796
+ *
797
+ * console.log(bgBrightBlue("Hello, world!"));
798
+ * ```
799
+ *
800
+ * @param str The text to make its background bright blue
801
+ * @returns The text with bright blue background
802
+ */
803
+ function bgBrightBlue(str) {
804
+ return run(str, code([104], 49));
805
+ }
806
+ /**
807
+ * Set background color to bright magenta.
808
+ *
809
+ * @example Usage
810
+ * ```ts no-assert
811
+ * import { bgBrightMagenta } from "@std/fmt/colors";
812
+ *
813
+ * console.log(bgBrightMagenta("Hello, world!"));
814
+ * ```
815
+ *
816
+ * @param str The text to make its background bright magenta
817
+ * @returns The text with bright magenta background
818
+ */
819
+ function bgBrightMagenta(str) {
820
+ return run(str, code([105], 49));
821
+ }
822
+ /**
823
+ * Set background color to bright cyan.
824
+ *
825
+ * @example Usage
826
+ * ```ts no-assert
827
+ * import { bgBrightCyan } from "@std/fmt/colors";
828
+ *
829
+ * console.log(bgBrightCyan("Hello, world!"));
830
+ * ```
831
+ *
832
+ * @param str The text to make its background bright cyan
833
+ * @returns The text with bright cyan background
834
+ */
835
+ function bgBrightCyan(str) {
836
+ return run(str, code([106], 49));
837
+ }
838
+ /**
839
+ * Set background color to bright white.
840
+ *
841
+ * @example Usage
842
+ * ```ts no-assert
843
+ * import { bgBrightWhite } from "@std/fmt/colors";
844
+ *
845
+ * console.log(bgBrightWhite("Hello, world!"));
846
+ * ```
847
+ *
848
+ * @param str The text to make its background bright white
849
+ * @returns The text with bright white background
850
+ */
851
+ function bgBrightWhite(str) {
852
+ return run(str, code([107], 49));
853
+ }
854
+ /* Special Color Sequences */
855
+ /**
856
+ * Clam and truncate color codes
857
+ * @param n The input number
858
+ * @param max The number to truncate to
859
+ * @param min The number to truncate from
860
+ */
861
+ function clampAndTruncate(n, max = 255, min = 0) {
862
+ return Math.trunc(Math.max(Math.min(n, max), min));
863
+ }
864
+ /**
865
+ * Set text color using paletted 8bit colors.
866
+ * https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
867
+ *
868
+ * @example Usage
869
+ * ```ts no-assert
870
+ * import { rgb8 } from "@std/fmt/colors";
871
+ *
872
+ * console.log(rgb8("Hello, world!", 42));
873
+ * ```
874
+ *
875
+ * @param str The text color to apply paletted 8bit colors to
876
+ * @param color The color code
877
+ * @returns The text with paletted 8bit color
878
+ */
879
+ function rgb8(str, color) {
880
+ return run(str, code([38, 5, clampAndTruncate(color)], 39));
881
+ }
882
+ /**
883
+ * Set background color using paletted 8bit colors.
884
+ * https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
885
+ *
886
+ * @example Usage
887
+ * ```ts no-assert
888
+ * import { bgRgb8 } from "@std/fmt/colors";
889
+ *
890
+ * console.log(bgRgb8("Hello, world!", 42));
891
+ * ```
892
+ *
893
+ * @param str The text color to apply paletted 8bit background colors to
894
+ * @param color code
895
+ * @returns The text with paletted 8bit background color
896
+ */
897
+ function bgRgb8(str, color) {
898
+ return run(str, code([48, 5, clampAndTruncate(color)], 49));
899
+ }
900
+ /**
901
+ * Set text color using 24bit rgb.
902
+ * `color` can be a number in range `0x000000` to `0xffffff` or
903
+ * an `Rgb`.
904
+ *
905
+ * @example To produce the color magenta:
906
+ * ```ts no-assert
907
+ * import { rgb24 } from "@std/fmt/colors";
908
+ *
909
+ * rgb24("foo", 0xff00ff);
910
+ * rgb24("foo", {r: 255, g: 0, b: 255});
911
+ * ```
912
+ * @param str The text color to apply 24bit rgb to
913
+ * @param color The color code
914
+ * @returns The text with 24bit rgb color
915
+ */
916
+ function rgb24(str, color) {
917
+ if (typeof color === "number") {
918
+ return run(str, code([38, 2, (color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff], 39));
919
+ }
920
+ return run(str, code([
921
+ 38,
922
+ 2,
923
+ clampAndTruncate(color.r),
924
+ clampAndTruncate(color.g),
925
+ clampAndTruncate(color.b),
926
+ ], 39));
927
+ }
928
+ /**
929
+ * Set background color using 24bit rgb.
930
+ * `color` can be a number in range `0x000000` to `0xffffff` or
931
+ * an `Rgb`.
932
+ *
933
+ * @example To produce the color magenta:
934
+ * ```ts no-assert
935
+ * import { bgRgb24 } from "@std/fmt/colors";
936
+ *
937
+ * bgRgb24("foo", 0xff00ff);
938
+ * bgRgb24("foo", {r: 255, g: 0, b: 255});
939
+ * ```
940
+ * @param str The text color to apply 24bit rgb to
941
+ * @param color The color code
942
+ * @returns The text with 24bit rgb color
943
+ */
944
+ function bgRgb24(str, color) {
945
+ if (typeof color === "number") {
946
+ return run(str, code([48, 2, (color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff], 49));
947
+ }
948
+ return run(str, code([
949
+ 48,
950
+ 2,
951
+ clampAndTruncate(color.r),
952
+ clampAndTruncate(color.g),
953
+ clampAndTruncate(color.b),
954
+ ], 49));
955
+ }
956
+ // https://github.com/chalk/ansi-regex/blob/02fa893d619d3da85411acc8fd4e2eea0e95a9d9/index.js
957
+ const ANSI_PATTERN = new RegExp([
958
+ "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
959
+ "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TXZcf-nq-uy=><~]))",
960
+ ].join("|"), "g");
961
+ /**
962
+ * Remove ANSI escape codes from the string.
963
+ *
964
+ * @example Usage
965
+ * ```ts no-assert
966
+ * import { stripAnsiCode, red } from "@std/fmt/colors";
967
+ *
968
+ * console.log(stripAnsiCode(red("Hello, world!")));
969
+ * ```
970
+ *
971
+ * @param string The text to remove ANSI escape codes from
972
+ * @returns The text without ANSI escape codes
973
+ */
974
+ function stripAnsiCode(string) {
975
+ return string.replace(ANSI_PATTERN, "");
976
+ }