@peteanderson/ansi 0.2.3 → 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.
Files changed (63) hide show
  1. package/README.md +30 -70
  2. package/package.json +20 -13
  3. package/dist/ansi.d.ts +0 -13
  4. package/dist/ansi.js +0 -23
  5. package/dist/caret.d.ts +0 -25
  6. package/dist/caret.js +0 -40
  7. package/dist/erase.d.ts +0 -14
  8. package/dist/erase.js +0 -15
  9. package/dist/index.d.ts +0 -107
  10. package/dist/index.js +0 -2
  11. package/dist/patterns.d.ts +0 -3
  12. package/dist/patterns.js +0 -43
  13. package/dist/scroll.d.ts +0 -2
  14. package/dist/scroll.js +0 -8
  15. package/dist/sgr/color.d.ts +0 -62
  16. package/dist/sgr/color.js +0 -111
  17. package/dist/sgr/index.d.ts +0 -59
  18. package/dist/sgr/index.js +0 -6
  19. package/dist/sgr/reset.d.ts +0 -1
  20. package/dist/sgr/reset.js +0 -3
  21. package/dist/sgr/sgr.d.ts +0 -14
  22. package/dist/sgr/sgr.js +0 -47
  23. package/dist/sgr/style.d.ts +0 -13
  24. package/dist/sgr/style.js +0 -16
  25. package/dist/sgr/utils.d.ts +0 -2
  26. package/dist/sgr/utils.js +0 -16
  27. package/dist/simplify/atom.d.ts +0 -3
  28. package/dist/simplify/atom.js +0 -28
  29. package/dist/simplify/index.d.ts +0 -2
  30. package/dist/simplify/index.js +0 -2
  31. package/dist/simplify/lookup.d.ts +0 -5
  32. package/dist/simplify/lookup.js +0 -77
  33. package/dist/simplify/simplify.d.ts +0 -1
  34. package/dist/simplify/simplify.js +0 -25
  35. package/dist/simplify/state.d.ts +0 -10
  36. package/dist/simplify/state.js +0 -57
  37. package/dist/simplify/utils.d.ts +0 -2
  38. package/dist/simplify/utils.js +0 -31
  39. package/dist/slice.d.ts +0 -1
  40. package/dist/slice.js +0 -83
  41. package/dist/strip.d.ts +0 -15
  42. package/dist/strip.js +0 -18
  43. package/src/caret.js +0 -49
  44. package/src/erase.js +0 -17
  45. package/src/index.js +0 -1
  46. package/src/patterns.js +0 -44
  47. package/src/scroll.js +0 -10
  48. package/src/sgr/color.js +0 -130
  49. package/src/sgr/index.js +0 -5
  50. package/src/sgr/reset.js +0 -3
  51. package/src/sgr/sgr.js +0 -66
  52. package/src/sgr/style.js +0 -19
  53. package/src/sgr/utils.js +0 -20
  54. package/src/simplify/atom.js +0 -34
  55. package/src/simplify/index.js +0 -1
  56. package/src/simplify/lookup.js +0 -86
  57. package/src/simplify/simplify.js +0 -33
  58. package/src/simplify/state.js +0 -73
  59. package/src/simplify/types.d.ts +0 -28
  60. package/src/simplify/utils.js +0 -41
  61. package/src/slice.js +0 -99
  62. package/src/strip.js +0 -23
  63. /package/{src/ansi.js → ansi.js} +0 -0
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @peteanderson/ansi
2
2
 
3
- ANSI escape sequence helpers for Node.js terminal output.
3
+ ANSI escape sequence helpers for Node.js terminal output. Automatically disables color when stdout is not a TTY or when standard environment variables (`NO_COLOR`, `NODE_DISABLE_COLORS`, `FORCE_COLOR`, `TERM=dumb`) indicate it should be.
4
4
 
5
5
  ## Installation
6
6
 
@@ -11,94 +11,54 @@ npm install @peteanderson/ansi
11
11
  ## Usage
12
12
 
13
13
  ```js
14
- const ansi = require("@peteanderson/ansi");
15
-
16
- console.log(ansi.fg.red("error: something went wrong"));
17
- console.log(ansi.bg.blue.combine(ansi.fg.white)("highlighted"));
18
- console.log(ansi.style.bold("important"));
19
- console.log(ansi.fg.rgb(5, 2, 0)("custom color"));
20
- console.log(ansi.strip("styled text")); // remove all ANSI codes
21
- console.log(ansi.visibleLength(styledText)); // get display width
22
- console.log(ansi.slice("styled text", 0, 5)); // slice by visible length
23
- console.log(ansi.simplify(styledText)); // combine adjacent SGR sequences
14
+ const {fg, bg, style, reset, stripAnsiSequences} = require('@peteanderson/ansi');
15
+
16
+ console.log(fg.red('error: something went wrong'));
17
+ console.log(bg.blue(fg.white('highlighted')));
18
+ console.log(style.bold('important'));
19
+ console.log(fg.rgb(5, 2, 0)('custom color'));
20
+ console.log('some styled text' + reset);
21
+ console.log(stripAnsiSequences('\x1b[31mred\x1b[0m')); // => 'red'
24
22
  ```
25
23
 
26
24
  ## API
27
25
 
28
- ### `fg`foreground colors
26
+ All color and style functions accept a string and return a string. When color is disabled, the functions are identity they return the input unchanged.
29
27
 
30
- Functions that wrap text with color codes:
28
+ ### `fg` foreground colors
31
29
 
32
- - Basic colors: `black` `red` `green` `yellow` `blue` `magenta` `cyan` `white` `default`
33
- - Bright colors: `brightBlack` `brightRed` `brightGreen` `brightYellow` `brightBlue` `brightMagenta`
34
- `brightCyan` `brightWhite`
35
- - `fg.rgb(r, g, b)(text)` - 24-bit RGB color (r, g, b in 0–5 or grayscale 232–255)
36
- - `fg.x256(code)(text)` or `fg.x256(r, g, b)(text)` - 256-color palette
30
+ `black` `red` `green` `yellow` `blue` `magenta` `cyan` `white` `gray`
37
31
 
38
- All return functions with `open` and `close` properties for raw sequences.
32
+ ```js
33
+ fg.red('text')
34
+ fg.rgb(r, g, b)('text') // r, g, b in 0–5 for the 6×6×6 cube, or grayscale 232–255
35
+ ```
39
36
 
40
37
  ### `bg` — background colors
41
38
 
42
- Functions that wrap text with color codes:
39
+ `black` `red` `green` `yellow` `blue` `magenta` `cyan` `white`
43
40
 
44
- - Basic colors: `black` `red` `green` `yellow` `blue` `magenta` `cyan` `white` `default`
45
- - Bright colors: `brightBlack` `brightRed` `brightGreen` `brightYellow` `brightBlue` `brightMagenta`
46
- `brightCyan` `brightWhite`
47
- - `bg.rgb(r, g, b)(text)` - 24-bit RGB color
48
- - `bg.x256(code)(text)` or `bg.x256(r, g, b)(text)` - 256-color palette
41
+ ```js
42
+ bg.green('text')
43
+ bg.rgb(r, g, b)('text')
44
+ ```
49
45
 
50
46
  ### `style`
51
47
 
52
- Functions that wrap text with style codes:
53
-
54
- `bold` `dim` `italic` `underline` `inverse` `hidden` `strikethrough` `doubleUnderline` `framed`
55
- `encircled` `overline`
56
-
57
- All return functions with `open` and `close` properties for raw sequences.
58
-
59
- ### `caret`
60
-
61
- - `caret.show` / `caret.hide` - show or hide the cursor
62
- - `caret.position.get` - get the current cursor position (terminal sends position to stdin)
63
- - `caret.position.set(row, col)` - set cursor position (1-based indexing)
64
- - `caret.shape.block` / `caret.shape.underline` / `caret.shape.bar` - change cursor shape
65
- - `caret.up(n)` / `caret.down(n)` / `caret.forward(n)` / `caret.backward(n)` - move cursor
66
- - `caret.nextLine(n)` / `caret.prevLine(n)` - move cursor to next/previous line
67
- - `caret.x(col)` - move cursor to column (1-based)
68
- - `caret.save` / `caret.restore` - save/restore cursor position (VT100)
69
-
70
- ### `erase`
48
+ `bold` `dim` `italic` `underline` `inverse` `hidden` `strikethrough`
71
49
 
72
- - `erase.line.toStart` / `erase.line.toEnd` / `erase.line.full` - erase line
73
- - `erase.screen.toStart` / `erase.screen.toEnd` / `erase.screen.full` - erase screen
74
- - `erase.screen.scrollback` - erase screen and scrollback buffer
75
-
76
- ### `scroll`
77
-
78
- - `scroll.up(lines)` - scroll up (default 1 line)
79
- - `scroll.down(lines)` - scroll down (default 1 line)
80
-
81
- ### `strip(text)`
82
-
83
- Removes all ANSI CSI sequences from a string.
84
-
85
- ### `slice(text, start, end)`
86
-
87
- Slices a string by visible characters, ignoring ANSI sequences. Works like `String.prototype.slice`
88
- but counts only visible characters. Properly maintains terminal state at slice boundaries.
89
-
90
- ### `sanitize(text)`
91
-
92
- Removes "unsafe" CSI sequences (non-SGR), leaving only color and style codes.
50
+ ```js
51
+ style.bold('text')
52
+ style.italic(style.bold('text'))
53
+ ```
93
54
 
94
- ### `simplify(text)`
55
+ ### `reset`
95
56
 
96
- Simplifies ANSI SGR sequences by combining adjacent sequences and removing redundant codes. Useful
97
- for optimizing styled strings.
57
+ The SGR reset sequence (`\x1b[0m`). An empty string when color is disabled.
98
58
 
99
- ### `visibleLength(text)`
59
+ ### `stripAnsiSequences(text)`
100
60
 
101
- Returns the visible length of a string with all ANSI sequences removed.
61
+ Removes ANSI SGR escape sequences from a string.
102
62
 
103
63
  ## License
104
64
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name" : "@peteanderson/ansi",
3
- "version" : "0.2.3",
3
+ "version" : "0.2.4",
4
4
  "description" : "ANSI escape sequence generation with automatic feature detection",
5
5
  "author" : {
6
6
  "name" : "Pete Anderson",
@@ -8,25 +8,32 @@
8
8
  },
9
9
  "repository" : {
10
10
  "type" : "git",
11
- "url" : "git+https://github.com/anderson-pete/ansi.git"
11
+ "url" : "https://github.com/anderson-pete/ansi"
12
12
  },
13
- "keywords" : ["ansi", "nodejs", "color", "terminal", "cli"],
14
- "engines" : {"node": ">=18"},
15
- "files" : ["dist", "src"],
16
- "main" : "dist/ansi.js",
17
- "types" : "dist/ansi.d.ts",
13
+ "keywords" : [
14
+ "ansi",
15
+ "nodejs",
16
+ "color",
17
+ "terminal",
18
+ "cli"
19
+ ],
20
+ "engines" : {
21
+ "node": ">=18"
22
+ },
23
+ "files" : [
24
+ "."
25
+ ],
26
+ "main" : "ansi.js",
27
+ "types" : "ansi.d.ts",
18
28
  "exports" : {
19
29
  ".": {
20
- "types" : "./dist/ansi.d.ts",
21
- "require" : "./dist/ansi.js"
30
+ "require": "./ansi.js"
22
31
  }
23
32
  },
24
33
  "license" : "MIT",
25
34
  "scripts" : {
26
- "prebuild" : "node -e \"require('node:fs').rmSync('dist', {force: true, recursive: true})\"",
27
- "build" : "tsc -p tsconfig.build.json",
28
- "prepack" : "npm run build",
29
- "tag" : "git tag -a v$npm_package_version -m v$npm_package_version"
35
+ "build" : "rm *.d.ts && tsc --allowJs --declaration --emitDeclarationOnly --moduleResolution node --ignoreDeprecations 6.0 ansi.js",
36
+ "tag" : "git tag -a v$npm_package_version -m v$npm_package_version"
30
37
  },
31
38
  "devDependencies" : {
32
39
  "@types/node" : "^26.0.0",
package/dist/ansi.d.ts DELETED
@@ -1,13 +0,0 @@
1
- import caret = require("./caret");
2
- import erase = require("./erase");
3
- import scroll = require("./scroll");
4
- import { reset } from "./sgr/reset";
5
- import { style } from "./sgr/style";
6
- import { fg } from "./sgr/color";
7
- import { bg } from "./sgr/color";
8
- import { strip } from "./strip";
9
- import { visibleLength } from "./strip";
10
- import { sanitize } from "./strip";
11
- import { slice } from "./slice";
12
- import { simplify } from "./simplify/simplify";
13
- export { caret, erase, scroll, reset, style, fg, bg, strip, visibleLength, sanitize, slice, simplify };
package/dist/ansi.js DELETED
@@ -1,23 +0,0 @@
1
- "use strict";
2
- const caret = require("./caret");
3
- const erase = require("./erase");
4
- const scroll = require("./scroll");
5
- const { bg, fg, reset, style } = require("./sgr");
6
- const { simplify } = require("./simplify");
7
- const { slice } = require("./slice");
8
- const { sanitize, strip, visibleLength } = require("./strip");
9
- const ansi = {
10
- caret,
11
- erase,
12
- scroll,
13
- reset,
14
- style,
15
- fg,
16
- bg,
17
- strip,
18
- visibleLength,
19
- sanitize,
20
- slice,
21
- simplify,
22
- };
23
- module.exports = ansi;
package/dist/caret.d.ts DELETED
@@ -1,25 +0,0 @@
1
- export let up: (count?: number) => string;
2
- export let down: (count?: number) => string;
3
- export let forward: (count?: number) => string;
4
- export let backward: (count?: number) => string;
5
- export let nextLine: (count?: number) => string;
6
- export let prevLine: (count?: number) => string;
7
- export let x: (x: number) => string;
8
- export let save: string;
9
- export let restore: string;
10
- export let hide: string;
11
- export let show: string;
12
- export namespace position {
13
- let get: string;
14
- let set: (x: number, y: number) => string;
15
- }
16
- export namespace shape {
17
- export let steadyBlock: string;
18
- export let steadyBar: string;
19
- export let steadyUnderline: string;
20
- export let blinkingBlock: string;
21
- export let blinkingBar: string;
22
- export let blinkingUnderline: string;
23
- let _default: string;
24
- export { _default as default };
25
- }
package/dist/caret.js DELETED
@@ -1,40 +0,0 @@
1
- "use strict";
2
- /** @type {(code: string) => (count?: number) => string} */
3
- const move = code => count => `\x1b[${count === undefined ? "" : count ? count : "?"}${code}`;
4
- const caret = {
5
- up: move("A"),
6
- down: move("B"),
7
- forward: move("C"),
8
- backward: move("D"),
9
- nextLine: move("E"),
10
- prevLine: move("F"),
11
- /** @type {(x: number) => string} */
12
- x: x => `\x1b[${x}G`,
13
- // These are the old VT100 codes, but they're widely supported by old and new terminals. The
14
- // newer VT220 codes are standardized by ECMA and ISO, and are also widely supported, but might
15
- // not work in some older terminals. The VT220 codes are:
16
- //
17
- // ```
18
- // save : "\x1b[s",
19
- // restore : "\x1b[u",
20
- // ```
21
- save: "\x1b7",
22
- restore: "\x1b8",
23
- hide: "\x1b[?25l",
24
- show: "\x1b[?25h",
25
- position: {
26
- get: "\x1b[6n",
27
- /** @type {(x: number, y: number) => string} */
28
- set: (x, y) => `\x1b[${y};${x}H`,
29
- },
30
- shape: {
31
- steadyBlock: "\x1b[2 q",
32
- steadyBar: "\x1b[6 q",
33
- steadyUnderline: "\x1b[4 q",
34
- blinkingBlock: "\x1b[1 q",
35
- blinkingBar: "\x1b[5 q",
36
- blinkingUnderline: "\x1b[3 q",
37
- default: "\x1b[0 q",
38
- },
39
- };
40
- module.exports = caret;
package/dist/erase.d.ts DELETED
@@ -1,14 +0,0 @@
1
- export namespace line {
2
- let toStart: string;
3
- let toEnd: string;
4
- let full: string;
5
- }
6
- export namespace screen {
7
- let toStart_1: string;
8
- export { toStart_1 as toStart };
9
- let toEnd_1: string;
10
- export { toEnd_1 as toEnd };
11
- let full_1: string;
12
- export { full_1 as full };
13
- export let scrollback: string;
14
- }
package/dist/erase.js DELETED
@@ -1,15 +0,0 @@
1
- "use strict";
2
- const erase = {
3
- line: {
4
- toStart: "\x1b[1K",
5
- toEnd: "\x1b[0K",
6
- full: "\x1b[2K",
7
- },
8
- screen: {
9
- toStart: "\x1b[1J",
10
- toEnd: "\x1b[0J",
11
- full: "\x1b[2J",
12
- scrollback: "\x1b[3J",
13
- },
14
- };
15
- module.exports = erase;
package/dist/index.d.ts DELETED
@@ -1,107 +0,0 @@
1
- declare const _exports: {
2
- caret: {
3
- up: (count?: number) => string;
4
- down: (count?: number) => string;
5
- forward: (count?: number) => string;
6
- backward: (count?: number) => string;
7
- nextLine: (count?: number) => string;
8
- prevLine: (count?: number) => string;
9
- x: (x: number) => string;
10
- save: string;
11
- restore: string;
12
- hide: string;
13
- show: string;
14
- position: {
15
- get: string;
16
- set: (x: number, y: number) => string;
17
- };
18
- shape: {
19
- steadyBlock: string;
20
- steadyBar: string;
21
- steadyUnderline: string;
22
- blinkingBlock: string;
23
- blinkingBar: string;
24
- blinkingUnderline: string;
25
- default: string;
26
- };
27
- };
28
- erase: {
29
- line: {
30
- toStart: string;
31
- toEnd: string;
32
- full: string;
33
- };
34
- screen: {
35
- toStart: string;
36
- toEnd: string;
37
- full: string;
38
- scrollback: string;
39
- };
40
- };
41
- scroll: {
42
- up: (lines?: number) => string;
43
- down: (lines?: number) => string;
44
- };
45
- 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
- };
101
- strip: (text: string) => string;
102
- visibleLength: (text: string) => number;
103
- sanitize: (text: string) => string;
104
- slice: typeof import("./slice").slice;
105
- simplify: typeof import("./simplify/simplify").simplify;
106
- };
107
- export = _exports;
package/dist/index.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- module.exports = require("./ansi");
@@ -1,3 +0,0 @@
1
- export const rxSGR: Readonly<RegExp>;
2
- export const rxCSI: Readonly<RegExp>;
3
- export const rxUnsafe: Readonly<RegExp>;
package/dist/patterns.js DELETED
@@ -1,43 +0,0 @@
1
- "use strict";
2
- /*
3
- I'm freezing these to prevent accidental mutation of the `lastIndex` property, which could keep
4
- future calls from starting at the beginning of the string.
5
-
6
- Code using these objects will have to clone them (with `new RegExp(rx)`) before using functions
7
- that modify `lastIndex` (such as `exec`). But according to my benchmarks, cloning the regex takes
8
- mere nanoseconds, and it wasn't even measurable when operating on longer strings. V8 clearly uses a
9
- global cache of compiled regexes. I assume that SpiderMonkey does the same thing.
10
-
11
- Here are my `timeit` benchmark results:
12
-
13
- ```js
14
- const {timeit} = require("$timeit");
15
-
16
- const rxSGR = /\x1b\[[\d;]*m/g;
17
- const short = "\x1b[31mred \x1b[32mgreen \x1b[34mblue \x1b[0m";
18
- const long = short.repeat(1000);
19
-
20
- timeit(() => short.replace(rxSGR, ""), {description: "short - no clone "});
21
- timeit(() => short.replace(new RegExp(rxSGR), ""), {description: "short - clone object "});
22
- timeit(() => short.replace(new RegExp(rxSGR.source, "g"), ""), {description: "short - clone source "});
23
-
24
- console.log();
25
-
26
- timeit(() => long .replace(rxSGR, ""), {description: "long - no clone "});
27
- timeit(() => long .replace(new RegExp(rxSGR), ""), {description: "long - clone object "});
28
- timeit(() => long .replace(new RegExp(rxSGR.source, "g"), ""), {description: "long - clone source "});
29
-
30
- // Output:
31
- // short - no clone : 82.73 ns (12,087,731 in 1.000016982 s)
32
- // short - clone object : 142.132 ns (7,035,692 in 1.0000001770000002 s)
33
- // short - clone source : 127.872 ns (7,820,293 in 1.00000017 s)
34
- //
35
- // long - no clone : 47.953 ųs (20,854 in 1.0000098149999999 s)
36
- // long - clone object : 46.713 ųs (21,408 in 1.0000285520000003 s)
37
- // long - clone source : 46.491 ųs (21,510 in 1.000026492 s)
38
- ```
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
- module.exports = { rxSGR, rxCSI, rxUnsafe };
package/dist/scroll.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export let up: (lines?: number) => string;
2
- export let down: (lines?: number) => string;
package/dist/scroll.js DELETED
@@ -1,8 +0,0 @@
1
- "use strict";
2
- const scroll = {
3
- /** @type {(lines?: number) => string} */
4
- up: lines => `\x1b[${lines ?? 1}S`,
5
- /** @type {(lines?: number) => string} */
6
- down: lines => `\x1b[${lines ?? 1}T`,
7
- };
8
- module.exports = scroll;
@@ -1,62 +0,0 @@
1
- export namespace fg {
2
- export let black: import("./sgr").SGR;
3
- export let red: import("./sgr").SGR;
4
- export let green: import("./sgr").SGR;
5
- export let yellow: import("./sgr").SGR;
6
- export let blue: import("./sgr").SGR;
7
- export let magenta: import("./sgr").SGR;
8
- export let cyan: import("./sgr").SGR;
9
- export let white: import("./sgr").SGR;
10
- export let brightBlack: import("./sgr").SGR;
11
- export let brightRed: import("./sgr").SGR;
12
- export let brightGreen: import("./sgr").SGR;
13
- export let brightYellow: import("./sgr").SGR;
14
- export let brightBlue: import("./sgr").SGR;
15
- export let brightMagenta: import("./sgr").SGR;
16
- export let brightCyan: import("./sgr").SGR;
17
- export let brightWhite: import("./sgr").SGR;
18
- let _default: string;
19
- export { _default as default };
20
- export let rgb: (r: number, g: number, b: number) => (text: string) => string;
21
- export let x256: (arg0: number, arg1?: number, arg2?: number) => (text: string) => string;
22
- }
23
- export namespace bg {
24
- let black_1: import("./sgr").SGR;
25
- export { black_1 as black };
26
- let red_1: import("./sgr").SGR;
27
- export { red_1 as red };
28
- let green_1: import("./sgr").SGR;
29
- export { green_1 as green };
30
- let yellow_1: import("./sgr").SGR;
31
- export { yellow_1 as yellow };
32
- let blue_1: import("./sgr").SGR;
33
- export { blue_1 as blue };
34
- let magenta_1: import("./sgr").SGR;
35
- export { magenta_1 as magenta };
36
- let cyan_1: import("./sgr").SGR;
37
- export { cyan_1 as cyan };
38
- let white_1: import("./sgr").SGR;
39
- export { white_1 as white };
40
- let brightBlack_1: import("./sgr").SGR;
41
- export { brightBlack_1 as brightBlack };
42
- let brightRed_1: import("./sgr").SGR;
43
- export { brightRed_1 as brightRed };
44
- let brightGreen_1: import("./sgr").SGR;
45
- export { brightGreen_1 as brightGreen };
46
- let brightYellow_1: import("./sgr").SGR;
47
- export { brightYellow_1 as brightYellow };
48
- let brightBlue_1: import("./sgr").SGR;
49
- export { brightBlue_1 as brightBlue };
50
- let brightMagenta_1: import("./sgr").SGR;
51
- export { brightMagenta_1 as brightMagenta };
52
- let brightCyan_1: import("./sgr").SGR;
53
- export { brightCyan_1 as brightCyan };
54
- let brightWhite_1: import("./sgr").SGR;
55
- export { brightWhite_1 as brightWhite };
56
- let _default_1: string;
57
- export { _default_1 as default };
58
- let rgb_1: (r: number, g: number, b: number) => (text: string) => string;
59
- export { rgb_1 as rgb };
60
- let x256_1: (arg0: number, arg1?: number, arg2?: number) => (text: string) => string;
61
- export { x256_1 as x256 };
62
- }
package/dist/sgr/color.js DELETED
@@ -1,111 +0,0 @@
1
- "use strict";
2
- const { sgr } = require("./sgr");
3
- /** @type {(r: number, g: number, b: number, open: number, close: number) => (text: string) => string} */
4
- const rgb = (r, g, b, open, close) => sgr([open, 2, r, g, b], close);
5
- /**
6
- * @overload
7
- * @param {number} code
8
- * @param {number} open
9
- * @param {number} close
10
- * @returns {(text: string) => string}
11
- */ /**
12
- * @overload
13
- * @param {number} r
14
- * @param {number} g
15
- * @param {number} b
16
- * @param {number} open
17
- * @param {number} close
18
- * @returns {(text: string) => string}
19
- */ /**
20
- @type {
21
- (
22
- ...args: [number, number, number] | [number, number, number, number, number]
23
- ) => (text: string) => string}
24
- */
25
- function x256(...args) {
26
- if (args.length === 3)
27
- return sgr([args[1], 5, args[0]], args[2]);
28
- const [r, g, b, open, close] = args;
29
- if (r === g && g === b) {
30
- // grayscale
31
- return sgr([open, 5, 232 + Math.floor(r * 24 / 256)], close);
32
- }
33
- // 6x6x6 color cube
34
- return sgr([
35
- open,
36
- 5,
37
- 16 +
38
- Math.floor(r * 6 / 256) * 36 +
39
- Math.floor(g * 6 / 256) * 6 +
40
- Math.floor(b * 6 / 256)
41
- ], close);
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
- /**
64
- * @overload
65
- * @param {number} code
66
- * @returns {(text: string) => string}
67
- */ /**
68
- * @param {number} r
69
- * @param {number} g
70
- * @param {number} b
71
- * @returns {(text: string) => string}
72
- */ /** @type {(arg0: number, arg1?: number, arg2?: number) => (text: string) => string} */
73
- x256: (arg0, arg1, arg2) => arg1 === undefined || arg2 === undefined
74
- ? x256(arg0, 38, 39)
75
- : x256(arg0, arg1, arg2, 38, 39),
76
- };
77
- const bg = {
78
- black: sgr(40, 49),
79
- red: sgr(41, 49),
80
- green: sgr(42, 49),
81
- yellow: sgr(43, 49),
82
- blue: sgr(44, 49),
83
- magenta: sgr(45, 49),
84
- cyan: sgr(46, 49),
85
- white: sgr(47, 49),
86
- brightBlack: sgr(100, 49),
87
- brightRed: sgr(101, 49),
88
- brightGreen: sgr(102, 49),
89
- brightYellow: sgr(103, 49),
90
- brightBlue: sgr(104, 49),
91
- brightMagenta: sgr(105, 49),
92
- brightCyan: sgr(106, 49),
93
- brightWhite: sgr(107, 49),
94
- default: "\x1b[49m",
95
- /** @type {(r: number, g: number, b: number) => (text: string) => string} */
96
- rgb: (r, g, b) => rgb(r, g, b, 48, 49),
97
- /**
98
- * @overload
99
- * @param {number} code
100
- * @returns {(text: string) => string}
101
- */ /**
102
- * @param {number} r
103
- * @param {number} g
104
- * @param {number} b
105
- * @returns {(text: string) => string}
106
- */ /** @type {(arg0: number, arg1?: number, arg2?: number) => (text: string) => string} */
107
- x256: (arg0, arg1, arg2) => arg1 === undefined || arg2 === undefined
108
- ? x256(arg0, 48, 49)
109
- : x256(arg0, arg1, arg2, 48, 49),
110
- };
111
- module.exports = { fg, bg };