@peteanderson/ansi 0.2.2 → 0.2.4
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 +30 -65
- package/ansi.js +28 -0
- package/package.json +20 -13
- package/dist/ansi.d.ts +0 -12
- package/dist/ansi.js +0 -21
- package/dist/caret.d.ts +0 -25
- package/dist/caret.js +0 -40
- package/dist/erase.d.ts +0 -14
- package/dist/erase.js +0 -15
- package/dist/index.d.ts +0 -106
- package/dist/index.js +0 -2
- package/dist/scroll.d.ts +0 -2
- package/dist/scroll.js +0 -8
- package/dist/sgr/color.d.ts +0 -62
- package/dist/sgr/color.js +0 -111
- package/dist/sgr/index.d.ts +0 -59
- package/dist/sgr/index.js +0 -6
- package/dist/sgr/reset.d.ts +0 -1
- package/dist/sgr/reset.js +0 -3
- package/dist/sgr/sgr.d.ts +0 -14
- package/dist/sgr/sgr.js +0 -47
- package/dist/sgr/style.d.ts +0 -13
- package/dist/sgr/style.js +0 -16
- package/dist/sgr/utils.d.ts +0 -2
- package/dist/sgr/utils.js +0 -16
- package/dist/simplify/atom.d.ts +0 -3
- package/dist/simplify/atom.js +0 -28
- package/dist/simplify/index.d.ts +0 -2
- package/dist/simplify/index.js +0 -2
- package/dist/simplify/lookup.d.ts +0 -5
- package/dist/simplify/lookup.js +0 -77
- package/dist/simplify/simplify.d.ts +0 -1
- package/dist/simplify/simplify.js +0 -24
- package/dist/simplify/state.d.ts +0 -10
- package/dist/simplify/state.js +0 -57
- package/dist/simplify/utils.d.ts +0 -2
- package/dist/simplify/utils.js +0 -31
- package/dist/strip.d.ts +0 -11
- package/dist/strip.js +0 -58
- package/src/ansi.js +0 -26
- package/src/caret.js +0 -49
- package/src/erase.js +0 -17
- package/src/index.js +0 -1
- package/src/scroll.js +0 -10
- package/src/sgr/color.js +0 -130
- package/src/sgr/index.js +0 -5
- package/src/sgr/reset.js +0 -3
- package/src/sgr/sgr.js +0 -66
- package/src/sgr/style.js +0 -19
- package/src/sgr/utils.js +0 -20
- package/src/simplify/atom.js +0 -34
- package/src/simplify/index.js +0 -1
- package/src/simplify/lookup.js +0 -86
- package/src/simplify/simplify.js +0 -33
- package/src/simplify/state.js +0 -73
- package/src/simplify/types.d.ts +0 -28
- package/src/simplify/utils.js +0 -41
- package/src/strip.js +0 -69
package/dist/sgr/index.d.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
declare const _exports: {
|
|
2
|
-
fg: {
|
|
3
|
-
black: import("./sgr").SGR;
|
|
4
|
-
red: import("./sgr").SGR;
|
|
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;
|
|
22
|
-
};
|
|
23
|
-
bg: {
|
|
24
|
-
black: import("./sgr").SGR;
|
|
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";
|
|
58
|
-
};
|
|
59
|
-
export = _exports;
|
package/dist/sgr/index.js
DELETED
package/dist/sgr/reset.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const reset: "\u001B[0m";
|
package/dist/sgr/reset.js
DELETED
package/dist/sgr/sgr.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export type Code = number | number[];
|
|
2
|
-
export type SGR = {
|
|
3
|
-
(text: string): string;
|
|
4
|
-
open: string;
|
|
5
|
-
close: string;
|
|
6
|
-
[$codes]: {
|
|
7
|
-
open: Code;
|
|
8
|
-
close: Code;
|
|
9
|
-
};
|
|
10
|
-
combine: (...styles: SGR[]) => SGR;
|
|
11
|
-
};
|
|
12
|
-
export function sgr(open: Code, close: Code, reset?: boolean): SGR;
|
|
13
|
-
declare const $codes: unique symbol;
|
|
14
|
-
export {};
|
package/dist/sgr/sgr.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const $codes = Symbol();
|
|
3
|
-
/**
|
|
4
|
-
@typedef {number | number[]} Code
|
|
5
|
-
@typedef {{
|
|
6
|
-
(text: string): string;
|
|
7
|
-
open : string;
|
|
8
|
-
close : string;
|
|
9
|
-
[$codes] : {open: Code, close: Code};
|
|
10
|
-
combine : (...styles: SGR[]) => SGR;
|
|
11
|
-
}} SGR
|
|
12
|
-
*/
|
|
13
|
-
/** @type {(code: Code, codes: Code[]) => Code} */
|
|
14
|
-
function combine(code, codes) {
|
|
15
|
-
if (!codes.length)
|
|
16
|
-
return code;
|
|
17
|
-
const rtn = Array.isArray(code) ? [...code] : [code];
|
|
18
|
-
for (const c of codes) {
|
|
19
|
-
if (Array.isArray(c))
|
|
20
|
-
rtn.push(...c);
|
|
21
|
-
else
|
|
22
|
-
rtn.push(c);
|
|
23
|
-
}
|
|
24
|
-
return rtn;
|
|
25
|
-
}
|
|
26
|
-
/** @type {(code: Code) => string | number} */
|
|
27
|
-
const codeSequence = code => Array.isArray(code) ? code.join(';') : code;
|
|
28
|
-
/** @type {(open: Code, close: Code, reset?: boolean) => SGR} */
|
|
29
|
-
function sgr(open, close, reset = false) {
|
|
30
|
-
const openCode = codeSequence(open);
|
|
31
|
-
const closeCode = codeSequence(close);
|
|
32
|
-
const openSequence = `\x1b[${openCode}m`;
|
|
33
|
-
const closeSequence = `\x1b[${closeCode}m`;
|
|
34
|
-
const reopenCode = reset ? `${closeCode};${openCode}` : openCode;
|
|
35
|
-
const rxClose = new RegExp(`(?<start>\\x1b\\[(?:\\d+;)*)${closeCode}(?<end>(?:;\\d+)*m)`, "g");
|
|
36
|
-
const replace = `$<start>${reopenCode}$<end>`;
|
|
37
|
-
/** @type {(text: string) => string} */
|
|
38
|
-
const func = s => openSequence + s.replace(rxClose, replace) + closeSequence;
|
|
39
|
-
return Object.assign(func, {
|
|
40
|
-
[$codes]: { open, close },
|
|
41
|
-
open: openSequence,
|
|
42
|
-
close: closeSequence,
|
|
43
|
-
/** @type {(...styles: SGR[]) => SGR} */
|
|
44
|
-
combine: (...styles) => sgr(combine(open, styles.map(s => s[$codes].open)), combine(close, styles.map(s => s[$codes].close))),
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
module.exports = { sgr };
|
package/dist/sgr/style.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export namespace style {
|
|
2
|
-
let bold: import("./sgr").SGR;
|
|
3
|
-
let dim: import("./sgr").SGR;
|
|
4
|
-
let italic: import("./sgr").SGR;
|
|
5
|
-
let underline: import("./sgr").SGR;
|
|
6
|
-
let inverse: import("./sgr").SGR;
|
|
7
|
-
let hidden: import("./sgr").SGR;
|
|
8
|
-
let strikethrough: import("./sgr").SGR;
|
|
9
|
-
let doubleUnderline: import("./sgr").SGR;
|
|
10
|
-
let frame: import("./sgr").SGR;
|
|
11
|
-
let encircle: import("./sgr").SGR;
|
|
12
|
-
let overline: import("./sgr").SGR;
|
|
13
|
-
}
|
package/dist/sgr/style.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const { sgr } = require("./sgr");
|
|
3
|
-
const style = {
|
|
4
|
-
bold: sgr(1, 22, true),
|
|
5
|
-
dim: sgr(2, 22, true),
|
|
6
|
-
italic: sgr(3, 23),
|
|
7
|
-
underline: sgr(4, 24),
|
|
8
|
-
inverse: sgr(7, 27),
|
|
9
|
-
hidden: sgr(8, 28),
|
|
10
|
-
strikethrough: sgr(9, 29),
|
|
11
|
-
doubleUnderline: sgr(21, 24),
|
|
12
|
-
frame: sgr(51, 54),
|
|
13
|
-
encircle: sgr(52, 54),
|
|
14
|
-
overline: sgr(53, 55),
|
|
15
|
-
};
|
|
16
|
-
module.exports = { style };
|
package/dist/sgr/utils.d.ts
DELETED
package/dist/sgr/utils.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/** @typedef {number | number[]} Code */
|
|
3
|
-
/** @type {(code: Code, codes: Code[]) => Code} */
|
|
4
|
-
function combine(code, codes) {
|
|
5
|
-
if (!codes.length)
|
|
6
|
-
return code;
|
|
7
|
-
const rtn = Array.isArray(code) ? [...code] : [code];
|
|
8
|
-
for (const c of codes) {
|
|
9
|
-
if (Array.isArray(c))
|
|
10
|
-
rtn.push(...c);
|
|
11
|
-
else
|
|
12
|
-
rtn.push(c);
|
|
13
|
-
}
|
|
14
|
-
return rtn;
|
|
15
|
-
}
|
|
16
|
-
module.exports = { combine };
|
package/dist/simplify/atom.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export type BuildAtom = import("./types").BuildAtom;
|
|
2
|
-
export function buildExtendedColorAtom(attribute: import("./types").Attribute, codes: number[], index: number, state: import("./types").AttributeMap): import("./types").Atom;
|
|
3
|
-
export function buildIntensityAtom(attribute: import("./types").Attribute, codes: number[], index: number, state: import("./types").AttributeMap): import("./types").Atom;
|
package/dist/simplify/atom.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/** @typedef {import("./types").BuildAtom} BuildAtom */
|
|
3
|
-
/** @type {BuildAtom} */
|
|
4
|
-
function buildExtendedColorAtom(attribute, codes, index) {
|
|
5
|
-
switch (codes[index + 1]) {
|
|
6
|
-
case 2:
|
|
7
|
-
if (index + 5 >= codes.length)
|
|
8
|
-
return { attribute, code: codes.slice(index), skip: codes.length - index - 1 };
|
|
9
|
-
return { attribute, code: codes.slice(index, index + 5), skip: 4 };
|
|
10
|
-
case 5:
|
|
11
|
-
if (index + 3 >= codes.length)
|
|
12
|
-
return { attribute, code: codes.slice(index), skip: codes.length - index - 1 };
|
|
13
|
-
return { attribute, code: codes.slice(index, index + 3), skip: 2 };
|
|
14
|
-
default:
|
|
15
|
-
return { attribute, code: codes.slice(index, index + 2), skip: 1 };
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
/** @type {BuildAtom} */
|
|
19
|
-
function buildIntensityAtom(attribute, codes, index, state) {
|
|
20
|
-
const code = codes[index];
|
|
21
|
-
if (code === 22)
|
|
22
|
-
return { attribute, code: [code] };
|
|
23
|
-
const current = state.get("intensity");
|
|
24
|
-
if (!current || current.length == 1 && current[0] === code || current[0] === 22)
|
|
25
|
-
return { attribute, code: [code] };
|
|
26
|
-
return { attribute, code: [1, 2] };
|
|
27
|
-
}
|
|
28
|
-
module.exports = { buildExtendedColorAtom, buildIntensityAtom };
|
package/dist/simplify/index.d.ts
DELETED
package/dist/simplify/index.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export type Atom = import("./types").Atom;
|
|
2
|
-
export type Attribute = import("./types").Attribute;
|
|
3
|
-
export type AttributeMap = import("./types").AttributeMap;
|
|
4
|
-
export type BuildAtom = import("./types").BuildAtom;
|
|
5
|
-
export function lookUpAtom(codes: number[], index: number, state: AttributeMap): Atom;
|
package/dist/simplify/lookup.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const { buildExtendedColorAtom, buildIntensityAtom } = require("./atom");
|
|
3
|
-
/** @typedef {import("./types").Atom} Atom */
|
|
4
|
-
/** @typedef {import("./types").Attribute} Attribute */
|
|
5
|
-
/** @typedef {import("./types").AttributeMap} AttributeMap */
|
|
6
|
-
/** @typedef {import("./types").BuildAtom} BuildAtom */
|
|
7
|
-
/** @type {Record<number, [attribute: Attribute, buildAtom?: BuildAtom]>} */
|
|
8
|
-
const codeMap = {
|
|
9
|
-
0: ["reset"],
|
|
10
|
-
1: ["intensity", buildIntensityAtom],
|
|
11
|
-
2: ["intensity", buildIntensityAtom],
|
|
12
|
-
3: ["italic"],
|
|
13
|
-
4: ["underline"],
|
|
14
|
-
7: ["inverse"],
|
|
15
|
-
8: ["hidden"],
|
|
16
|
-
9: ["strikethrough"],
|
|
17
|
-
21: ["underline"],
|
|
18
|
-
22: ["intensity", buildIntensityAtom],
|
|
19
|
-
23: ["italic"],
|
|
20
|
-
24: ["underline"],
|
|
21
|
-
27: ["inverse"],
|
|
22
|
-
28: ["hidden"],
|
|
23
|
-
29: ["strikethrough"],
|
|
24
|
-
30: ["fg"],
|
|
25
|
-
31: ["fg"],
|
|
26
|
-
32: ["fg"],
|
|
27
|
-
33: ["fg"],
|
|
28
|
-
34: ["fg"],
|
|
29
|
-
35: ["fg"],
|
|
30
|
-
36: ["fg"],
|
|
31
|
-
37: ["fg"],
|
|
32
|
-
38: ["fg", buildExtendedColorAtom],
|
|
33
|
-
39: ["fg"],
|
|
34
|
-
40: ["bg"],
|
|
35
|
-
41: ["bg"],
|
|
36
|
-
42: ["bg"],
|
|
37
|
-
43: ["bg"],
|
|
38
|
-
44: ["bg"],
|
|
39
|
-
45: ["bg"],
|
|
40
|
-
46: ["bg"],
|
|
41
|
-
47: ["bg"],
|
|
42
|
-
48: ["bg", buildExtendedColorAtom],
|
|
43
|
-
49: ["bg"],
|
|
44
|
-
51: ["frame"],
|
|
45
|
-
52: ["frame"],
|
|
46
|
-
53: ["overline"],
|
|
47
|
-
54: ["frame"],
|
|
48
|
-
55: ["overline"],
|
|
49
|
-
90: ["fg"],
|
|
50
|
-
91: ["fg"],
|
|
51
|
-
92: ["fg"],
|
|
52
|
-
93: ["fg"],
|
|
53
|
-
94: ["fg"],
|
|
54
|
-
95: ["fg"],
|
|
55
|
-
96: ["fg"],
|
|
56
|
-
97: ["fg"],
|
|
57
|
-
100: ["bg"],
|
|
58
|
-
101: ["bg"],
|
|
59
|
-
102: ["bg"],
|
|
60
|
-
103: ["bg"],
|
|
61
|
-
104: ["bg"],
|
|
62
|
-
105: ["bg"],
|
|
63
|
-
106: ["bg"],
|
|
64
|
-
107: ["bg"],
|
|
65
|
-
};
|
|
66
|
-
/** @type {(codes: number[], index: number, state: AttributeMap) => Atom} */
|
|
67
|
-
function lookUpAtom(codes, index, state) {
|
|
68
|
-
const code = codes[index];
|
|
69
|
-
const entry = codeMap[code];
|
|
70
|
-
if (!entry)
|
|
71
|
-
return { attribute: code, code: [code] };
|
|
72
|
-
const [attribute, buildAtom] = entry;
|
|
73
|
-
if (buildAtom)
|
|
74
|
-
return buildAtom(attribute, codes, index, state);
|
|
75
|
-
return { attribute, code: [code] };
|
|
76
|
-
}
|
|
77
|
-
module.exports = { lookUpAtom };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export function simplify(text: string): string;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const { State } = require("./state");
|
|
3
|
-
const rxSGR = /\x1b\[([0-9;]+)m/;
|
|
4
|
-
/** @type {(text: string) => string} */
|
|
5
|
-
function simplify(text) {
|
|
6
|
-
const parts = text.split(rxSGR);
|
|
7
|
-
const state = new State();
|
|
8
|
-
let result = parts[0];
|
|
9
|
-
for (let i = 1; i < parts.length;) {
|
|
10
|
-
let codes = parts[i++].split(";").map(Number);
|
|
11
|
-
let chunk = parts[i++];
|
|
12
|
-
while (!chunk && i < parts.length) {
|
|
13
|
-
// Merge consecutive SGR sequences.
|
|
14
|
-
codes.push(...parts[i++].split(";").map(Number));
|
|
15
|
-
chunk = parts[i++];
|
|
16
|
-
}
|
|
17
|
-
codes = state.update(codes);
|
|
18
|
-
if (codes.length)
|
|
19
|
-
result += `\x1b[${codes.join(";")}m`;
|
|
20
|
-
result += chunk;
|
|
21
|
-
}
|
|
22
|
-
return result;
|
|
23
|
-
}
|
|
24
|
-
module.exports = { simplify };
|
package/dist/simplify/state.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export type Attribute = import("./types").Attribute;
|
|
2
|
-
export type AttributeMap = import("./types").AttributeMap;
|
|
3
|
-
/** @type {AttributeMap} */
|
|
4
|
-
export class State extends Map<any, any> {
|
|
5
|
-
constructor();
|
|
6
|
-
constructor(entries?: readonly (readonly [any, any])[] | null | undefined);
|
|
7
|
-
constructor();
|
|
8
|
-
constructor(iterable?: Iterable<readonly [any, any]> | null | undefined);
|
|
9
|
-
update(codes: number[]): number[];
|
|
10
|
-
}
|
package/dist/simplify/state.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const { lookUpAtom } = require("./lookup");
|
|
3
|
-
const { arraysEqual, transitionIntensity } = require("./utils");
|
|
4
|
-
/** @typedef {import("./types").Attribute} Attribute */
|
|
5
|
-
/** @typedef {import("./types").AttributeMap} AttributeMap */
|
|
6
|
-
/** @type {Map<Attribute, number[]>} */
|
|
7
|
-
const defaultCodes = new Map([
|
|
8
|
-
["intensity", [22]],
|
|
9
|
-
["italic", [23]],
|
|
10
|
-
["underline", [24]],
|
|
11
|
-
["inverse", [27]],
|
|
12
|
-
["hidden", [28]],
|
|
13
|
-
["strikethrough", [29]],
|
|
14
|
-
["fg", [39]],
|
|
15
|
-
["bg", [49]],
|
|
16
|
-
["frame", [54]],
|
|
17
|
-
["overline", [55]],
|
|
18
|
-
]);
|
|
19
|
-
/** @type {AttributeMap} */
|
|
20
|
-
class State extends Map {
|
|
21
|
-
/** @type {(codes: number[]) => number[]} */
|
|
22
|
-
update(codes) {
|
|
23
|
-
/** @type {AttributeMap} */
|
|
24
|
-
let snapshot = new Map(this);
|
|
25
|
-
/** @type {Set<Attribute>} */
|
|
26
|
-
const attributes = new Set();
|
|
27
|
-
for (let i = 0; i < codes.length; i++) {
|
|
28
|
-
const { attribute, code, skip } = lookUpAtom(codes, i, this);
|
|
29
|
-
if (attribute === "reset") {
|
|
30
|
-
attributes.clear();
|
|
31
|
-
this.clear();
|
|
32
|
-
attributes.add("reset");
|
|
33
|
-
for (const [attr, defaultCode] of defaultCodes)
|
|
34
|
-
this.set(attr, defaultCode);
|
|
35
|
-
snapshot = new Map(this);
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
attributes.add(attribute);
|
|
39
|
-
this.set(attribute, code);
|
|
40
|
-
if (skip)
|
|
41
|
-
i += skip;
|
|
42
|
-
}
|
|
43
|
-
return Array.from(attributes).flatMap(attribute => {
|
|
44
|
-
if (attribute === "reset")
|
|
45
|
-
return [0];
|
|
46
|
-
const code = this.get(attribute);
|
|
47
|
-
if (arraysEqual(code, snapshot.get(attribute)))
|
|
48
|
-
return [];
|
|
49
|
-
if (attribute === "intensity") {
|
|
50
|
-
const previous = snapshot.get(attribute);
|
|
51
|
-
return transitionIntensity(previous, code);
|
|
52
|
-
}
|
|
53
|
-
return code;
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
module.exports = { State };
|
package/dist/simplify/utils.d.ts
DELETED
package/dist/simplify/utils.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/** @type {<T>(a: T[] | undefined, b: T[] | undefined) => boolean} */
|
|
3
|
-
function arraysEqual(a, b) {
|
|
4
|
-
if (a === b)
|
|
5
|
-
return true;
|
|
6
|
-
if (!a || !b || a.length !== b.length)
|
|
7
|
-
return false;
|
|
8
|
-
for (let i = 0; i < a.length; i++) {
|
|
9
|
-
if (a[i] !== b[i])
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
14
|
-
/** @type {(previous: number[] | undefined, current: number[]) => number[]} */
|
|
15
|
-
function transitionIntensity(previous, current) {
|
|
16
|
-
if (!previous || previous[0] === 22 || current[0] === 22)
|
|
17
|
-
return current;
|
|
18
|
-
const oldBold = previous[0] === 1;
|
|
19
|
-
const newBold = current[0] === 1;
|
|
20
|
-
const oldDim = previous[previous.length - 1] === 2;
|
|
21
|
-
const newDim = current[current.length - 1] === 2;
|
|
22
|
-
const result = [];
|
|
23
|
-
if (oldBold && !newBold || oldDim && !newDim)
|
|
24
|
-
result.push(22);
|
|
25
|
-
if (newBold && (!oldBold || result[0] === 22))
|
|
26
|
-
result.push(1);
|
|
27
|
-
if (newDim && (!oldDim || result[0] === 22))
|
|
28
|
-
result.push(2);
|
|
29
|
-
return result;
|
|
30
|
-
}
|
|
31
|
-
module.exports = { arraysEqual, transitionIntensity };
|
package/dist/strip.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Remove all ANSI escape codes from the given text.
|
|
3
|
-
* @type {(text: string) => string}
|
|
4
|
-
*/
|
|
5
|
-
export const strip: (text: string) => string;
|
|
6
|
-
/**
|
|
7
|
-
* Remove all ANSI escape codes except SGR codes (m), which are used for color and styling.
|
|
8
|
-
* @type {(text: string) => string}
|
|
9
|
-
*/
|
|
10
|
-
export const sanitize: (text: string) => string;
|
|
11
|
-
export function slice(text: string, start: number, end: number): string;
|
package/dist/strip.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const { reset } = require("./sgr");
|
|
3
|
-
const rxCSI = /\x1b\[[0-?]*[ -/]*[@-~]/g;
|
|
4
|
-
const rxUnsafe = /\x1b\[[0-?]*[ -/]*[@-ln-~]/g; // Everything except SGR codes (m).
|
|
5
|
-
/**
|
|
6
|
-
* Remove all ANSI escape codes from the given text.
|
|
7
|
-
* @type {(text: string) => string}
|
|
8
|
-
*/
|
|
9
|
-
const strip = text => text.replace(rxCSI, '');
|
|
10
|
-
/**
|
|
11
|
-
* Remove all ANSI escape codes except SGR codes (m), which are used for color and styling.
|
|
12
|
-
* @type {(text: string) => string}
|
|
13
|
-
*/
|
|
14
|
-
const sanitize = text => text.replace(rxUnsafe, '');
|
|
15
|
-
/** @type {(text: string, start: number, end: number) => string} */
|
|
16
|
-
function slice(text, start, end) {
|
|
17
|
-
if (start < 0 || end < 0) {
|
|
18
|
-
const visibleLength = strip(text).length;
|
|
19
|
-
if (start < 0)
|
|
20
|
-
start = Math.max(0, visibleLength + start);
|
|
21
|
-
if (end < 0)
|
|
22
|
-
end = Math.max(0, visibleLength + end);
|
|
23
|
-
}
|
|
24
|
-
if (start > end)
|
|
25
|
-
return "";
|
|
26
|
-
let visibleIndex = 0;
|
|
27
|
-
let startIndex = 0;
|
|
28
|
-
while (startIndex < text.length && visibleIndex < start) {
|
|
29
|
-
if (text[startIndex] === "\x1b") {
|
|
30
|
-
rxCSI.lastIndex = startIndex;
|
|
31
|
-
const match = rxCSI.exec(text);
|
|
32
|
-
if (match?.index === startIndex) {
|
|
33
|
-
startIndex += match[0].length;
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
startIndex++;
|
|
38
|
-
visibleIndex++;
|
|
39
|
-
}
|
|
40
|
-
let endIndex = startIndex;
|
|
41
|
-
let hasAnsi = false;
|
|
42
|
-
while (endIndex < text.length && visibleIndex < end) {
|
|
43
|
-
if (text[endIndex] === "\x1b") {
|
|
44
|
-
rxCSI.lastIndex = endIndex;
|
|
45
|
-
const match = rxCSI.exec(text);
|
|
46
|
-
if (match?.index === endIndex) {
|
|
47
|
-
endIndex += match[0].length;
|
|
48
|
-
hasAnsi = true;
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
endIndex++;
|
|
53
|
-
visibleIndex++;
|
|
54
|
-
}
|
|
55
|
-
return text.slice(startIndex, endIndex) + (hasAnsi ? reset : "");
|
|
56
|
-
}
|
|
57
|
-
;
|
|
58
|
-
module.exports = { strip, sanitize, slice };
|
package/src/ansi.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const caret = require("./caret");
|
|
4
|
-
const erase = require("./erase");
|
|
5
|
-
const scroll = require("./scroll");
|
|
6
|
-
const {bg, fg, reset, style} = require("./sgr");
|
|
7
|
-
const {simplify} = require("./simplify");
|
|
8
|
-
const {sanitize, slice, strip} = require("./strip");
|
|
9
|
-
|
|
10
|
-
const ansi = {
|
|
11
|
-
caret,
|
|
12
|
-
erase,
|
|
13
|
-
scroll,
|
|
14
|
-
|
|
15
|
-
reset,
|
|
16
|
-
style,
|
|
17
|
-
fg,
|
|
18
|
-
bg,
|
|
19
|
-
|
|
20
|
-
strip,
|
|
21
|
-
sanitize,
|
|
22
|
-
slice,
|
|
23
|
-
simplify,
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
module.exports = ansi;
|
package/src/caret.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/** @type {(code: string) => (count?: number) => string} */
|
|
4
|
-
const move = code =>
|
|
5
|
-
count => `\x1b[${count === undefined ? "" : count ? count : "?"}${code}`;
|
|
6
|
-
|
|
7
|
-
const caret = {
|
|
8
|
-
up : move("A"),
|
|
9
|
-
down : move("B"),
|
|
10
|
-
forward : move("C"),
|
|
11
|
-
backward : move("D"),
|
|
12
|
-
nextLine : move("E"),
|
|
13
|
-
prevLine : move("F"),
|
|
14
|
-
|
|
15
|
-
/** @type {(x: number) => string} */
|
|
16
|
-
x: x => `\x1b[${x}G`,
|
|
17
|
-
|
|
18
|
-
// These are the old VT100 codes, but they're widely supported by old and new terminals. The
|
|
19
|
-
// newer VT220 codes are standardized by ECMA and ISO, and are also widely supported, but might
|
|
20
|
-
// not work in some older terminals. The VT220 codes are:
|
|
21
|
-
//
|
|
22
|
-
// ```
|
|
23
|
-
// save : "\x1b[s",
|
|
24
|
-
// restore : "\x1b[u",
|
|
25
|
-
// ```
|
|
26
|
-
save : "\x1b7",
|
|
27
|
-
restore : "\x1b8",
|
|
28
|
-
|
|
29
|
-
hide : "\x1b[?25l",
|
|
30
|
-
show : "\x1b[?25h",
|
|
31
|
-
|
|
32
|
-
position: {
|
|
33
|
-
get: "\x1b[6n",
|
|
34
|
-
/** @type {(x: number, y: number) => string} */
|
|
35
|
-
set: (x, y) => `\x1b[${y};${x}H`,
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
shape: {
|
|
39
|
-
steadyBlock : "\x1b[2 q",
|
|
40
|
-
steadyBar : "\x1b[6 q",
|
|
41
|
-
steadyUnderline : "\x1b[4 q",
|
|
42
|
-
blinkingBlock : "\x1b[1 q",
|
|
43
|
-
blinkingBar : "\x1b[5 q",
|
|
44
|
-
blinkingUnderline : "\x1b[3 q",
|
|
45
|
-
default : "\x1b[0 q",
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
module.exports = caret;
|
package/src/erase.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const erase = {
|
|
4
|
-
line: {
|
|
5
|
-
toStart: "\x1b[1K",
|
|
6
|
-
toEnd : "\x1b[0K",
|
|
7
|
-
full : "\x1b[2K",
|
|
8
|
-
},
|
|
9
|
-
screen: {
|
|
10
|
-
toStart : "\x1b[1J",
|
|
11
|
-
toEnd : "\x1b[0J",
|
|
12
|
-
full : "\x1b[2J",
|
|
13
|
-
scrollback : "\x1b[3J",
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
module.exports = erase;
|
package/src/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require("./ansi");
|
package/src/scroll.js
DELETED