@peteanderson/ansi 0.2.3 → 0.3.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.
- package/README.md +70 -19
- package/dist/ansi.d.ts +41 -8
- package/dist/ansi.js +44 -18
- package/dist/caret.d.ts +28 -25
- package/dist/caret.js +31 -1
- package/dist/erase.d.ts +13 -14
- package/dist/erase.js +16 -1
- package/dist/features/build.d.ts +11 -0
- package/dist/features/build.js +50 -0
- package/dist/features/detect.d.ts +4 -0
- package/dist/features/detect.js +33 -0
- package/dist/features/features.d.ts +5 -0
- package/dist/features/features.js +39 -0
- package/dist/features/index.d.ts +2 -0
- package/dist/features/index.js +2 -0
- package/dist/index.d.ts +12 -62
- package/dist/scroll.d.ts +6 -2
- package/dist/scroll.js +7 -1
- package/dist/sgr/color/color.d.ts +9 -0
- package/dist/sgr/color/color.js +76 -0
- package/dist/sgr/color/index.d.ts +2 -0
- package/dist/sgr/color/index.js +2 -0
- package/dist/sgr/color/utils.d.ts +27 -0
- package/dist/sgr/color/utils.js +67 -0
- package/dist/sgr/index.d.ts +5 -55
- package/dist/sgr/reset.d.ts +1 -1
- package/dist/sgr/reset.js +2 -2
- package/dist/sgr/sgr.d.ts +3 -3
- package/dist/sgr/sgr.js +18 -8
- package/dist/sgr/style.d.ts +13 -13
- package/dist/sgr/style.js +18 -15
- package/package.json +1 -1
- package/src/ansi.js +54 -24
- package/src/caret.js +40 -3
- package/src/erase.js +18 -1
- package/src/features/build.js +60 -0
- package/src/features/detect.js +39 -0
- package/src/features/features.js +53 -0
- package/src/features/index.js +1 -0
- package/src/features/types.d.ts +9 -0
- package/src/scroll.js +9 -1
- package/src/sgr/color/color.js +104 -0
- package/src/sgr/color/index.js +1 -0
- package/src/sgr/color/types.d.ts +28 -0
- package/src/sgr/color/utils.js +81 -0
- package/src/sgr/reset.js +2 -2
- package/src/sgr/sgr.js +25 -14
- package/src/sgr/style.js +19 -15
- package/dist/sgr/color.d.ts +0 -62
- package/dist/sgr/color.js +0 -111
- package/src/sgr/color.js +0 -130
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
declare const _exports: {
|
|
2
|
-
|
|
1
|
+
declare const _exports: ((...args: Args) => Ansi) & {
|
|
2
|
+
fg: Channel;
|
|
3
|
+
bg: Channel;
|
|
4
|
+
} & {
|
|
5
|
+
caret: ReturnType<(enabled?: boolean) => {
|
|
3
6
|
up: (count?: number) => string;
|
|
4
7
|
down: (count?: number) => string;
|
|
5
8
|
forward: (count?: number) => string;
|
|
@@ -24,8 +27,8 @@ declare const _exports: {
|
|
|
24
27
|
blinkingUnderline: string;
|
|
25
28
|
default: string;
|
|
26
29
|
};
|
|
27
|
-
}
|
|
28
|
-
erase: {
|
|
30
|
+
}>;
|
|
31
|
+
erase: ReturnType<(enabled?: boolean) => {
|
|
29
32
|
line: {
|
|
30
33
|
toStart: string;
|
|
31
34
|
toEnd: string;
|
|
@@ -37,71 +40,18 @@ declare const _exports: {
|
|
|
37
40
|
full: string;
|
|
38
41
|
scrollback: string;
|
|
39
42
|
};
|
|
40
|
-
}
|
|
41
|
-
scroll: {
|
|
43
|
+
}>;
|
|
44
|
+
scroll: ReturnType<(enabled?: boolean) => {
|
|
42
45
|
up: (lines?: number) => string;
|
|
43
46
|
down: (lines?: number) => string;
|
|
44
|
-
}
|
|
47
|
+
}>;
|
|
45
48
|
reset: string;
|
|
46
|
-
style:
|
|
47
|
-
bold: import("./sgr/sgr").SGR;
|
|
48
|
-
dim: import("./sgr/sgr").SGR;
|
|
49
|
-
italic: import("./sgr/sgr").SGR;
|
|
50
|
-
underline: import("./sgr/sgr").SGR;
|
|
51
|
-
inverse: import("./sgr/sgr").SGR;
|
|
52
|
-
hidden: import("./sgr/sgr").SGR;
|
|
53
|
-
strikethrough: import("./sgr/sgr").SGR;
|
|
54
|
-
doubleUnderline: import("./sgr/sgr").SGR;
|
|
55
|
-
frame: import("./sgr/sgr").SGR;
|
|
56
|
-
encircle: import("./sgr/sgr").SGR;
|
|
57
|
-
overline: import("./sgr/sgr").SGR;
|
|
58
|
-
};
|
|
59
|
-
fg: {
|
|
60
|
-
black: import("./sgr/sgr").SGR;
|
|
61
|
-
red: import("./sgr/sgr").SGR;
|
|
62
|
-
green: import("./sgr/sgr").SGR;
|
|
63
|
-
yellow: import("./sgr/sgr").SGR;
|
|
64
|
-
blue: import("./sgr/sgr").SGR;
|
|
65
|
-
magenta: import("./sgr/sgr").SGR;
|
|
66
|
-
cyan: import("./sgr/sgr").SGR;
|
|
67
|
-
white: import("./sgr/sgr").SGR;
|
|
68
|
-
brightBlack: import("./sgr/sgr").SGR;
|
|
69
|
-
brightRed: import("./sgr/sgr").SGR;
|
|
70
|
-
brightGreen: import("./sgr/sgr").SGR;
|
|
71
|
-
brightYellow: import("./sgr/sgr").SGR;
|
|
72
|
-
brightBlue: import("./sgr/sgr").SGR;
|
|
73
|
-
brightMagenta: import("./sgr/sgr").SGR;
|
|
74
|
-
brightCyan: import("./sgr/sgr").SGR;
|
|
75
|
-
brightWhite: import("./sgr/sgr").SGR;
|
|
76
|
-
default: string;
|
|
77
|
-
rgb: (r: number, g: number, b: number) => (text: string) => string;
|
|
78
|
-
x256: (arg0: number, arg1?: number, arg2?: number) => (text: string) => string;
|
|
79
|
-
};
|
|
80
|
-
bg: {
|
|
81
|
-
black: import("./sgr/sgr").SGR;
|
|
82
|
-
red: import("./sgr/sgr").SGR;
|
|
83
|
-
green: import("./sgr/sgr").SGR;
|
|
84
|
-
yellow: import("./sgr/sgr").SGR;
|
|
85
|
-
blue: import("./sgr/sgr").SGR;
|
|
86
|
-
magenta: import("./sgr/sgr").SGR;
|
|
87
|
-
cyan: import("./sgr/sgr").SGR;
|
|
88
|
-
white: import("./sgr/sgr").SGR;
|
|
89
|
-
brightBlack: import("./sgr/sgr").SGR;
|
|
90
|
-
brightRed: import("./sgr/sgr").SGR;
|
|
91
|
-
brightGreen: import("./sgr/sgr").SGR;
|
|
92
|
-
brightYellow: import("./sgr/sgr").SGR;
|
|
93
|
-
brightBlue: import("./sgr/sgr").SGR;
|
|
94
|
-
brightMagenta: import("./sgr/sgr").SGR;
|
|
95
|
-
brightCyan: import("./sgr/sgr").SGR;
|
|
96
|
-
brightWhite: import("./sgr/sgr").SGR;
|
|
97
|
-
default: string;
|
|
98
|
-
rgb: (r: number, g: number, b: number) => (text: string) => string;
|
|
99
|
-
x256: (arg0: number, arg1?: number, arg2?: number) => (text: string) => string;
|
|
100
|
-
};
|
|
49
|
+
style: ReturnType<typeof import("./sgr/style").makeStyle>;
|
|
101
50
|
strip: (text: string) => string;
|
|
102
51
|
visibleLength: (text: string) => number;
|
|
103
52
|
sanitize: (text: string) => string;
|
|
104
53
|
slice: typeof import("./slice").slice;
|
|
105
54
|
simplify: typeof import("./simplify/simplify").simplify;
|
|
55
|
+
features: ReturnType<typeof import("./features/features").getFeatures>;
|
|
106
56
|
};
|
|
107
57
|
export = _exports;
|
package/dist/scroll.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
1
|
+
export function makeScroll(enabled?: boolean): {
|
|
2
|
+
/** @type {(lines?: number) => string} */
|
|
3
|
+
up: (lines?: number) => string;
|
|
4
|
+
/** @type {(lines?: number) => string} */
|
|
5
|
+
down: (lines?: number) => string;
|
|
6
|
+
};
|
package/dist/scroll.js
CHANGED
|
@@ -5,4 +5,10 @@ const scroll = {
|
|
|
5
5
|
/** @type {(lines?: number) => string} */
|
|
6
6
|
down: lines => `\x1b[${lines ?? 1}T`,
|
|
7
7
|
};
|
|
8
|
-
|
|
8
|
+
/** @type {typeof scroll} */
|
|
9
|
+
const disabled = {
|
|
10
|
+
up: () => "",
|
|
11
|
+
down: () => "",
|
|
12
|
+
};
|
|
13
|
+
const makeScroll = (enabled = true) => enabled ? scroll : disabled;
|
|
14
|
+
module.exports = { makeScroll };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type Code = import("../sgr").Code;
|
|
2
|
+
export type ColorDepth = import("../../features/types").ColorDepth;
|
|
3
|
+
export type SGR = import("../sgr").SGR;
|
|
4
|
+
export type Channel = import("./types").Channel;
|
|
5
|
+
/** @type {(colorDepth: ColorDepth) => {fg: Channel, bg: Channel}} */
|
|
6
|
+
export const makeColor: (colorDepth: ColorDepth) => {
|
|
7
|
+
fg: Channel;
|
|
8
|
+
bg: Channel;
|
|
9
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const { makeSGR } = require("../sgr");
|
|
3
|
+
const { makeStyle } = require("../style");
|
|
4
|
+
const { clip, rgbToX256, rgbToX16, rgbToX8, x256ToRgb } = require("./utils");
|
|
5
|
+
/** @typedef {import("../sgr").Code} Code */
|
|
6
|
+
/** @typedef {import("../../features/types").ColorDepth} ColorDepth */
|
|
7
|
+
/** @typedef {import("../sgr").SGR} SGR */
|
|
8
|
+
/** @typedef {import("./types").Channel} Channel */
|
|
9
|
+
const fgOpen = 30, fgClose = 39;
|
|
10
|
+
const bgOpen = 40, bgClose = 49;
|
|
11
|
+
/** @type {(colorDepth: ColorDepth, open: number, close: number) => Channel} */
|
|
12
|
+
function makeChannel(colorDepth, open, close) {
|
|
13
|
+
const sgrBase = makeSGR(colorDepth > 1);
|
|
14
|
+
const style = makeStyle(colorDepth > 1);
|
|
15
|
+
/** @type {(code: Code) => SGR} */
|
|
16
|
+
const sgr = code => sgrBase(code, close);
|
|
17
|
+
/** @type {(index: number) => SGR} */
|
|
18
|
+
const bright = colorDepth >= 4 ? index => sgr(open + 60 + index) :
|
|
19
|
+
colorDepth === 3 ?
|
|
20
|
+
open === fgOpen ?
|
|
21
|
+
index => style.bold.combine(sgr(open + index)) :
|
|
22
|
+
index => sgr(open + index) :
|
|
23
|
+
() => sgr(0);
|
|
24
|
+
/** @type {(code: number) => SGR} */
|
|
25
|
+
const x16ToX8 = open === fgOpen ?
|
|
26
|
+
code => code >= 60 ? style.bold.combine(sgr(open + code - 60)) : sgr(open + code) :
|
|
27
|
+
code => code >= 60 ? sgr(open + code - 60) : sgr(open + code);
|
|
28
|
+
return {
|
|
29
|
+
black: sgr(open + 0),
|
|
30
|
+
red: sgr(open + 1),
|
|
31
|
+
green: sgr(open + 2),
|
|
32
|
+
yellow: sgr(open + 3),
|
|
33
|
+
blue: sgr(open + 4),
|
|
34
|
+
magenta: sgr(open + 5),
|
|
35
|
+
cyan: sgr(open + 6),
|
|
36
|
+
white: sgr(open + 7),
|
|
37
|
+
brightBlack: bright(0),
|
|
38
|
+
brightRed: bright(1),
|
|
39
|
+
brightGreen: bright(2),
|
|
40
|
+
brightYellow: bright(3),
|
|
41
|
+
brightBlue: bright(4),
|
|
42
|
+
brightMagenta: bright(5),
|
|
43
|
+
brightCyan: bright(6),
|
|
44
|
+
brightWhite: bright(7),
|
|
45
|
+
rgb: colorDepth >= 24 ? (r, g, b) => sgr([open + 8, 2, ...clip(r, g, b)]) :
|
|
46
|
+
colorDepth >= 8 ? (r, g, b) => sgr([open + 8, 5, rgbToX256(...clip(r, g, b))]) :
|
|
47
|
+
colorDepth >= 4 ? (r, g, b) => sgr(open + rgbToX16(...clip(r, g, b))) :
|
|
48
|
+
colorDepth === 3 ?
|
|
49
|
+
open === fgOpen ?
|
|
50
|
+
(r, g, b) => x16ToX8(rgbToX16(...clip(r, g, b))) :
|
|
51
|
+
(r, g, b) => sgr(open + rgbToX8(...clip(r, g, b))) :
|
|
52
|
+
() => sgr(0),
|
|
53
|
+
/** @type {(...args: [number] | [number, number, number]) => SGR} */
|
|
54
|
+
x256: colorDepth >= 8 ?
|
|
55
|
+
(...args) => sgr([open + 8, 5, args.length === 3 ? rgbToX256(...clip(...args)) : clip(args[0])]) :
|
|
56
|
+
colorDepth >= 4 ?
|
|
57
|
+
(...args) => sgr(open +
|
|
58
|
+
rgbToX16(...(args.length === 3 ? clip(...args) : x256ToRgb(clip(args[0]))))) :
|
|
59
|
+
colorDepth === 3 ?
|
|
60
|
+
open === fgOpen ?
|
|
61
|
+
(...args) => x16ToX8(args.length === 3 ?
|
|
62
|
+
rgbToX16(...clip(...args)) :
|
|
63
|
+
rgbToX16(...x256ToRgb(clip(args[0])))) :
|
|
64
|
+
(...args) => sgr(open + rgbToX8(...args.length === 3 ? clip(...args) : x256ToRgb(clip(args[0])))) :
|
|
65
|
+
() => sgr(0),
|
|
66
|
+
default: colorDepth > 1 ? `\x1b[${close}m` : "",
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/** @type {Partial<Record<ColorDepth, {fg: Channel, bg: Channel}>>} */
|
|
70
|
+
const cache = {};
|
|
71
|
+
/** @type {(colorDepth: ColorDepth) => {fg: Channel, bg: Channel}} */
|
|
72
|
+
const makeColor = (colorDepth = 4) => cache[colorDepth] ?? (cache[colorDepth] = {
|
|
73
|
+
fg: makeChannel(colorDepth, fgOpen, fgClose),
|
|
74
|
+
bg: makeChannel(colorDepth, bgOpen, bgClose),
|
|
75
|
+
});
|
|
76
|
+
module.exports = { makeColor };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type Code = import("../sgr").Code;
|
|
2
|
+
export function rgbToX256(r: number, g: number, b: number): number;
|
|
3
|
+
export function x256ToRgb(code: number): [number, number, number];
|
|
4
|
+
export function rgbToX16(r: number, g: number, b: number): number;
|
|
5
|
+
export function rgbToX8(r: number, g: number, b: number): number;
|
|
6
|
+
/**
|
|
7
|
+
* @overload
|
|
8
|
+
* @param {number} x
|
|
9
|
+
* @returns {number}
|
|
10
|
+
* @overload
|
|
11
|
+
* @param {number} r
|
|
12
|
+
* @param {number} g
|
|
13
|
+
* @param {number} b
|
|
14
|
+
* @returns {[number, number, number]}
|
|
15
|
+
*/
|
|
16
|
+
export function clip(x: number): number;
|
|
17
|
+
/**
|
|
18
|
+
* @overload
|
|
19
|
+
* @param {number} x
|
|
20
|
+
* @returns {number}
|
|
21
|
+
* @overload
|
|
22
|
+
* @param {number} r
|
|
23
|
+
* @param {number} g
|
|
24
|
+
* @param {number} b
|
|
25
|
+
* @returns {[number, number, number]}
|
|
26
|
+
*/
|
|
27
|
+
export function clip(r: number, g: number, b: number): [number, number, number];
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** @typedef {import("../sgr").Code} Code */
|
|
3
|
+
/** @type {(r: number, g: number, b: number) => number} */
|
|
4
|
+
function rgbToX256(r, g, b) {
|
|
5
|
+
if (r === g && g === b) {
|
|
6
|
+
// grayscale
|
|
7
|
+
return 232 + Math.floor(r * 24 / 256);
|
|
8
|
+
}
|
|
9
|
+
// 6x6x6 color cube
|
|
10
|
+
return (16 +
|
|
11
|
+
Math.floor(r * 6 / 256) * 36 +
|
|
12
|
+
Math.floor(g * 6 / 256) * 6 +
|
|
13
|
+
Math.floor(b * 6 / 256));
|
|
14
|
+
}
|
|
15
|
+
/** @type {(code: number) => [number, number, number]} */
|
|
16
|
+
function x256ToRgb(code) {
|
|
17
|
+
if (code >= 232) {
|
|
18
|
+
// grayscale
|
|
19
|
+
const gray = Math.round((code - 232) * 255 / 24);
|
|
20
|
+
return [gray, gray, gray];
|
|
21
|
+
}
|
|
22
|
+
code -= 16;
|
|
23
|
+
const r = Math.floor(code / 36) * 51;
|
|
24
|
+
const g = Math.floor((code % 36) / 6) * 51;
|
|
25
|
+
const b = (code % 6) * 51;
|
|
26
|
+
return [r, g, b];
|
|
27
|
+
}
|
|
28
|
+
/** @type {(r: number, g: number, b: number) => number} */
|
|
29
|
+
function rgbToX16(r, g, b) {
|
|
30
|
+
// First calculate it as a 4x4x4 cube.
|
|
31
|
+
r = Math.min(2, Math.floor(r / 85));
|
|
32
|
+
g = Math.min(2, Math.floor(g / 85));
|
|
33
|
+
b = Math.min(2, Math.floor(b / 85));
|
|
34
|
+
// Which channels are "on" determines the hue (ANSI color index 0–7).
|
|
35
|
+
const index = (r ? 1 : 0) | (g ? 2 : 0) | (b ? 4 : 0);
|
|
36
|
+
// The bright bit is derived from the max channel level across all three.
|
|
37
|
+
const twos = (r === 2 ? 1 : 0) + (g === 2 ? 1 : 0) + (b === 2 ? 1 : 0);
|
|
38
|
+
const ones = (r === 1 ? 1 : 0) + (g === 1 ? 1 : 0) + (b === 1 ? 1 : 0);
|
|
39
|
+
const bright = twos > 0 && twos >= ones;
|
|
40
|
+
// Return value uses the SGR offset scheme: 0–7 for normal, 60–67 for bright.
|
|
41
|
+
return index + (bright ? 60 : 0);
|
|
42
|
+
}
|
|
43
|
+
/** @type {(r: number, g: number, b: number) => number} */
|
|
44
|
+
function rgbToX8(r, g, b) {
|
|
45
|
+
r = r >= 128 ? 1 : 0;
|
|
46
|
+
g = g >= 128 ? 1 : 0;
|
|
47
|
+
b = b >= 128 ? 1 : 0;
|
|
48
|
+
return (r ? 1 : 0) | (g ? 2 : 0) | (b ? 4 : 0);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* @overload
|
|
52
|
+
* @param {number} x
|
|
53
|
+
* @returns {number}
|
|
54
|
+
* @overload
|
|
55
|
+
* @param {number} r
|
|
56
|
+
* @param {number} g
|
|
57
|
+
* @param {number} b
|
|
58
|
+
* @returns {[number, number, number]}
|
|
59
|
+
*/ /** @param {[number] | [number, number, number]} args */
|
|
60
|
+
const clip = (...args) => args.length === 1 ?
|
|
61
|
+
Math.max(0, Math.min(255, Math.floor(args[0]))) :
|
|
62
|
+
[
|
|
63
|
+
Math.max(0, Math.min(255, Math.floor(args[0]))),
|
|
64
|
+
Math.max(0, Math.min(255, Math.floor(args[1]))),
|
|
65
|
+
Math.max(0, Math.min(255, Math.floor(args[2]))),
|
|
66
|
+
];
|
|
67
|
+
module.exports = { rgbToX256, x256ToRgb, rgbToX16, rgbToX8, clip };
|
package/dist/sgr/index.d.ts
CHANGED
|
@@ -1,59 +1,9 @@
|
|
|
1
1
|
declare const _exports: {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
green: import("./sgr").SGR;
|
|
6
|
-
yellow: import("./sgr").SGR;
|
|
7
|
-
blue: import("./sgr").SGR;
|
|
8
|
-
magenta: import("./sgr").SGR;
|
|
9
|
-
cyan: import("./sgr").SGR;
|
|
10
|
-
white: import("./sgr").SGR;
|
|
11
|
-
brightBlack: import("./sgr").SGR;
|
|
12
|
-
brightRed: import("./sgr").SGR;
|
|
13
|
-
brightGreen: import("./sgr").SGR;
|
|
14
|
-
brightYellow: import("./sgr").SGR;
|
|
15
|
-
brightBlue: import("./sgr").SGR;
|
|
16
|
-
brightMagenta: import("./sgr").SGR;
|
|
17
|
-
brightCyan: import("./sgr").SGR;
|
|
18
|
-
brightWhite: import("./sgr").SGR;
|
|
19
|
-
default: string;
|
|
20
|
-
rgb: (r: number, g: number, b: number) => (text: string) => string;
|
|
21
|
-
x256: (arg0: number, arg1?: number, arg2?: number) => (text: string) => string;
|
|
2
|
+
makeColor: (colorDepth: ColorDepth) => {
|
|
3
|
+
fg: Channel;
|
|
4
|
+
bg: Channel;
|
|
22
5
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
red: import("./sgr").SGR;
|
|
26
|
-
green: import("./sgr").SGR;
|
|
27
|
-
yellow: import("./sgr").SGR;
|
|
28
|
-
blue: import("./sgr").SGR;
|
|
29
|
-
magenta: import("./sgr").SGR;
|
|
30
|
-
cyan: import("./sgr").SGR;
|
|
31
|
-
white: import("./sgr").SGR;
|
|
32
|
-
brightBlack: import("./sgr").SGR;
|
|
33
|
-
brightRed: import("./sgr").SGR;
|
|
34
|
-
brightGreen: import("./sgr").SGR;
|
|
35
|
-
brightYellow: import("./sgr").SGR;
|
|
36
|
-
brightBlue: import("./sgr").SGR;
|
|
37
|
-
brightMagenta: import("./sgr").SGR;
|
|
38
|
-
brightCyan: import("./sgr").SGR;
|
|
39
|
-
brightWhite: import("./sgr").SGR;
|
|
40
|
-
default: string;
|
|
41
|
-
rgb: (r: number, g: number, b: number) => (text: string) => string;
|
|
42
|
-
x256: (arg0: number, arg1?: number, arg2?: number) => (text: string) => string;
|
|
43
|
-
};
|
|
44
|
-
style: {
|
|
45
|
-
bold: import("./sgr").SGR;
|
|
46
|
-
dim: import("./sgr").SGR;
|
|
47
|
-
italic: import("./sgr").SGR;
|
|
48
|
-
underline: import("./sgr").SGR;
|
|
49
|
-
inverse: import("./sgr").SGR;
|
|
50
|
-
hidden: import("./sgr").SGR;
|
|
51
|
-
strikethrough: import("./sgr").SGR;
|
|
52
|
-
doubleUnderline: import("./sgr").SGR;
|
|
53
|
-
frame: import("./sgr").SGR;
|
|
54
|
-
encircle: import("./sgr").SGR;
|
|
55
|
-
overline: import("./sgr").SGR;
|
|
56
|
-
};
|
|
57
|
-
reset: "\u001B[0m";
|
|
6
|
+
makeStyle: typeof import("./style").makeStyle;
|
|
7
|
+
makeReset: (enabled?: boolean) => "" | "\u001B[0m";
|
|
58
8
|
};
|
|
59
9
|
export = _exports;
|
package/dist/sgr/reset.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export function makeReset(enabled?: boolean): "" | "\u001B[0m";
|
package/dist/sgr/reset.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const
|
|
3
|
-
module.exports = {
|
|
2
|
+
const makeReset = (enabled = true) => enabled ? "\x1b[0m" : "";
|
|
3
|
+
module.exports = { makeReset };
|
package/dist/sgr/sgr.d.ts
CHANGED
|
@@ -3,12 +3,12 @@ export type SGR = {
|
|
|
3
3
|
(text: string): string;
|
|
4
4
|
open: string;
|
|
5
5
|
close: string;
|
|
6
|
-
|
|
6
|
+
codes: {
|
|
7
7
|
open: Code;
|
|
8
8
|
close: Code;
|
|
9
9
|
};
|
|
10
10
|
combine: (...styles: SGR[]) => SGR;
|
|
11
11
|
};
|
|
12
|
-
export function
|
|
13
|
-
declare
|
|
12
|
+
export function makeSGR(enabled?: boolean): typeof sgr;
|
|
13
|
+
declare function sgr(open: Code, close: Code, reset?: boolean): SGR;
|
|
14
14
|
export {};
|
package/dist/sgr/sgr.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const $codes = Symbol();
|
|
3
2
|
/**
|
|
4
3
|
@typedef {number | number[]} Code
|
|
5
4
|
@typedef {{
|
|
6
5
|
(text: string): string;
|
|
7
|
-
open
|
|
8
|
-
close
|
|
9
|
-
|
|
10
|
-
combine
|
|
6
|
+
open : string;
|
|
7
|
+
close : string;
|
|
8
|
+
codes : {open: Code, close: Code};
|
|
9
|
+
combine : (...styles: SGR[]) => SGR;
|
|
11
10
|
}} SGR
|
|
12
11
|
*/
|
|
13
12
|
/** @type {(code: Code, codes: Code[]) => Code} */
|
|
@@ -37,11 +36,22 @@ function sgr(open, close, reset = false) {
|
|
|
37
36
|
/** @type {(text: string) => string} */
|
|
38
37
|
const func = s => openSequence + s.replace(rxClose, replace) + closeSequence;
|
|
39
38
|
return Object.assign(func, {
|
|
40
|
-
|
|
39
|
+
codes: { open, close },
|
|
41
40
|
open: openSequence,
|
|
42
41
|
close: closeSequence,
|
|
43
42
|
/** @type {(...styles: SGR[]) => SGR} */
|
|
44
|
-
combine: (...styles) => sgr(combine(open, styles.map(s => s
|
|
43
|
+
combine: (...styles) => sgr(combine(open, styles.map(s => s.codes.open)), combine(close, styles.map(s => s.codes.close))),
|
|
45
44
|
});
|
|
46
45
|
}
|
|
47
|
-
|
|
46
|
+
;
|
|
47
|
+
/** @type {SGR} */
|
|
48
|
+
const disabledSGR = Object.assign(/** @type {(text: string) => string} */ /** @type {(text: string) => string} */ s => s, {
|
|
49
|
+
codes: { open: 0, close: 0 },
|
|
50
|
+
open: "",
|
|
51
|
+
close: "",
|
|
52
|
+
combine: () => disabledSGR,
|
|
53
|
+
});
|
|
54
|
+
/** @type {typeof sgr} */
|
|
55
|
+
const disabled = () => disabledSGR;
|
|
56
|
+
const makeSGR = (enabled = true) => enabled ? sgr : disabled;
|
|
57
|
+
module.exports = { makeSGR };
|
package/dist/sgr/style.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
1
|
+
export function makeStyle(enabled?: boolean): {
|
|
2
|
+
bold: import("./sgr").SGR;
|
|
3
|
+
dim: import("./sgr").SGR;
|
|
4
|
+
italic: import("./sgr").SGR;
|
|
5
|
+
underline: import("./sgr").SGR;
|
|
6
|
+
inverse: import("./sgr").SGR;
|
|
7
|
+
hidden: import("./sgr").SGR;
|
|
8
|
+
strikethrough: import("./sgr").SGR;
|
|
9
|
+
doubleUnderline: import("./sgr").SGR;
|
|
10
|
+
frame: import("./sgr").SGR;
|
|
11
|
+
encircle: import("./sgr").SGR;
|
|
12
|
+
overline: import("./sgr").SGR;
|
|
13
|
+
};
|
package/dist/sgr/style.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
2
|
+
const { makeSGR } = require("./sgr");
|
|
3
|
+
function makeStyle(enabled = true) {
|
|
4
|
+
const sgr = makeSGR(enabled);
|
|
5
|
+
return {
|
|
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 = { makeStyle };
|
package/package.json
CHANGED
package/src/ansi.js
CHANGED
|
@@ -1,28 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const {
|
|
7
|
-
const {
|
|
8
|
-
const {
|
|
9
|
-
const {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
3
|
+
const {makeCaret} = require("./caret");
|
|
4
|
+
const {makeErase} = require("./erase");
|
|
5
|
+
const {getFeatures} = require("./features");
|
|
6
|
+
const {makeScroll} = require("./scroll");
|
|
7
|
+
const {makeColor, makeReset, makeStyle} = require("./sgr");
|
|
8
|
+
const {simplify} = require("./simplify");
|
|
9
|
+
const {slice} = require("./slice");
|
|
10
|
+
const {sanitize, strip, visibleLength} = require("./strip");
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
@typedef {import("./features/features").Args} Args
|
|
14
|
+
|
|
15
|
+
@typedef {ReturnType<typeof makeColor> & {
|
|
16
|
+
caret : ReturnType<typeof makeCaret>;
|
|
17
|
+
erase : ReturnType<typeof makeErase>;
|
|
18
|
+
scroll : ReturnType<typeof makeScroll>;
|
|
19
|
+
|
|
20
|
+
reset : string;
|
|
21
|
+
style : ReturnType<typeof makeStyle>;
|
|
22
|
+
|
|
23
|
+
strip : typeof strip;
|
|
24
|
+
visibleLength : typeof visibleLength;
|
|
25
|
+
sanitize : typeof sanitize;
|
|
26
|
+
slice : typeof slice;
|
|
27
|
+
simplify : typeof simplify;
|
|
28
|
+
|
|
29
|
+
features : ReturnType<typeof getFeatures>;
|
|
30
|
+
}} Ansi
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/** @type {(...args: Args) => Ansi}*/
|
|
34
|
+
function makeAnsi(...args) {
|
|
35
|
+
const features = getFeatures(...args);
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
caret : makeCaret(features.caret),
|
|
39
|
+
erase : makeErase(features.erase),
|
|
40
|
+
scroll : makeScroll(features.scroll),
|
|
41
|
+
|
|
42
|
+
reset : makeReset(features.colorDepth > 1),
|
|
43
|
+
style : makeStyle(features.style),
|
|
44
|
+
...makeColor(features.colorDepth),
|
|
45
|
+
|
|
46
|
+
strip,
|
|
47
|
+
visibleLength,
|
|
48
|
+
sanitize,
|
|
49
|
+
slice,
|
|
50
|
+
simplify,
|
|
51
|
+
|
|
52
|
+
features,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const ansi = Object.assign(makeAnsi, makeAnsi());
|
|
27
57
|
|
|
28
58
|
module.exports = ansi;
|
package/src/caret.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
/** @type {(code: string) => (count?: number) => string} */
|
|
4
|
-
const move = code =>
|
|
5
|
-
|
|
4
|
+
const move = code => count => `\x1b[${count === undefined ? "" : count ? count : "?"}${code}`;
|
|
5
|
+
|
|
6
|
+
/** @type {(count?: number) => string} */
|
|
7
|
+
const noop = () => "";
|
|
6
8
|
|
|
7
9
|
const caret = {
|
|
8
10
|
up : move("A"),
|
|
@@ -46,4 +48,39 @@ const caret = {
|
|
|
46
48
|
},
|
|
47
49
|
};
|
|
48
50
|
|
|
49
|
-
|
|
51
|
+
/** @type {typeof caret} */
|
|
52
|
+
const disabled = {
|
|
53
|
+
up : noop,
|
|
54
|
+
down : noop,
|
|
55
|
+
forward : noop,
|
|
56
|
+
backward : noop,
|
|
57
|
+
nextLine : noop,
|
|
58
|
+
prevLine : noop,
|
|
59
|
+
|
|
60
|
+
x: noop,
|
|
61
|
+
|
|
62
|
+
save : "",
|
|
63
|
+
restore : "",
|
|
64
|
+
|
|
65
|
+
hide : "",
|
|
66
|
+
show : "",
|
|
67
|
+
|
|
68
|
+
position: {
|
|
69
|
+
get: "",
|
|
70
|
+
set: noop,
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
shape: {
|
|
74
|
+
steadyBlock : "",
|
|
75
|
+
steadyBar : "",
|
|
76
|
+
steadyUnderline : "",
|
|
77
|
+
blinkingBlock : "",
|
|
78
|
+
blinkingBar : "",
|
|
79
|
+
blinkingUnderline : "",
|
|
80
|
+
default : "",
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const makeCaret = (enabled = true) => enabled ? caret : disabled;
|
|
85
|
+
|
|
86
|
+
module.exports = {makeCaret};
|