@peteanderson/ansi 0.2.0 → 0.2.1
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.
- package/README.md +5 -4
- package/dist/ansi.d.ts +4 -4
- package/dist/index.d.ts +45 -174
- package/dist/sgr/color.d.ts +62 -0
- package/dist/sgr/color.js +111 -0
- package/dist/sgr/index.d.ts +59 -0
- package/dist/sgr/index.js +6 -0
- package/dist/sgr/reset.d.ts +1 -0
- package/dist/sgr/reset.js +3 -0
- package/dist/sgr/sgr.d.ts +14 -0
- package/dist/sgr/sgr.js +47 -0
- package/dist/sgr/style.d.ts +13 -0
- package/dist/sgr/style.js +16 -0
- package/dist/sgr/utils.d.ts +2 -0
- package/dist/sgr/utils.js +16 -0
- package/dist/strip.d.ts +1 -1
- package/dist/strip.js +2 -2
- package/package.json +1 -1
- package/src/sgr/color.js +130 -0
- package/src/sgr/index.js +5 -0
- package/src/sgr/reset.js +3 -0
- package/src/sgr/sgr.js +66 -0
- package/src/sgr/style.js +19 -0
- package/src/sgr/utils.js +20 -0
- package/src/strip.js +2 -2
- package/dist/sgr.d.ts +0 -205
- package/dist/sgr.js +0 -89
- package/src/sgr.js +0 -113
package/dist/strip.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const { reset } = require("./sgr");
|
|
3
3
|
const rxCSI = /\x1b\[[0-?]*[ -/]*[@-~]/g;
|
|
4
|
-
const rxUnsafe = /\x1b\[[0-?]*[ -/]*[@-ln-~]/g; // Everything except SGR (m)
|
|
4
|
+
const rxUnsafe = /\x1b\[[0-?]*[ -/]*[@-ln-~]/g; // Everything except SGR codes (m).
|
|
5
5
|
/**
|
|
6
6
|
* Remove all ANSI escape codes from the given text.
|
|
7
7
|
* @type {(text: string) => string}
|
|
8
8
|
*/
|
|
9
9
|
const strip = text => text.replace(rxCSI, '');
|
|
10
10
|
/**
|
|
11
|
-
* Remove all ANSI escape codes except SGR (m)
|
|
11
|
+
* Remove all ANSI escape codes except SGR codes (m), which are used for color and styling.
|
|
12
12
|
* @type {(text: string) => string}
|
|
13
13
|
*/
|
|
14
14
|
const sanitize = text => text.replace(rxUnsafe, '');
|
package/package.json
CHANGED
package/src/sgr/color.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const {sgr} = require("./sgr");
|
|
4
|
+
|
|
5
|
+
/** @type {(r: number, g: number, b: number, open: number, close: number) => (text: string) => string} */
|
|
6
|
+
const rgb = (r, g, b, open, close) => sgr([open, 2, r, g, b], close);
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @overload
|
|
10
|
+
* @param {number} code
|
|
11
|
+
* @param {number} open
|
|
12
|
+
* @param {number} close
|
|
13
|
+
* @returns {(text: string) => string}
|
|
14
|
+
*//**
|
|
15
|
+
* @overload
|
|
16
|
+
* @param {number} r
|
|
17
|
+
* @param {number} g
|
|
18
|
+
* @param {number} b
|
|
19
|
+
* @param {number} open
|
|
20
|
+
* @param {number} close
|
|
21
|
+
* @returns {(text: string) => string}
|
|
22
|
+
*//**
|
|
23
|
+
@type {
|
|
24
|
+
(
|
|
25
|
+
...args: [number, number, number] | [number, number, number, number, number]
|
|
26
|
+
) => (text: string) => string}
|
|
27
|
+
*/
|
|
28
|
+
function x256(...args) {
|
|
29
|
+
if (args.length === 3)
|
|
30
|
+
return sgr([args[1], 5, args[0]], args[2]);
|
|
31
|
+
|
|
32
|
+
const [r, g, b, open, close] = args;
|
|
33
|
+
if (r === g && g === b) {
|
|
34
|
+
// grayscale
|
|
35
|
+
return sgr([open, 5, 232 + Math.floor(r * 24 / 256)], close);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 6x6x6 color cube
|
|
39
|
+
return sgr(
|
|
40
|
+
[
|
|
41
|
+
open,
|
|
42
|
+
5,
|
|
43
|
+
16 +
|
|
44
|
+
Math.floor(r * 6 / 256) * 36 +
|
|
45
|
+
Math.floor(g * 6 / 256) * 6 +
|
|
46
|
+
Math.floor(b * 6 / 256)
|
|
47
|
+
],
|
|
48
|
+
close,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const fg = {
|
|
53
|
+
black : sgr(30, 39),
|
|
54
|
+
red : sgr(31, 39),
|
|
55
|
+
green : sgr(32, 39),
|
|
56
|
+
yellow : sgr(33, 39),
|
|
57
|
+
blue : sgr(34, 39),
|
|
58
|
+
magenta : sgr(35, 39),
|
|
59
|
+
cyan : sgr(36, 39),
|
|
60
|
+
white : sgr(37, 39),
|
|
61
|
+
|
|
62
|
+
brightBlack : sgr(90, 39),
|
|
63
|
+
brightRed : sgr(91, 39),
|
|
64
|
+
brightGreen : sgr(92, 39),
|
|
65
|
+
brightYellow : sgr(93, 39),
|
|
66
|
+
brightBlue : sgr(94, 39),
|
|
67
|
+
brightMagenta : sgr(95, 39),
|
|
68
|
+
brightCyan : sgr(96, 39),
|
|
69
|
+
brightWhite : sgr(97, 39),
|
|
70
|
+
|
|
71
|
+
default : "\x1b[39m",
|
|
72
|
+
|
|
73
|
+
/** @type {(r: number, g: number, b: number) => (text: string) => string} */
|
|
74
|
+
rgb : (r, g, b) => rgb(r, g, b, 38, 39),
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @overload
|
|
78
|
+
* @param {number} code
|
|
79
|
+
* @returns {(text: string) => string}
|
|
80
|
+
*//**
|
|
81
|
+
* @param {number} r
|
|
82
|
+
* @param {number} g
|
|
83
|
+
* @param {number} b
|
|
84
|
+
* @returns {(text: string) => string}
|
|
85
|
+
*//** @type {(arg0: number, arg1?: number, arg2?: number) => (text: string) => string} */
|
|
86
|
+
x256 : (arg0, arg1, arg2) => arg1 === undefined || arg2 === undefined
|
|
87
|
+
? x256(arg0 , 38, 39)
|
|
88
|
+
: x256(arg0, arg1, arg2, 38, 39),
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const bg = {
|
|
92
|
+
black : sgr(40, 49),
|
|
93
|
+
red : sgr(41, 49),
|
|
94
|
+
green : sgr(42, 49),
|
|
95
|
+
yellow : sgr(43, 49),
|
|
96
|
+
blue : sgr(44, 49),
|
|
97
|
+
magenta : sgr(45, 49),
|
|
98
|
+
cyan : sgr(46, 49),
|
|
99
|
+
white : sgr(47, 49),
|
|
100
|
+
|
|
101
|
+
brightBlack : sgr(100, 49),
|
|
102
|
+
brightRed : sgr(101, 49),
|
|
103
|
+
brightGreen : sgr(102, 49),
|
|
104
|
+
brightYellow : sgr(103, 49),
|
|
105
|
+
brightBlue : sgr(104, 49),
|
|
106
|
+
brightMagenta : sgr(105, 49),
|
|
107
|
+
brightCyan : sgr(106, 49),
|
|
108
|
+
brightWhite : sgr(107, 49),
|
|
109
|
+
|
|
110
|
+
default : "\x1b[49m",
|
|
111
|
+
|
|
112
|
+
/** @type {(r: number, g: number, b: number) => (text: string) => string} */
|
|
113
|
+
rgb : (r, g, b) => rgb(r, g, b, 48, 49),
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @overload
|
|
117
|
+
* @param {number} code
|
|
118
|
+
* @returns {(text: string) => string}
|
|
119
|
+
*//**
|
|
120
|
+
* @param {number} r
|
|
121
|
+
* @param {number} g
|
|
122
|
+
* @param {number} b
|
|
123
|
+
* @returns {(text: string) => string}
|
|
124
|
+
*//** @type {(arg0: number, arg1?: number, arg2?: number) => (text: string) => string} */
|
|
125
|
+
x256 : (arg0, arg1, arg2) => arg1 === undefined || arg2 === undefined
|
|
126
|
+
? x256(arg0 , 48, 49)
|
|
127
|
+
: x256(arg0, arg1, arg2, 48, 49),
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
module.exports = {fg, bg};
|
package/src/sgr/index.js
ADDED
package/src/sgr/reset.js
ADDED
package/src/sgr/sgr.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const $codes = Symbol();
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
@typedef {number | number[]} Code
|
|
7
|
+
@typedef {{
|
|
8
|
+
(text: string): string;
|
|
9
|
+
open : string;
|
|
10
|
+
close : string;
|
|
11
|
+
[$codes] : {open: Code, close: Code};
|
|
12
|
+
combine : (...styles: SGR[]) => SGR;
|
|
13
|
+
}} SGR
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** @type {(code: Code, codes: Code[]) => Code} */
|
|
17
|
+
function combine(code, codes, ) {
|
|
18
|
+
if (!codes.length)
|
|
19
|
+
return code;
|
|
20
|
+
|
|
21
|
+
const rtn = Array.isArray(code) ? [...code] : [code];
|
|
22
|
+
|
|
23
|
+
for (const c of codes) {
|
|
24
|
+
if (Array.isArray(c))
|
|
25
|
+
rtn.push(...c);
|
|
26
|
+
else
|
|
27
|
+
rtn.push(c);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return rtn;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** @type {(code: Code) => string | number} */
|
|
34
|
+
const codeSequence = code => Array.isArray(code) ? code.join(';') : code;
|
|
35
|
+
|
|
36
|
+
/** @type {(open: Code, close: Code, reset?: boolean) => SGR} */
|
|
37
|
+
function sgr(open, close, reset = false) {
|
|
38
|
+
const openCode = codeSequence(open);
|
|
39
|
+
const closeCode = codeSequence(close);
|
|
40
|
+
const openSequence = `\x1b[${openCode}m`;
|
|
41
|
+
const closeSequence = `\x1b[${closeCode}m`;
|
|
42
|
+
const reopenCode = reset ? `${closeCode};${openCode}` : openCode;
|
|
43
|
+
|
|
44
|
+
const rxClose = new RegExp(
|
|
45
|
+
`(?<start>\\x1b\\[(?:\\d+;)*)${closeCode}(?<end>(?:;\\d+)*m)`,
|
|
46
|
+
"g"
|
|
47
|
+
);
|
|
48
|
+
const replace = `$<start>${reopenCode}$<end>`;
|
|
49
|
+
|
|
50
|
+
/** @type {(text: string) => string} */
|
|
51
|
+
const func = s => openSequence + s.replace(rxClose, replace) + closeSequence
|
|
52
|
+
|
|
53
|
+
return Object.assign(func, {
|
|
54
|
+
[$codes] : {open, close},
|
|
55
|
+
open : openSequence,
|
|
56
|
+
close : closeSequence,
|
|
57
|
+
|
|
58
|
+
/** @type {(...styles: SGR[]) => SGR} */
|
|
59
|
+
combine: (...styles) => sgr(
|
|
60
|
+
combine(open, styles.map(s => s[$codes].open)),
|
|
61
|
+
combine(close, styles.map(s => s[$codes].close)),
|
|
62
|
+
),
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
module.exports = {sgr};
|
package/src/sgr/style.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const {sgr} = require("./sgr");
|
|
4
|
+
|
|
5
|
+
const style = {
|
|
6
|
+
bold : sgr(1, 22, true),
|
|
7
|
+
dim : sgr(2, 22, true),
|
|
8
|
+
italic : sgr(3, 23),
|
|
9
|
+
underline : sgr(4, 24),
|
|
10
|
+
inverse : sgr(7, 27),
|
|
11
|
+
hidden : sgr(8, 28),
|
|
12
|
+
strikethrough : sgr(9, 29),
|
|
13
|
+
doubleUnderline : sgr(21, 24),
|
|
14
|
+
frame : sgr(51, 54),
|
|
15
|
+
encircle : sgr(52, 54),
|
|
16
|
+
overline : sgr(53, 55),
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
module.exports = {style};
|
package/src/sgr/utils.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** @typedef {number | number[]} Code */
|
|
2
|
+
|
|
3
|
+
/** @type {(code: Code, codes: Code[]) => Code} */
|
|
4
|
+
function combine(code, codes, ) {
|
|
5
|
+
if (!codes.length)
|
|
6
|
+
return code;
|
|
7
|
+
|
|
8
|
+
const rtn = Array.isArray(code) ? [...code] : [code];
|
|
9
|
+
|
|
10
|
+
for (const c of codes) {
|
|
11
|
+
if (Array.isArray(c))
|
|
12
|
+
rtn.push(...c);
|
|
13
|
+
else
|
|
14
|
+
rtn.push(c);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return rtn;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports = {combine};
|
package/src/strip.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const {reset} = require("./sgr");
|
|
4
4
|
|
|
5
5
|
const rxCSI = /\x1b\[[0-?]*[ -/]*[@-~]/g;
|
|
6
|
-
const rxUnsafe = /\x1b\[[0-?]*[ -/]*[@-ln-~]/g; // Everything except SGR (m)
|
|
6
|
+
const rxUnsafe = /\x1b\[[0-?]*[ -/]*[@-ln-~]/g; // Everything except SGR codes (m).
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Remove all ANSI escape codes from the given text.
|
|
@@ -12,7 +12,7 @@ const rxUnsafe = /\x1b\[[0-?]*[ -/]*[@-ln-~]/g; // Everything except SGR (m) cod
|
|
|
12
12
|
const strip = text => text.replace(rxCSI, '');
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* Remove all ANSI escape codes except SGR (m)
|
|
15
|
+
* Remove all ANSI escape codes except SGR codes (m), which are used for color and styling.
|
|
16
16
|
* @type {(text: string) => string}
|
|
17
17
|
*/
|
|
18
18
|
const sanitize = text => text.replace(rxUnsafe, '');
|
package/dist/sgr.d.ts
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
export const reset: "\u001B[0m";
|
|
2
|
-
export namespace style {
|
|
3
|
-
let bold: ((s: string) => string) & {
|
|
4
|
-
open: string;
|
|
5
|
-
close: string;
|
|
6
|
-
};
|
|
7
|
-
let dim: ((s: string) => string) & {
|
|
8
|
-
open: string;
|
|
9
|
-
close: string;
|
|
10
|
-
};
|
|
11
|
-
let italic: ((s: string) => string) & {
|
|
12
|
-
open: string;
|
|
13
|
-
close: string;
|
|
14
|
-
};
|
|
15
|
-
let underline: ((s: string) => string) & {
|
|
16
|
-
open: string;
|
|
17
|
-
close: string;
|
|
18
|
-
};
|
|
19
|
-
let inverse: ((s: string) => string) & {
|
|
20
|
-
open: string;
|
|
21
|
-
close: string;
|
|
22
|
-
};
|
|
23
|
-
let hidden: ((s: string) => string) & {
|
|
24
|
-
open: string;
|
|
25
|
-
close: string;
|
|
26
|
-
};
|
|
27
|
-
let strikethrough: ((s: string) => string) & {
|
|
28
|
-
open: string;
|
|
29
|
-
close: string;
|
|
30
|
-
};
|
|
31
|
-
let doubleUnderline: ((s: string) => string) & {
|
|
32
|
-
open: string;
|
|
33
|
-
close: string;
|
|
34
|
-
};
|
|
35
|
-
let frame: ((s: string) => string) & {
|
|
36
|
-
open: string;
|
|
37
|
-
close: string;
|
|
38
|
-
};
|
|
39
|
-
let encircle: ((s: string) => string) & {
|
|
40
|
-
open: string;
|
|
41
|
-
close: string;
|
|
42
|
-
};
|
|
43
|
-
let overline: ((s: string) => string) & {
|
|
44
|
-
open: string;
|
|
45
|
-
close: string;
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
export namespace fg {
|
|
49
|
-
export let black: ((s: string) => string) & {
|
|
50
|
-
open: string;
|
|
51
|
-
close: string;
|
|
52
|
-
};
|
|
53
|
-
export let red: ((s: string) => string) & {
|
|
54
|
-
open: string;
|
|
55
|
-
close: string;
|
|
56
|
-
};
|
|
57
|
-
export let green: ((s: string) => string) & {
|
|
58
|
-
open: string;
|
|
59
|
-
close: string;
|
|
60
|
-
};
|
|
61
|
-
export let yellow: ((s: string) => string) & {
|
|
62
|
-
open: string;
|
|
63
|
-
close: string;
|
|
64
|
-
};
|
|
65
|
-
export let blue: ((s: string) => string) & {
|
|
66
|
-
open: string;
|
|
67
|
-
close: string;
|
|
68
|
-
};
|
|
69
|
-
export let magenta: ((s: string) => string) & {
|
|
70
|
-
open: string;
|
|
71
|
-
close: string;
|
|
72
|
-
};
|
|
73
|
-
export let cyan: ((s: string) => string) & {
|
|
74
|
-
open: string;
|
|
75
|
-
close: string;
|
|
76
|
-
};
|
|
77
|
-
export let white: ((s: string) => string) & {
|
|
78
|
-
open: string;
|
|
79
|
-
close: string;
|
|
80
|
-
};
|
|
81
|
-
export let brightBlack: ((s: string) => string) & {
|
|
82
|
-
open: string;
|
|
83
|
-
close: string;
|
|
84
|
-
};
|
|
85
|
-
export let brightRed: ((s: string) => string) & {
|
|
86
|
-
open: string;
|
|
87
|
-
close: string;
|
|
88
|
-
};
|
|
89
|
-
export let brightGreen: ((s: string) => string) & {
|
|
90
|
-
open: string;
|
|
91
|
-
close: string;
|
|
92
|
-
};
|
|
93
|
-
export let brightYellow: ((s: string) => string) & {
|
|
94
|
-
open: string;
|
|
95
|
-
close: string;
|
|
96
|
-
};
|
|
97
|
-
export let brightBlue: ((s: string) => string) & {
|
|
98
|
-
open: string;
|
|
99
|
-
close: string;
|
|
100
|
-
};
|
|
101
|
-
export let brightMagenta: ((s: string) => string) & {
|
|
102
|
-
open: string;
|
|
103
|
-
close: string;
|
|
104
|
-
};
|
|
105
|
-
export let brightCyan: ((s: string) => string) & {
|
|
106
|
-
open: string;
|
|
107
|
-
close: string;
|
|
108
|
-
};
|
|
109
|
-
export let brightWhite: ((s: string) => string) & {
|
|
110
|
-
open: string;
|
|
111
|
-
close: string;
|
|
112
|
-
};
|
|
113
|
-
let _default: string;
|
|
114
|
-
export { _default as default };
|
|
115
|
-
export let rgb: (r: number, g: number, b: number) => (text: string) => string;
|
|
116
|
-
export let x256: (r: number, g: number, b: number) => (text: string) => string;
|
|
117
|
-
}
|
|
118
|
-
export namespace bg {
|
|
119
|
-
let black_1: ((s: string) => string) & {
|
|
120
|
-
open: string;
|
|
121
|
-
close: string;
|
|
122
|
-
};
|
|
123
|
-
export { black_1 as black };
|
|
124
|
-
let red_1: ((s: string) => string) & {
|
|
125
|
-
open: string;
|
|
126
|
-
close: string;
|
|
127
|
-
};
|
|
128
|
-
export { red_1 as red };
|
|
129
|
-
let green_1: ((s: string) => string) & {
|
|
130
|
-
open: string;
|
|
131
|
-
close: string;
|
|
132
|
-
};
|
|
133
|
-
export { green_1 as green };
|
|
134
|
-
let yellow_1: ((s: string) => string) & {
|
|
135
|
-
open: string;
|
|
136
|
-
close: string;
|
|
137
|
-
};
|
|
138
|
-
export { yellow_1 as yellow };
|
|
139
|
-
let blue_1: ((s: string) => string) & {
|
|
140
|
-
open: string;
|
|
141
|
-
close: string;
|
|
142
|
-
};
|
|
143
|
-
export { blue_1 as blue };
|
|
144
|
-
let magenta_1: ((s: string) => string) & {
|
|
145
|
-
open: string;
|
|
146
|
-
close: string;
|
|
147
|
-
};
|
|
148
|
-
export { magenta_1 as magenta };
|
|
149
|
-
let cyan_1: ((s: string) => string) & {
|
|
150
|
-
open: string;
|
|
151
|
-
close: string;
|
|
152
|
-
};
|
|
153
|
-
export { cyan_1 as cyan };
|
|
154
|
-
let white_1: ((s: string) => string) & {
|
|
155
|
-
open: string;
|
|
156
|
-
close: string;
|
|
157
|
-
};
|
|
158
|
-
export { white_1 as white };
|
|
159
|
-
let brightBlack_1: ((s: string) => string) & {
|
|
160
|
-
open: string;
|
|
161
|
-
close: string;
|
|
162
|
-
};
|
|
163
|
-
export { brightBlack_1 as brightBlack };
|
|
164
|
-
let brightRed_1: ((s: string) => string) & {
|
|
165
|
-
open: string;
|
|
166
|
-
close: string;
|
|
167
|
-
};
|
|
168
|
-
export { brightRed_1 as brightRed };
|
|
169
|
-
let brightGreen_1: ((s: string) => string) & {
|
|
170
|
-
open: string;
|
|
171
|
-
close: string;
|
|
172
|
-
};
|
|
173
|
-
export { brightGreen_1 as brightGreen };
|
|
174
|
-
let brightYellow_1: ((s: string) => string) & {
|
|
175
|
-
open: string;
|
|
176
|
-
close: string;
|
|
177
|
-
};
|
|
178
|
-
export { brightYellow_1 as brightYellow };
|
|
179
|
-
let brightBlue_1: ((s: string) => string) & {
|
|
180
|
-
open: string;
|
|
181
|
-
close: string;
|
|
182
|
-
};
|
|
183
|
-
export { brightBlue_1 as brightBlue };
|
|
184
|
-
let brightMagenta_1: ((s: string) => string) & {
|
|
185
|
-
open: string;
|
|
186
|
-
close: string;
|
|
187
|
-
};
|
|
188
|
-
export { brightMagenta_1 as brightMagenta };
|
|
189
|
-
let brightCyan_1: ((s: string) => string) & {
|
|
190
|
-
open: string;
|
|
191
|
-
close: string;
|
|
192
|
-
};
|
|
193
|
-
export { brightCyan_1 as brightCyan };
|
|
194
|
-
let brightWhite_1: ((s: string) => string) & {
|
|
195
|
-
open: string;
|
|
196
|
-
close: string;
|
|
197
|
-
};
|
|
198
|
-
export { brightWhite_1 as brightWhite };
|
|
199
|
-
let _default_1: string;
|
|
200
|
-
export { _default_1 as default };
|
|
201
|
-
let rgb_1: (r: number, g: number, b: number) => (text: string) => string;
|
|
202
|
-
export { rgb_1 as rgb };
|
|
203
|
-
let x256_1: (r: number, g: number, b: number) => (text: string) => string;
|
|
204
|
-
export { x256_1 as x256 };
|
|
205
|
-
}
|
package/dist/sgr.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @param {number | string} open
|
|
4
|
-
* @param {number | string} close
|
|
5
|
-
*/
|
|
6
|
-
function sgr(open, close) {
|
|
7
|
-
const openSequence = `\x1b[${open}m`;
|
|
8
|
-
const closeSequence = `\x1b[${close}m`;
|
|
9
|
-
return Object.assign(
|
|
10
|
-
/** @type {(text: string) => string} */
|
|
11
|
-
s => openSequence +
|
|
12
|
-
s.replaceAll(openSequence, '').replaceAll(closeSequence, openSequence) +
|
|
13
|
-
closeSequence, { open: openSequence, close: closeSequence });
|
|
14
|
-
}
|
|
15
|
-
/** @type {(r: number, g: number, b: number, open: number, close: number) => (text: string) => string} */
|
|
16
|
-
const rgb = (r, g, b, open, close) => sgr(`${open};2;${r};${g};${b}`, close);
|
|
17
|
-
/** @type {(r: number, g: number, b: number, open: number, close: number) => (text: string) => string} */
|
|
18
|
-
function x256(r, g, b, open, close) {
|
|
19
|
-
if (r === g && g === b) {
|
|
20
|
-
// grayscale
|
|
21
|
-
return sgr(`${open};5;${232 + Math.floor(r * 24 / 256)}`, close);
|
|
22
|
-
}
|
|
23
|
-
// 6x6x6 color cube
|
|
24
|
-
return sgr(`${open};5;${16 +
|
|
25
|
-
Math.floor(r * 6 / 256) * 36 +
|
|
26
|
-
Math.floor(g * 6 / 256) * 6 +
|
|
27
|
-
Math.floor(b * 6 / 256)}`, close);
|
|
28
|
-
}
|
|
29
|
-
const reset = "\x1b[0m";
|
|
30
|
-
const style = {
|
|
31
|
-
bold: sgr(1, 22),
|
|
32
|
-
dim: sgr(2, 22),
|
|
33
|
-
italic: sgr(3, 23),
|
|
34
|
-
underline: sgr(4, 24),
|
|
35
|
-
inverse: sgr(7, 27),
|
|
36
|
-
hidden: sgr(8, 28),
|
|
37
|
-
strikethrough: sgr(9, 29),
|
|
38
|
-
doubleUnderline: sgr(21, 24),
|
|
39
|
-
frame: sgr(51, 54),
|
|
40
|
-
encircle: sgr(52, 54),
|
|
41
|
-
overline: sgr(53, 55),
|
|
42
|
-
};
|
|
43
|
-
const fg = {
|
|
44
|
-
black: sgr(30, 39),
|
|
45
|
-
red: sgr(31, 39),
|
|
46
|
-
green: sgr(32, 39),
|
|
47
|
-
yellow: sgr(33, 39),
|
|
48
|
-
blue: sgr(34, 39),
|
|
49
|
-
magenta: sgr(35, 39),
|
|
50
|
-
cyan: sgr(36, 39),
|
|
51
|
-
white: sgr(37, 39),
|
|
52
|
-
brightBlack: sgr(90, 39),
|
|
53
|
-
brightRed: sgr(91, 39),
|
|
54
|
-
brightGreen: sgr(92, 39),
|
|
55
|
-
brightYellow: sgr(93, 39),
|
|
56
|
-
brightBlue: sgr(94, 39),
|
|
57
|
-
brightMagenta: sgr(95, 39),
|
|
58
|
-
brightCyan: sgr(96, 39),
|
|
59
|
-
brightWhite: sgr(97, 39),
|
|
60
|
-
default: "\x1b[39m",
|
|
61
|
-
/** @type {(r: number, g: number, b: number) => (text: string) => string} */
|
|
62
|
-
rgb: (r, g, b) => rgb(r, g, b, 38, 39),
|
|
63
|
-
/** @type {(r: number, g: number, b: number) => (text: string) => string} */
|
|
64
|
-
x256: (r, g, b) => x256(r, g, b, 38, 39),
|
|
65
|
-
};
|
|
66
|
-
const bg = {
|
|
67
|
-
black: sgr(40, 49),
|
|
68
|
-
red: sgr(41, 49),
|
|
69
|
-
green: sgr(42, 49),
|
|
70
|
-
yellow: sgr(43, 49),
|
|
71
|
-
blue: sgr(44, 49),
|
|
72
|
-
magenta: sgr(45, 49),
|
|
73
|
-
cyan: sgr(46, 49),
|
|
74
|
-
white: sgr(47, 49),
|
|
75
|
-
brightBlack: sgr(100, 49),
|
|
76
|
-
brightRed: sgr(101, 49),
|
|
77
|
-
brightGreen: sgr(102, 49),
|
|
78
|
-
brightYellow: sgr(103, 49),
|
|
79
|
-
brightBlue: sgr(104, 49),
|
|
80
|
-
brightMagenta: sgr(105, 49),
|
|
81
|
-
brightCyan: sgr(106, 49),
|
|
82
|
-
brightWhite: sgr(107, 49),
|
|
83
|
-
default: "\x1b[49m",
|
|
84
|
-
/** @type {(r: number, g: number, b: number) => (text: string) => string} */
|
|
85
|
-
rgb: (r, g, b) => rgb(r, g, b, 48, 49),
|
|
86
|
-
/** @type {(r: number, g: number, b: number) => (text: string) => string} */
|
|
87
|
-
x256: (r, g, b) => x256(r, g, b, 48, 49),
|
|
88
|
-
};
|
|
89
|
-
module.exports = { reset, style, fg, bg };
|
package/src/sgr.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @param {number | string} open
|
|
5
|
-
* @param {number | string} close
|
|
6
|
-
*/
|
|
7
|
-
function sgr(open, close) {
|
|
8
|
-
const openSequence = `\x1b[${open}m`;
|
|
9
|
-
const closeSequence = `\x1b[${close}m`;
|
|
10
|
-
|
|
11
|
-
return Object.assign(
|
|
12
|
-
/** @type {(text: string) => string} */
|
|
13
|
-
s =>
|
|
14
|
-
openSequence +
|
|
15
|
-
s.replaceAll(openSequence, '').replaceAll(closeSequence, openSequence) +
|
|
16
|
-
closeSequence,
|
|
17
|
-
{open: openSequence, close: closeSequence}
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** @type {(r: number, g: number, b: number, open: number, close: number) => (text: string) => string} */
|
|
22
|
-
const rgb = (r, g, b, open, close) => sgr(`${open};2;${r};${g};${b}`, close);
|
|
23
|
-
|
|
24
|
-
/** @type {(r: number, g: number, b: number, open: number, close: number) => (text: string) => string} */
|
|
25
|
-
function x256(r, g, b, open, close) {
|
|
26
|
-
if (r === g && g === b) {
|
|
27
|
-
// grayscale
|
|
28
|
-
return sgr(`${open};5;${232 + Math.floor(r * 24 / 256)}`, close);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// 6x6x6 color cube
|
|
32
|
-
return sgr(
|
|
33
|
-
`${open};5;${
|
|
34
|
-
16 +
|
|
35
|
-
Math.floor(r * 6 / 256) * 36 +
|
|
36
|
-
Math.floor(g * 6 / 256) * 6 +
|
|
37
|
-
Math.floor(b * 6 / 256)
|
|
38
|
-
}`,
|
|
39
|
-
close,
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const reset = "\x1b[0m";
|
|
44
|
-
|
|
45
|
-
const style = {
|
|
46
|
-
bold : sgr(1, 22),
|
|
47
|
-
dim : sgr(2, 22),
|
|
48
|
-
italic : sgr(3, 23),
|
|
49
|
-
underline : sgr(4, 24),
|
|
50
|
-
inverse : sgr(7, 27),
|
|
51
|
-
hidden : sgr(8, 28),
|
|
52
|
-
strikethrough : sgr(9, 29),
|
|
53
|
-
doubleUnderline : sgr(21, 24),
|
|
54
|
-
frame : sgr(51, 54),
|
|
55
|
-
encircle : sgr(52, 54),
|
|
56
|
-
overline : sgr(53, 55),
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const fg = {
|
|
60
|
-
black : sgr(30, 39),
|
|
61
|
-
red : sgr(31, 39),
|
|
62
|
-
green : sgr(32, 39),
|
|
63
|
-
yellow : sgr(33, 39),
|
|
64
|
-
blue : sgr(34, 39),
|
|
65
|
-
magenta : sgr(35, 39),
|
|
66
|
-
cyan : sgr(36, 39),
|
|
67
|
-
white : sgr(37, 39),
|
|
68
|
-
|
|
69
|
-
brightBlack : sgr(90, 39),
|
|
70
|
-
brightRed : sgr(91, 39),
|
|
71
|
-
brightGreen : sgr(92, 39),
|
|
72
|
-
brightYellow : sgr(93, 39),
|
|
73
|
-
brightBlue : sgr(94, 39),
|
|
74
|
-
brightMagenta : sgr(95, 39),
|
|
75
|
-
brightCyan : sgr(96, 39),
|
|
76
|
-
brightWhite : sgr(97, 39),
|
|
77
|
-
|
|
78
|
-
default : "\x1b[39m",
|
|
79
|
-
|
|
80
|
-
/** @type {(r: number, g: number, b: number) => (text: string) => string} */
|
|
81
|
-
rgb : (r, g, b) => rgb(r, g, b, 38, 39),
|
|
82
|
-
/** @type {(r: number, g: number, b: number) => (text: string) => string} */
|
|
83
|
-
x256 : (r, g, b) => x256(r, g, b, 38, 39),
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const bg = {
|
|
87
|
-
black : sgr(40, 49),
|
|
88
|
-
red : sgr(41, 49),
|
|
89
|
-
green : sgr(42, 49),
|
|
90
|
-
yellow : sgr(43, 49),
|
|
91
|
-
blue : sgr(44, 49),
|
|
92
|
-
magenta : sgr(45, 49),
|
|
93
|
-
cyan : sgr(46, 49),
|
|
94
|
-
white : sgr(47, 49),
|
|
95
|
-
|
|
96
|
-
brightBlack : sgr(100, 49),
|
|
97
|
-
brightRed : sgr(101, 49),
|
|
98
|
-
brightGreen : sgr(102, 49),
|
|
99
|
-
brightYellow : sgr(103, 49),
|
|
100
|
-
brightBlue : sgr(104, 49),
|
|
101
|
-
brightMagenta : sgr(105, 49),
|
|
102
|
-
brightCyan : sgr(106, 49),
|
|
103
|
-
brightWhite : sgr(107, 49),
|
|
104
|
-
|
|
105
|
-
default : "\x1b[49m",
|
|
106
|
-
|
|
107
|
-
/** @type {(r: number, g: number, b: number) => (text: string) => string} */
|
|
108
|
-
rgb : (r, g, b) => rgb(r, g, b, 48, 49),
|
|
109
|
-
/** @type {(r: number, g: number, b: number) => (text: string) => string} */
|
|
110
|
-
x256 : (r, g, b) => x256(r, g, b, 48, 49),
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
module.exports = {reset, style, fg, bg};
|