@peteanderson/ansi 0.3.3 → 1.0.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/dist/ansi.d.ts +28 -37
- package/dist/ansi.d.ts.map +1 -0
- package/dist/ansi.js +29 -52
- package/dist/ansi.js.map +1 -0
- package/dist/caret.d.ts +5 -3
- package/dist/caret.d.ts.map +1 -0
- package/dist/caret.js +6 -8
- package/dist/caret.js.map +1 -0
- package/dist/erase.d.ts +5 -1
- package/dist/erase.d.ts.map +1 -0
- package/dist/erase.js +4 -2
- package/dist/erase.js.map +1 -0
- package/dist/features/build.d.ts +7 -11
- package/dist/features/build.d.ts.map +1 -0
- package/dist/features/build.js +12 -25
- package/dist/features/build.js.map +1 -0
- package/dist/features/detect.d.ts +4 -4
- package/dist/features/detect.d.ts.map +1 -0
- package/dist/features/detect.js +5 -6
- package/dist/features/detect.js.map +1 -0
- package/dist/features/features.d.ts +4 -4
- package/dist/features/features.d.ts.map +1 -0
- package/dist/features/features.js +17 -28
- package/dist/features/features.js.map +1 -0
- package/dist/features/index.d.ts +2 -2
- package/dist/features/index.d.ts.map +1 -0
- package/dist/features/index.js +17 -1
- package/dist/features/index.js.map +1 -0
- package/dist/features/types.d.ts +10 -0
- package/dist/features/types.d.ts.map +1 -0
- package/dist/features/types.js +3 -0
- package/dist/features/types.js.map +1 -0
- package/dist/index.d.ts +3 -81
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -1
- package/dist/index.js.map +1 -0
- package/dist/pad.d.ts +3 -4
- package/dist/pad.d.ts.map +1 -0
- package/dist/pad.js +8 -6
- package/dist/pad.js.map +1 -0
- package/dist/patterns.d.ts +4 -3
- package/dist/patterns.d.ts.map +1 -0
- package/dist/patterns.js +6 -4
- package/dist/patterns.js.map +1 -0
- package/dist/scroll.d.ts +5 -3
- package/dist/scroll.d.ts.map +1 -0
- package/dist/scroll.js +6 -6
- package/dist/scroll.js.map +1 -0
- package/dist/sgr/color/color.d.ts +5 -9
- package/dist/sgr/color/color.d.ts.map +1 -0
- package/dist/sgr/color/color.js +22 -29
- package/dist/sgr/color/color.js.map +1 -0
- package/dist/sgr/color/index.d.ts +2 -2
- package/dist/sgr/color/index.d.ts.map +1 -0
- package/dist/sgr/color/index.js +17 -1
- package/dist/sgr/color/index.js.map +1 -0
- package/dist/sgr/color/types.d.ts +30 -0
- package/dist/sgr/color/types.d.ts.map +1 -0
- package/dist/sgr/color/types.js +3 -0
- package/dist/sgr/color/types.js.map +1 -0
- package/dist/sgr/color/utils.d.ts +7 -27
- package/dist/sgr/color/utils.d.ts.map +1 -0
- package/dist/sgr/color/utils.js +16 -23
- package/dist/sgr/color/utils.js.map +1 -0
- package/dist/sgr/index.d.ts +4 -9
- package/dist/sgr/index.d.ts.map +1 -0
- package/dist/sgr/index.js +18 -4
- package/dist/sgr/index.js.map +1 -0
- package/dist/sgr/reset.d.ts +2 -1
- package/dist/sgr/reset.d.ts.map +1 -0
- package/dist/sgr/reset.js +4 -1
- package/dist/sgr/reset.js.map +1 -0
- package/dist/sgr/sgr.d.ts +4 -3
- package/dist/sgr/sgr.d.ts.map +1 -0
- package/dist/sgr/sgr.js +14 -27
- package/dist/sgr/sgr.js.map +1 -0
- package/dist/sgr/style.d.ts +3 -1
- package/dist/sgr/style.d.ts.map +1 -0
- package/dist/sgr/style.js +5 -3
- package/dist/sgr/style.js.map +1 -0
- package/dist/sgr/utils.d.ts +3 -2
- package/dist/sgr/utils.d.ts.map +1 -0
- package/dist/sgr/utils.js +3 -3
- package/dist/sgr/utils.js.map +1 -0
- package/dist/simplify/atom.d.ts +4 -3
- package/dist/simplify/atom.d.ts.map +1 -0
- package/dist/simplify/atom.js +9 -8
- package/dist/simplify/atom.js.map +1 -0
- package/dist/simplify/index.d.ts +2 -2
- package/dist/simplify/index.d.ts.map +1 -0
- package/dist/simplify/index.js +17 -1
- package/dist/simplify/index.js.map +1 -0
- package/dist/simplify/lookup.d.ts +3 -5
- package/dist/simplify/lookup.d.ts.map +1 -0
- package/dist/simplify/lookup.js +9 -13
- package/dist/simplify/lookup.js.map +1 -0
- package/dist/simplify/simplify.d.ts +2 -1
- package/dist/simplify/simplify.d.ts.map +1 -0
- package/dist/simplify/simplify.js +7 -7
- package/dist/simplify/simplify.js.map +1 -0
- package/dist/simplify/state.d.ts +3 -8
- package/dist/simplify/state.d.ts.map +1 -0
- package/dist/simplify/state.js +9 -13
- package/dist/simplify/state.js.map +1 -0
- package/dist/simplify/types.d.ts +9 -0
- package/dist/simplify/types.d.ts.map +1 -0
- package/dist/simplify/types.js +3 -0
- package/dist/simplify/types.js.map +1 -0
- package/dist/simplify/utils.d.ts +3 -2
- package/dist/simplify/utils.d.ts.map +1 -0
- package/dist/simplify/utils.js +4 -3
- package/dist/simplify/utils.js.map +1 -0
- package/dist/slice.d.ts +21 -1
- package/dist/slice.d.ts.map +1 -0
- package/dist/slice.js +10 -21
- package/dist/slice.js.map +1 -0
- package/dist/strip.d.ts +7 -15
- package/dist/strip.d.ts.map +1 -0
- package/dist/strip.js +13 -17
- package/dist/strip.js.map +1 -0
- package/dist/terminal.d.ts +5 -1
- package/dist/terminal.d.ts.map +1 -0
- package/dist/terminal.js +4 -2
- package/dist/terminal.js.map +1 -0
- package/package.json +8 -6
- package/src/ansi.ts +71 -0
- package/src/{caret.js → caret.ts} +9 -15
- package/src/{erase.js → erase.ts} +7 -10
- package/src/features/build.ts +53 -0
- package/src/features/detect.ts +36 -0
- package/src/features/{features.js → features.ts} +9 -18
- package/src/features/index.ts +1 -0
- package/src/index.ts +2 -0
- package/src/{pad.js → pad.ts} +4 -10
- package/src/{patterns.js → patterns.ts} +3 -5
- package/src/scroll.ts +13 -0
- package/src/sgr/color/{color.js → color.ts} +26 -35
- package/src/sgr/color/index.ts +1 -0
- package/src/sgr/color/{types.d.ts → types.ts} +6 -2
- package/src/sgr/color/{utils.js → utils.ts} +17 -30
- package/src/sgr/index.ts +3 -0
- package/src/sgr/reset.ts +1 -0
- package/src/sgr/sgr.ts +65 -0
- package/src/sgr/{style.js → style.ts} +3 -5
- package/src/sgr/{utils.js → utils.ts} +3 -6
- package/src/simplify/{atom.js → atom.ts} +5 -11
- package/src/simplify/index.ts +1 -0
- package/src/simplify/{lookup.js → lookup.ts} +5 -14
- package/src/simplify/{simplify.js → simplify.ts} +4 -10
- package/src/simplify/state.ts +63 -0
- package/src/simplify/{types.d.ts → types.ts} +5 -5
- package/src/simplify/{utils.js → utils.ts} +4 -10
- package/src/{slice.js → slice.ts} +12 -25
- package/src/strip.ts +10 -0
- package/src/{terminal.js → terminal.ts} +4 -7
- package/src/ansi.js +0 -70
- package/src/features/build.js +0 -68
- package/src/features/detect.js +0 -40
- package/src/features/index.js +0 -1
- package/src/index.js +0 -1
- package/src/scroll.js +0 -18
- package/src/sgr/color/index.js +0 -1
- package/src/sgr/index.js +0 -5
- package/src/sgr/reset.js +0 -3
- package/src/sgr/sgr.js +0 -77
- package/src/simplify/index.js +0 -1
- package/src/simplify/state.js +0 -73
- package/src/strip.js +0 -23
- /package/src/features/{types.d.ts → types.ts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slice.js","sourceRoot":"","sources":["../src/slice.ts"],"names":[],"mappings":"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"}
|
package/dist/strip.d.ts
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* @type {(text: string) => number}
|
|
9
|
-
*/
|
|
10
|
-
export const visibleLength: (text: string) => number;
|
|
11
|
-
/**
|
|
12
|
-
* Remove all ANSI escape codes except SGR codes (m), which are used for color and styling.
|
|
13
|
-
* @type {(text: string) => string}
|
|
14
|
-
*/
|
|
15
|
-
export const sanitize: (text: string) => string;
|
|
1
|
+
/** Remove all ANSI escape codes from the given text. */
|
|
2
|
+
export declare const strip: (text: string) => string;
|
|
3
|
+
/** Calculate the visible length of a string with ANSI escape codes stripped. */
|
|
4
|
+
export declare const visibleLength: (text: string) => number;
|
|
5
|
+
/** Remove all ANSI escape codes except SGR codes (m), which are used for color and styling. */
|
|
6
|
+
export declare const sanitize: (text: string) => string;
|
|
7
|
+
//# sourceMappingURL=strip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strip.d.ts","sourceRoot":"","sources":["../src/strip.ts"],"names":[],"mappings":"AAEA,wDAAwD;AACxD,eAAO,MAAM,KAAK,GAAY,MAAM,MAAM,KAAG,MAA6C,CAAC;AAE3F,gFAAgF;AAChF,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,KAAG,MAA4B,CAAC;AAE1E,+FAA+F;AAC/F,eAAO,MAAM,QAAQ,GAAS,MAAM,MAAM,KAAG,MAAgD,CAAC"}
|
package/dist/strip.js
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*/
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* @type {(text: string) => string}
|
|
16
|
-
*/
|
|
17
|
-
const sanitize = text => text.replace(new RegExp(rxUnsafe), "");
|
|
18
|
-
module.exports = { strip, visibleLength, sanitize };
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sanitize = exports.visibleLength = exports.strip = void 0;
|
|
4
|
+
const patterns_1 = require("./patterns");
|
|
5
|
+
/** Remove all ANSI escape codes from the given text. */
|
|
6
|
+
const strip = (text) => text.replace(new RegExp(patterns_1.rxCSI), "");
|
|
7
|
+
exports.strip = strip;
|
|
8
|
+
/** Calculate the visible length of a string with ANSI escape codes stripped. */
|
|
9
|
+
const visibleLength = (text) => (0, exports.strip)(text).length;
|
|
10
|
+
exports.visibleLength = visibleLength;
|
|
11
|
+
/** Remove all ANSI escape codes except SGR codes (m), which are used for color and styling. */
|
|
12
|
+
const sanitize = (text) => text.replace(new RegExp(patterns_1.rxUnsafe), "");
|
|
13
|
+
exports.sanitize = sanitize;
|
|
14
|
+
//# sourceMappingURL=strip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strip.js","sourceRoot":"","sources":["../src/strip.ts"],"names":[],"mappings":";;;AAAA,yCAA2C;AAE3C,wDAAwD;AACjD,MAAM,KAAK,GAAW,CAAC,IAAY,EAAU,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,gBAAK,CAAC,EAAE,EAAE,CAAC,CAAC;AAA9E,QAAA,KAAK,SAAyE;AAE3F,gFAAgF;AACzE,MAAM,aAAa,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,IAAA,aAAK,EAAC,IAAI,CAAC,CAAC,MAAM,CAAC;AAA7D,QAAA,aAAa,iBAAgD;AAE1E,+FAA+F;AACxF,MAAM,QAAQ,GAAQ,CAAC,IAAY,EAAU,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,mBAAQ,CAAC,EAAE,EAAE,CAAC,CAAC;AAAjF,QAAA,QAAQ,YAAyE"}
|
package/dist/terminal.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
declare const terminal: {
|
|
2
2
|
focusReporting: {
|
|
3
3
|
enable: string;
|
|
4
4
|
disable: string;
|
|
@@ -20,3 +20,7 @@ export function makeTerminal(enabled?: boolean): {
|
|
|
20
20
|
end: string;
|
|
21
21
|
};
|
|
22
22
|
};
|
|
23
|
+
export type Terminal = typeof terminal;
|
|
24
|
+
export declare const makeTerminal: (enabled?: boolean) => Terminal;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=terminal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminal.d.ts","sourceRoot":"","sources":["../src/terminal.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;CAwBb,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC;AA4BvC,eAAO,MAAM,YAAY,GAAI,iBAAc,KAAG,QAAyC,CAAC"}
|
package/dist/terminal.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeTerminal = void 0;
|
|
2
4
|
const terminal = {
|
|
3
5
|
focusReporting: {
|
|
4
6
|
enable: "\x1b[?1004h",
|
|
@@ -21,7 +23,6 @@ const terminal = {
|
|
|
21
23
|
end: "\x1b[201~",
|
|
22
24
|
},
|
|
23
25
|
};
|
|
24
|
-
/** @type {typeof terminal} */
|
|
25
26
|
const disabled = {
|
|
26
27
|
focusReporting: {
|
|
27
28
|
enable: "",
|
|
@@ -45,4 +46,5 @@ const disabled = {
|
|
|
45
46
|
},
|
|
46
47
|
};
|
|
47
48
|
const makeTerminal = (enabled = true) => enabled ? terminal : disabled;
|
|
48
|
-
|
|
49
|
+
exports.makeTerminal = makeTerminal;
|
|
50
|
+
//# sourceMappingURL=terminal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminal.js","sourceRoot":"","sources":["../src/terminal.ts"],"names":[],"mappings":";;;AAAA,MAAM,QAAQ,GAAG;IAChB,cAAc,EAAE;QACf,MAAM,EAAI,aAAa;QACvB,OAAO,EAAG,aAAa;QACvB,KAAK,EAAK,QAAQ;QAClB,IAAI,EAAM,QAAQ;KAClB;IAED,eAAe,EAAE;QAChB,MAAM,EAAI,aAAa;QACvB,OAAO,EAAG,aAAa;QAEvB,MAAM,EAAE;YACP,MAAM,EAAI,WAAW;YACrB,OAAO,EAAG,WAAW;SACrB;KACD;IAED,cAAc,EAAE;QACf,MAAM,EAAI,aAAa;QACvB,OAAO,EAAG,aAAa;QACvB,KAAK,EAAK,WAAW;QACrB,GAAG,EAAO,WAAW;KACrB;CACD,CAAC;AAIF,MAAM,QAAQ,GAAa;IAC1B,cAAc,EAAE;QACf,MAAM,EAAI,EAAE;QACZ,OAAO,EAAG,EAAE;QACZ,KAAK,EAAK,EAAE;QACZ,IAAI,EAAM,EAAE;KACZ;IAED,eAAe,EAAE;QAChB,MAAM,EAAI,EAAE;QACZ,OAAO,EAAG,EAAE;QAEZ,MAAM,EAAE;YACP,MAAM,EAAI,EAAE;YACZ,OAAO,EAAG,EAAE;SACZ;KACD;IAED,cAAc,EAAE;QACf,MAAM,EAAI,EAAE;QACZ,OAAO,EAAG,EAAE;QACZ,KAAK,EAAK,EAAE;QACZ,GAAG,EAAO,EAAE;KACZ;CACD,CAAC;AAEK,MAAM,YAAY,GAAG,CAAC,OAAO,GAAG,IAAI,EAAY,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC;AAA3E,QAAA,YAAY,gBAA+D"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name" : "@peteanderson/ansi",
|
|
3
|
-
"version" : "0.
|
|
3
|
+
"version" : "1.0.1",
|
|
4
4
|
"description" : "ANSI escape sequence generation with automatic feature detection",
|
|
5
5
|
"author" : {
|
|
6
6
|
"name" : "Pete Anderson",
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
"keywords" : ["ansi", "nodejs", "color", "terminal", "cli"],
|
|
14
14
|
"engines" : {"node": ">=18"},
|
|
15
15
|
"files" : ["dist", "src"],
|
|
16
|
-
"main" : "dist/
|
|
17
|
-
"types" : "dist/
|
|
16
|
+
"main" : "dist/index.js",
|
|
17
|
+
"types" : "dist/index.d.ts",
|
|
18
18
|
"exports" : {
|
|
19
19
|
".": {
|
|
20
|
-
"types" : "./dist/
|
|
21
|
-
"require" : "./dist/
|
|
20
|
+
"types" : "./dist/index.d.ts",
|
|
21
|
+
"require" : "./dist/index.js"
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"license" : "MIT",
|
|
@@ -26,10 +26,12 @@
|
|
|
26
26
|
"prebuild" : "node -e \"require('node:fs').rmSync('dist', {force: true, recursive: true})\"",
|
|
27
27
|
"build" : "tsc -p tsconfig.build.json",
|
|
28
28
|
"prepack" : "npm run build",
|
|
29
|
-
"tag" : "git tag -a v$npm_package_version -m v$npm_package_version"
|
|
29
|
+
"tag" : "git tag -a v$npm_package_version -m v$npm_package_version",
|
|
30
|
+
"tag-all" : "tsx --tsconfig scripts/tsconfig.json scripts/tag-all.ts"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies" : {
|
|
32
33
|
"@types/node" : "^26.0.0",
|
|
34
|
+
"tsx" : "^4.22.4",
|
|
33
35
|
"typescript" : "^6.0.3"
|
|
34
36
|
}
|
|
35
37
|
}
|
package/src/ansi.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import {makeCaret} from "./caret";
|
|
2
|
+
import {makeErase} from "./erase";
|
|
3
|
+
import {getFeatures} from "./features";
|
|
4
|
+
import {padEnd, padStart} from "./pad";
|
|
5
|
+
import {makeScroll} from "./scroll";
|
|
6
|
+
import {makeColor, makeReset, makeStyle} from "./sgr";
|
|
7
|
+
import {simplify} from "./simplify";
|
|
8
|
+
import {slice} from "./slice";
|
|
9
|
+
import {sanitize, strip, visibleLength} from "./strip";
|
|
10
|
+
import {makeTerminal} from "./terminal";
|
|
11
|
+
|
|
12
|
+
import type {Args} from "./features/features";
|
|
13
|
+
import type {Caret} from "./caret";
|
|
14
|
+
import type {Erase} from "./erase";
|
|
15
|
+
import type {Features} from "./features/types";
|
|
16
|
+
import type {Scroll} from "./scroll";
|
|
17
|
+
import type {Color, Style} from "./sgr";
|
|
18
|
+
import type {Terminal} from "./terminal";
|
|
19
|
+
|
|
20
|
+
export type Ansi = Color & {
|
|
21
|
+
caret : Caret;
|
|
22
|
+
erase : Erase;
|
|
23
|
+
scroll : Scroll;
|
|
24
|
+
|
|
25
|
+
reset : string;
|
|
26
|
+
style : Style;
|
|
27
|
+
|
|
28
|
+
terminal : Terminal;
|
|
29
|
+
|
|
30
|
+
padEnd : typeof padEnd;
|
|
31
|
+
padStart : typeof padStart;
|
|
32
|
+
|
|
33
|
+
strip : typeof strip;
|
|
34
|
+
visibleLength : typeof visibleLength;
|
|
35
|
+
sanitize : typeof sanitize;
|
|
36
|
+
slice : typeof slice;
|
|
37
|
+
simplify : typeof simplify;
|
|
38
|
+
|
|
39
|
+
features : Features;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export function makeAnsi(...args: Args): Ansi {
|
|
43
|
+
const features = getFeatures(...args);
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
caret : makeCaret(features.caret),
|
|
47
|
+
erase : makeErase(features.erase),
|
|
48
|
+
scroll : makeScroll(features.scroll),
|
|
49
|
+
|
|
50
|
+
reset : makeReset(features.colorDepth > 1),
|
|
51
|
+
style : makeStyle(features.style),
|
|
52
|
+
...makeColor(features.colorDepth),
|
|
53
|
+
|
|
54
|
+
terminal: makeTerminal(features.terminal),
|
|
55
|
+
|
|
56
|
+
padEnd,
|
|
57
|
+
padStart,
|
|
58
|
+
|
|
59
|
+
strip,
|
|
60
|
+
visibleLength,
|
|
61
|
+
sanitize,
|
|
62
|
+
slice,
|
|
63
|
+
simplify,
|
|
64
|
+
|
|
65
|
+
features,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const ansi = Object.assign(makeAnsi, makeAnsi());
|
|
70
|
+
|
|
71
|
+
export default ansi;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
const move = (code: string) => (count?: number): string =>
|
|
2
|
+
`\x1b[${count === undefined ? "" : count ? count : "?"}${code}`;
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
const move = code => count => `\x1b[${count === undefined ? "" : count ? count : "?"}${code}`;
|
|
5
|
-
|
|
6
|
-
/** @type {(count?: number) => string} */
|
|
7
|
-
const noop = () => "";
|
|
4
|
+
const noop = (): string => "";
|
|
8
5
|
|
|
9
6
|
const caret = {
|
|
10
7
|
up : move("A"),
|
|
@@ -14,8 +11,7 @@ const caret = {
|
|
|
14
11
|
nextLine : move("E"),
|
|
15
12
|
prevLine : move("F"),
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
x: x => `\x1b[${x}G`,
|
|
14
|
+
x: (x: number): string => `\x1b[${x}G`,
|
|
19
15
|
|
|
20
16
|
// These are the old VT100 codes, but they're widely supported by old and new terminals. The
|
|
21
17
|
// newer VT220 codes are standardized by ECMA and ISO, and are also widely supported, but might
|
|
@@ -33,8 +29,7 @@ const caret = {
|
|
|
33
29
|
|
|
34
30
|
position: {
|
|
35
31
|
get: "\x1b[6n",
|
|
36
|
-
|
|
37
|
-
set: (x, y) => `\x1b[${y};${x}H`,
|
|
32
|
+
set: (x: number, y: number): string => `\x1b[${y};${x}H`,
|
|
38
33
|
},
|
|
39
34
|
|
|
40
35
|
shape: {
|
|
@@ -48,8 +43,9 @@ const caret = {
|
|
|
48
43
|
},
|
|
49
44
|
};
|
|
50
45
|
|
|
51
|
-
|
|
52
|
-
|
|
46
|
+
export type Caret = typeof caret;
|
|
47
|
+
|
|
48
|
+
const disabled: Caret = {
|
|
53
49
|
up : noop,
|
|
54
50
|
down : noop,
|
|
55
51
|
forward : noop,
|
|
@@ -81,6 +77,4 @@ const disabled = {
|
|
|
81
77
|
},
|
|
82
78
|
};
|
|
83
79
|
|
|
84
|
-
const makeCaret = (enabled = true) => enabled ? caret : disabled;
|
|
85
|
-
|
|
86
|
-
module.exports = {makeCaret};
|
|
80
|
+
export const makeCaret = (enabled = true): Caret => enabled ? caret : disabled;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
1
|
const erase = {
|
|
4
2
|
line: {
|
|
5
|
-
toStart: "\x1b[1K",
|
|
6
|
-
toEnd
|
|
7
|
-
full
|
|
3
|
+
toStart : "\x1b[1K",
|
|
4
|
+
toEnd : "\x1b[0K",
|
|
5
|
+
full : "\x1b[2K",
|
|
8
6
|
},
|
|
9
7
|
screen: {
|
|
10
8
|
toStart : "\x1b[1J",
|
|
@@ -14,8 +12,9 @@ const erase = {
|
|
|
14
12
|
},
|
|
15
13
|
};
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
export type Erase = typeof erase;
|
|
16
|
+
|
|
17
|
+
const disabled: Erase = {
|
|
19
18
|
line: {
|
|
20
19
|
toStart : "",
|
|
21
20
|
toEnd : "",
|
|
@@ -29,6 +28,4 @@ const disabled = {
|
|
|
29
28
|
},
|
|
30
29
|
};
|
|
31
30
|
|
|
32
|
-
const makeErase = (enabled = true) => enabled ? erase : disabled;
|
|
33
|
-
|
|
34
|
-
module.exports = {makeErase};
|
|
31
|
+
export const makeErase = (enabled = true): Erase => enabled ? erase : disabled;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {detectFeatureSupport, getColorDepth} from "./detect";
|
|
2
|
+
|
|
3
|
+
import type {ColorDepth, Features} from "./types";
|
|
4
|
+
|
|
5
|
+
function normalizeColorDepth(colorDepth: number): ColorDepth {
|
|
6
|
+
colorDepth = Math.floor(colorDepth);
|
|
7
|
+
if (colorDepth >= 24) return 24;
|
|
8
|
+
if (colorDepth >= 8) return 8;
|
|
9
|
+
if (colorDepth >= 4) return 4;
|
|
10
|
+
if (colorDepth === 3) return 3;
|
|
11
|
+
return 1;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function build(
|
|
15
|
+
isTTY : boolean,
|
|
16
|
+
colorDepth : ColorDepth,
|
|
17
|
+
style? : boolean,
|
|
18
|
+
caret? : boolean,
|
|
19
|
+
erase? : boolean,
|
|
20
|
+
scroll? : boolean,
|
|
21
|
+
terminal? : boolean,
|
|
22
|
+
): Features {
|
|
23
|
+
if (
|
|
24
|
+
style !== undefined &&
|
|
25
|
+
caret !== undefined &&
|
|
26
|
+
erase !== undefined &&
|
|
27
|
+
scroll !== undefined &&
|
|
28
|
+
terminal !== undefined
|
|
29
|
+
)
|
|
30
|
+
return {colorDepth: normalizeColorDepth(colorDepth), style, caret, erase, scroll, terminal};
|
|
31
|
+
|
|
32
|
+
const support = detectFeatureSupport(isTTY, colorDepth);
|
|
33
|
+
return {
|
|
34
|
+
colorDepth : normalizeColorDepth(colorDepth),
|
|
35
|
+
style : style ?? support.style,
|
|
36
|
+
caret : caret ?? support.caret,
|
|
37
|
+
erase : erase ?? support.erase,
|
|
38
|
+
scroll : scroll ?? support.scroll,
|
|
39
|
+
terminal : terminal ?? support.terminal,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const boolean = (isTTY: boolean, enabled: boolean): Features =>
|
|
44
|
+
build(isTTY, enabled ? 4 : 1);
|
|
45
|
+
|
|
46
|
+
export const number = (isTTY: boolean, colorDepth: ColorDepth): Features =>
|
|
47
|
+
build(isTTY, colorDepth);
|
|
48
|
+
|
|
49
|
+
export const tty = (stream: NodeJS.WriteStream): Features =>
|
|
50
|
+
build(true, getColorDepth(stream));
|
|
51
|
+
|
|
52
|
+
export const pipe = (): Features =>
|
|
53
|
+
build(false, getColorDepth());
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type {ColorDepth, Features} from "./types";
|
|
2
|
+
|
|
3
|
+
export function getColorDepth(stream?: NodeJS.WriteStream): ColorDepth {
|
|
4
|
+
if (stream?.isTTY)
|
|
5
|
+
return stream.getColorDepth() as ColorDepth;
|
|
6
|
+
|
|
7
|
+
if (process.env.NO_COLOR || process.env.NODE_DISABLE_COLORS)
|
|
8
|
+
return 1;
|
|
9
|
+
|
|
10
|
+
switch (process.env.FORCE_COLOR) {
|
|
11
|
+
case "":
|
|
12
|
+
case "true":
|
|
13
|
+
case "1":
|
|
14
|
+
return 4;
|
|
15
|
+
case "2":
|
|
16
|
+
return 8;
|
|
17
|
+
case "3":
|
|
18
|
+
return 24;
|
|
19
|
+
default:
|
|
20
|
+
return 1;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function detectFeatureSupport(
|
|
25
|
+
isTTY : boolean,
|
|
26
|
+
colorDepth : ColorDepth,
|
|
27
|
+
): Omit<Features, "colorDepth"> {
|
|
28
|
+
const enabled = process.env.TERM !== "dumb" && isTTY;
|
|
29
|
+
return {
|
|
30
|
+
style : colorDepth > 1,
|
|
31
|
+
caret : enabled,
|
|
32
|
+
erase : enabled,
|
|
33
|
+
scroll : enabled,
|
|
34
|
+
terminal : enabled,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -1,25 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
import {Socket} from "node:net";
|
|
2
|
+
import {WriteStream} from "node:tty";
|
|
3
|
+
import {boolean, build, number, pipe, tty} from "./build";
|
|
4
|
+
import {getColorDepth} from "./detect";
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
const {WriteStream} = require("node:tty");
|
|
5
|
-
const {build, boolean, number, tty, pipe} = require("./build");
|
|
6
|
-
const {getColorDepth} = require("./detect");
|
|
6
|
+
import type {ColorDepth, Features} from "./types";
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
@typedef {import("./types").ColorDepth} ColorDepth
|
|
10
|
-
@typedef {import("./types").Features} Features
|
|
11
|
-
|
|
12
|
-
@typedef {
|
|
8
|
+
export type Args =
|
|
13
9
|
| [enabled : boolean, stream?: NodeJS.WriteStream]
|
|
14
10
|
| [colorDepth : ColorDepth, stream?: NodeJS.WriteStream]
|
|
15
11
|
| [features : Partial<Features>, stream?: NodeJS.WriteStream]
|
|
16
12
|
| [socket : Socket]
|
|
17
|
-
| [stream? : NodeJS.WriteStream]
|
|
18
|
-
} Args
|
|
19
|
-
*/
|
|
13
|
+
| [stream? : NodeJS.WriteStream];
|
|
20
14
|
|
|
21
|
-
|
|
22
|
-
function getFeatures(...args) {
|
|
15
|
+
export function getFeatures(...args: Args): Features {
|
|
23
16
|
let [features, stream] = args;
|
|
24
17
|
|
|
25
18
|
if (typeof features === "boolean")
|
|
@@ -48,6 +41,4 @@ function getFeatures(...args) {
|
|
|
48
41
|
return build(true, getColorDepth(stream), style, caret, erase, scroll, terminal);
|
|
49
42
|
|
|
50
43
|
return build(false, getColorDepth(), style, caret, erase, scroll, terminal);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
module.exports = {getFeatures};
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./features";
|
package/src/index.ts
ADDED
package/src/{pad.js → pad.ts}
RENAMED
|
@@ -1,21 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {visibleLength} = require("./strip");
|
|
1
|
+
import {visibleLength} from "./strip";
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* Pad the given text at the end with the specified fill string to the target visible length without
|
|
7
5
|
* counting ANSI escape codes.
|
|
8
|
-
* @type {(text: string, targetLength: number, fillString?: string) => string}
|
|
9
6
|
*/
|
|
10
|
-
const padEnd = (text, targetLength, fillString = " ") =>
|
|
7
|
+
export const padEnd = (text: string, targetLength: number, fillString = " "): string =>
|
|
11
8
|
text + fillString.repeat(Math.max(0, targetLength - visibleLength(text)) / fillString.length);
|
|
12
9
|
|
|
13
10
|
/**
|
|
14
11
|
* Pad the given text at the start with the specified fill string to the target visible length
|
|
15
12
|
* without counting ANSI escape codes.
|
|
16
|
-
* @type {(text: string, targetLength: number, fillString?: string) => string}
|
|
17
13
|
*/
|
|
18
|
-
const padStart = (text, targetLength, fillString = " ") =>
|
|
19
|
-
fillString.repeat(Math.max(0, targetLength - visibleLength(text)) / fillString.length) + text;
|
|
20
|
-
|
|
21
|
-
module.exports = {padEnd, padStart};
|
|
14
|
+
export const padStart = (text: string, targetLength: number, fillString = " "): string =>
|
|
15
|
+
fillString.repeat(Math.max(0, targetLength - visibleLength(text)) / fillString.length) + text;
|
|
@@ -37,8 +37,6 @@ timeit(() => long .replace(new RegExp(rxSGR.source, "g"), ""), {description: "lo
|
|
|
37
37
|
```
|
|
38
38
|
*/
|
|
39
39
|
|
|
40
|
-
const rxSGR = Object.freeze(/\x1b\[[\d;]*m/g);
|
|
41
|
-
const rxCSI = Object.freeze(/\x1b\[[0-?]*[ -/]*[@-~]/g);
|
|
42
|
-
const rxUnsafe = Object.freeze(/\x1b\[[0-?]*[ -/]*[@-ln-~]/g); // Everything except SGR codes (m).
|
|
43
|
-
|
|
44
|
-
module.exports = {rxSGR, rxCSI, rxUnsafe};
|
|
40
|
+
export const rxSGR = Object.freeze(/\x1b\[[\d;]*m/g);
|
|
41
|
+
export const rxCSI = Object.freeze(/\x1b\[[0-?]*[ -/]*[@-~]/g);
|
|
42
|
+
export const rxUnsafe = Object.freeze(/\x1b\[[0-?]*[ -/]*[@-ln-~]/g); // Everything except SGR codes (m).
|
package/src/scroll.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const scroll = {
|
|
2
|
+
up : (lines?: number): string => `\x1b[${lines ?? 1}S`,
|
|
3
|
+
down : (lines?: number): string => `\x1b[${lines ?? 1}T`,
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export type Scroll = typeof scroll;
|
|
7
|
+
|
|
8
|
+
const disabled: Scroll = {
|
|
9
|
+
up : () => "",
|
|
10
|
+
down : () => "",
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const makeScroll = (enabled = true): Scroll => enabled ? scroll : disabled;
|
|
@@ -1,25 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {makeSGR} from "../sgr";
|
|
2
|
+
import {makeStyle} from "../style";
|
|
3
|
+
import {clip, rgbToX16, rgbToX256, rgbToX8, x256ToRgb} from "./utils";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
import type {ColorDepth} from "../../features/types";
|
|
6
|
+
import type {SGR} from "../sgr";
|
|
7
|
+
import type {Channel, Color} from "./types";
|
|
8
|
+
|
|
9
|
+
export type {Color} from "./types";
|
|
9
10
|
|
|
10
11
|
const fgOpen = 30, fgClose = 39;
|
|
11
12
|
const bgOpen = 40, bgClose = 49;
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
function makeChannel(colorDepth, open, close) {
|
|
14
|
+
function makeChannel(colorDepth: ColorDepth, open: number, close: number): Channel {
|
|
15
15
|
const sgrBase = makeSGR(colorDepth > 1);
|
|
16
16
|
const style = makeStyle(colorDepth > 1);
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
const sgr = code => sgrBase(code, close);
|
|
18
|
+
const sgr = (code: number | number[]): SGR => sgrBase(code, close);
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
const bright =
|
|
20
|
+
const bright: (index: number) => SGR =
|
|
23
21
|
colorDepth >= 4 ? index => sgr(open + 60 + index) :
|
|
24
22
|
colorDepth === 3 ?
|
|
25
23
|
open === fgOpen ?
|
|
@@ -27,11 +25,10 @@ function makeChannel(colorDepth, open, close) {
|
|
|
27
25
|
index => sgr(open + index) :
|
|
28
26
|
() => sgr(0);
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
const x16ToX8 =
|
|
28
|
+
const x16ToX8: (code: number) => SGR =
|
|
32
29
|
open === fgOpen ?
|
|
33
30
|
code => code >= 60 ? style.bold.combine(sgr(open + code - 60)) : sgr(open + code) :
|
|
34
|
-
code => code >= 60 ? sgr(open + code - 60)
|
|
31
|
+
code => code >= 60 ? sgr(open + code - 60) : sgr(open + code);
|
|
35
32
|
|
|
36
33
|
return {
|
|
37
34
|
black : sgr(open + 0),
|
|
@@ -62,43 +59,37 @@ function makeChannel(colorDepth, open, close) {
|
|
|
62
59
|
(r, g, b) => sgr(open + rgbToX8(...clip(r, g, b))) :
|
|
63
60
|
() => sgr(0),
|
|
64
61
|
|
|
65
|
-
/** @type {(...args: [number] | [number, number, number]) => SGR} */
|
|
66
62
|
x256:
|
|
67
63
|
colorDepth >= 8 ?
|
|
68
|
-
(...args) => sgr(
|
|
64
|
+
(...args: [number] | [number, number, number]): SGR => sgr(
|
|
69
65
|
[open + 8, 5, args.length === 3 ? rgbToX256(...clip(...args)) : clip(args[0])],
|
|
70
66
|
) :
|
|
71
67
|
colorDepth >= 4 ?
|
|
72
|
-
(...args) => sgr(
|
|
68
|
+
(...args: [number] | [number, number, number]): SGR => sgr(
|
|
73
69
|
open +
|
|
74
70
|
rgbToX16(...(args.length === 3 ? clip(...args) : x256ToRgb(clip(args[0])))),
|
|
75
71
|
) :
|
|
76
72
|
colorDepth === 3 ?
|
|
77
73
|
open === fgOpen ?
|
|
78
|
-
(...args) => x16ToX8(
|
|
79
|
-
args.length === 3
|
|
80
|
-
rgbToX16(...clip(...args))
|
|
81
|
-
rgbToX16(...x256ToRgb(clip(args[0]))),
|
|
74
|
+
(...args: [number] | [number, number, number]): SGR => x16ToX8(
|
|
75
|
+
args.length === 3
|
|
76
|
+
? rgbToX16(...clip(...args))
|
|
77
|
+
: rgbToX16(...x256ToRgb(clip(args[0]))),
|
|
82
78
|
) :
|
|
83
|
-
(...args) => sgr(
|
|
84
|
-
open +
|
|
85
|
-
...args.length === 3 ? clip(...args) : x256ToRgb(clip(args[0])),
|
|
86
|
-
),
|
|
79
|
+
(...args: [number] | [number, number, number]): SGR => sgr(
|
|
80
|
+
open +
|
|
81
|
+
rgbToX8(...args.length === 3 ? clip(...args) : x256ToRgb(clip(args[0]))),
|
|
87
82
|
) :
|
|
88
|
-
() => sgr(0),
|
|
83
|
+
(): SGR => sgr(0),
|
|
89
84
|
|
|
90
85
|
default: colorDepth > 1 ? `\x1b[${close}m` : "",
|
|
91
86
|
};
|
|
92
87
|
}
|
|
93
88
|
|
|
94
|
-
|
|
95
|
-
const cache = {};
|
|
89
|
+
const cache: Partial<Record<ColorDepth, Color>> = {};
|
|
96
90
|
|
|
97
|
-
|
|
98
|
-
const makeColor = (colorDepth = 4) =>
|
|
91
|
+
export const makeColor = (colorDepth: ColorDepth = 4): Color =>
|
|
99
92
|
cache[colorDepth] ?? (cache[colorDepth] = {
|
|
100
93
|
fg : makeChannel(colorDepth, fgOpen, fgClose),
|
|
101
94
|
bg : makeChannel(colorDepth, bgOpen, bgClose),
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
module.exports = {makeColor};
|
|
95
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./color";
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type {SGR} from "../sgr";
|
|
2
|
+
|
|
1
3
|
export interface Channel {
|
|
2
4
|
black : SGR;
|
|
3
5
|
red : SGR;
|
|
@@ -24,5 +26,7 @@ export interface Channel {
|
|
|
24
26
|
(r: number, g: number, b: number): SGR;
|
|
25
27
|
};
|
|
26
28
|
|
|
27
|
-
default: string
|
|
28
|
-
}
|
|
29
|
+
default: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type Color = {fg: Channel; bg: Channel};
|