@peteanderson/ansi 1.0.0 → 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/LICENSE +7 -0
- package/README.md +174 -0
- package/dist/features/build.d.ts.map +1 -1
- package/dist/features/build.js.map +1 -1
- package/dist/features/detect.d.ts.map +1 -1
- package/dist/features/detect.js.map +1 -1
- package/dist/features/features.d.ts.map +1 -1
- package/dist/features/features.js +12 -13
- package/dist/features/features.js.map +1 -1
- package/dist/pad.d.ts +8 -0
- package/dist/pad.d.ts.map +1 -1
- package/dist/pad.js +8 -0
- package/dist/pad.js.map +1 -1
- package/dist/sgr/color/utils.d.ts.map +1 -1
- package/dist/sgr/color/utils.js +12 -4
- package/dist/sgr/color/utils.js.map +1 -1
- package/dist/sgr/sgr.d.ts.map +1 -1
- package/dist/sgr/sgr.js +8 -7
- package/dist/sgr/sgr.js.map +1 -1
- package/dist/simplify/atom.d.ts.map +1 -1
- package/dist/simplify/atom.js +8 -1
- package/dist/simplify/atom.js.map +1 -1
- package/dist/slice.d.ts.map +1 -1
- package/dist/slice.js +1 -0
- package/dist/slice.js.map +1 -1
- package/dist/strip.d.ts +3 -0
- package/dist/strip.d.ts.map +1 -1
- package/dist/strip.js +3 -0
- package/dist/strip.js.map +1 -1
- package/package.json +24 -9
- package/src/features/build.ts +4 -3
- package/src/features/detect.ts +6 -3
- package/src/features/features.ts +19 -23
- package/src/features/index.ts +1 -1
- package/src/features/types.ts +1 -1
- package/src/pad.ts +8 -0
- package/src/sgr/color/index.ts +1 -1
- package/src/sgr/color/utils.ts +15 -5
- package/src/sgr/sgr.ts +14 -17
- package/src/simplify/atom.ts +8 -2
- package/src/slice.ts +1 -0
- package/src/strip.ts +5 -0
- package/dist/sgr/color/test-rgb.d.ts +0 -3
- package/dist/sgr/color/test-rgb.d.ts.map +0 -1
- package/dist/sgr/color/test-rgb.js +0 -149
- package/dist/sgr/color/test-rgb.js.map +0 -1
- package/dist/simplify/test.d.ts +0 -2
- package/dist/simplify/test.d.ts.map +0 -1
- package/dist/simplify/test.js +0 -64
- package/dist/simplify/test.js.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2026 Pete Anderson
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# @peteanderson/ansi
|
|
2
|
+
|
|
3
|
+
ANSI escape sequence helpers for Node.js terminal output. Automatically detects terminal
|
|
4
|
+
capabilities and adapts output accordingly.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
npm install @peteanderson/ansi
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```js
|
|
15
|
+
const ansi = require("@peteanderson/ansi");
|
|
16
|
+
|
|
17
|
+
console.log(ansi.fg.red("error: something went wrong"));
|
|
18
|
+
console.log(ansi.bg.blue.combine(ansi.fg.white)("highlighted"));
|
|
19
|
+
console.log(ansi.style.bold("important"));
|
|
20
|
+
console.log(ansi.fg.rgb(5, 2, 0)("custom color"));
|
|
21
|
+
|
|
22
|
+
// Disable colors for a specific stream
|
|
23
|
+
const ansiNoColor = ansi(1); // force 1-bit (no color)
|
|
24
|
+
console.log(ansiNoColor.fg.red("this won't be colored"));
|
|
25
|
+
|
|
26
|
+
// Override specific features
|
|
27
|
+
const customAnsi = ansi({colorDepth: 8, caret: false});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Feature Detection
|
|
31
|
+
|
|
32
|
+
The module automatically detects:
|
|
33
|
+
|
|
34
|
+
- **Color depth**: 1 (none), 4 (16 colors), 8 (256 colors), 24 (true color)
|
|
35
|
+
- **Style support**: enabled if color depth > 1
|
|
36
|
+
- **Other features**: caret, erase, scroll — enabled if output is a TTY and `TERM` is not `dumb`
|
|
37
|
+
|
|
38
|
+
When disabled, features output empty strings. Color outputs plain text. This can be overridden:
|
|
39
|
+
|
|
40
|
+
- Pass a boolean to force color on/off
|
|
41
|
+
- Pass a number to set specific color depth (1, 3, 4, 8, or 24)
|
|
42
|
+
- Pass a stream to use for detection
|
|
43
|
+
- Pass a partial features object to override individual features
|
|
44
|
+
|
|
45
|
+
## API
|
|
46
|
+
|
|
47
|
+
### Default Export
|
|
48
|
+
|
|
49
|
+
The module exports a callable function with detection-based properties:
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
const ansi = require("@peteanderson/ansi");
|
|
53
|
+
const customAnsi = ansi(options); // returns configured instance
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### `fg` — foreground colors
|
|
57
|
+
|
|
58
|
+
Functions that wrap text with color codes (or plain text if disabled):
|
|
59
|
+
|
|
60
|
+
- Basic colors: `black` `red` `green` `yellow` `blue` `magenta` `cyan` `white` `default`
|
|
61
|
+
- Bright colors: `brightBlack` `brightRed` `brightGreen` `brightYellow` `brightBlue` `brightMagenta`
|
|
62
|
+
`brightCyan` `brightWhite`
|
|
63
|
+
- `fg.rgb(r, g, b)(text)` - 24-bit RGB color, downscaled for lower color depths
|
|
64
|
+
- `fg.x256(code)(text)` or `fg.x256(r, g, b)(text)` - 256-color palette, downscaled as needed
|
|
65
|
+
|
|
66
|
+
All return functions with `open` and `close` properties for raw sequences.
|
|
67
|
+
|
|
68
|
+
### `bg` — background colors
|
|
69
|
+
|
|
70
|
+
Functions that wrap text with color codes (or plain text if disabled):
|
|
71
|
+
|
|
72
|
+
- Basic colors: `black` `red` `green` `yellow` `blue` `magenta` `cyan` `white` `default`
|
|
73
|
+
- Bright colors: `brightBlack` `brightRed` `brightGreen` `brightYellow` `brightBlue` `brightMagenta`
|
|
74
|
+
`brightCyan` `brightWhite`
|
|
75
|
+
- `bg.rgb(r, g, b)(text)` - 24-bit RGB color, downscaled for lower color depths
|
|
76
|
+
- `bg.x256(code)(text)` or `bg.x256(r, g, b)(text)` - 256-color palette, downscaled as needed
|
|
77
|
+
|
|
78
|
+
### `style`
|
|
79
|
+
|
|
80
|
+
Functions that wrap text with style codes (disabled if color depth = 1):
|
|
81
|
+
|
|
82
|
+
`bold` `dim` `italic` `underline` `inverse` `hidden` `strikethrough` `doubleUnderline` `framed`
|
|
83
|
+
`encircled` `overline`
|
|
84
|
+
|
|
85
|
+
All return functions with `open` and `close` properties for raw sequences.
|
|
86
|
+
|
|
87
|
+
### `reset`
|
|
88
|
+
|
|
89
|
+
The SGR reset sequence. Empty string if color is disabled.
|
|
90
|
+
|
|
91
|
+
### `caret`
|
|
92
|
+
|
|
93
|
+
Available if feature is enabled:
|
|
94
|
+
|
|
95
|
+
- `caret.show` / `caret.hide` - show or hide the cursor
|
|
96
|
+
- `caret.position.get` - get the current cursor position (terminal sends position to stdin)
|
|
97
|
+
- `caret.position.set(row, col)` - set cursor position (1-based indexing)
|
|
98
|
+
- `caret.shape.block` / `caret.shape.underline` / `caret.shape.bar` - change cursor shape
|
|
99
|
+
- `caret.up(n)` / `caret.down(n)` / `caret.forward(n)` / `caret.backward(n)` - move cursor
|
|
100
|
+
- `caret.nextLine(n)` / `caret.prevLine(n)` - move cursor to next/previous line
|
|
101
|
+
- `caret.x(col)` - move cursor to column (1-based)
|
|
102
|
+
- `caret.save` / `caret.restore` - save/restore cursor position (VT100)
|
|
103
|
+
|
|
104
|
+
### `terminal`
|
|
105
|
+
|
|
106
|
+
Terminal control features (available if feature is enabled):
|
|
107
|
+
|
|
108
|
+
- `terminal.focusReporting.enable` / `terminal.focusReporting.disable` - enable/disable focus
|
|
109
|
+
reporting
|
|
110
|
+
- `terminal.alternateBuffer.on` / `terminal.alternateBuffer.off` - switch to/from alternate buffer
|
|
111
|
+
- `terminal.alternateBuffer.legacy.on` / `terminal.alternateBuffer.legacy.off` - use legacy
|
|
112
|
+
alternate buffer sequences
|
|
113
|
+
- `terminal.bracketedPasteMode.enable` / `terminal.bracketedPasteMode.disable` - enable/disable
|
|
114
|
+
bracketed paste mode
|
|
115
|
+
|
|
116
|
+
### `erase`
|
|
117
|
+
|
|
118
|
+
Available if feature is enabled:
|
|
119
|
+
|
|
120
|
+
- `erase.line.toStart` / `erase.line.toEnd` / `erase.line.full` - erase line
|
|
121
|
+
- `erase.screen.toStart` / `erase.screen.toEnd` / `erase.screen.full` - erase screen
|
|
122
|
+
- `erase.screen.scrollback` - erase screen and scrollback buffer
|
|
123
|
+
|
|
124
|
+
### `scroll`
|
|
125
|
+
|
|
126
|
+
Available if feature is enabled:
|
|
127
|
+
|
|
128
|
+
- `scroll.up(lines)` - scroll up (default 1 line)
|
|
129
|
+
- `scroll.down(lines)` - scroll down (default 1 line)
|
|
130
|
+
|
|
131
|
+
### `strip(text)`
|
|
132
|
+
|
|
133
|
+
Removes all ANSI CSI sequences from a string (always available).
|
|
134
|
+
|
|
135
|
+
### `slice(text, start, end)`
|
|
136
|
+
|
|
137
|
+
Slices a string by visible characters, ignoring ANSI sequences (always available).
|
|
138
|
+
|
|
139
|
+
### `sanitize(text)`
|
|
140
|
+
|
|
141
|
+
Removes "unsafe" CSI sequences, leaving only color and style codes (always available).
|
|
142
|
+
|
|
143
|
+
### `simplify(text)`
|
|
144
|
+
|
|
145
|
+
Simplifies ANSI SGR sequences by combining adjacent sequences and removing redundant codes (always
|
|
146
|
+
available).
|
|
147
|
+
|
|
148
|
+
### `visibleLength(text)`
|
|
149
|
+
|
|
150
|
+
Returns the visible length of a string with all ANSI sequences removed (always available).
|
|
151
|
+
|
|
152
|
+
### `padStart(text, targetLength)` and `padEnd(text, targetLength)`
|
|
153
|
+
|
|
154
|
+
Pads a string to a target visible length using spaces. Accounts for ANSI sequences when calculating
|
|
155
|
+
length.
|
|
156
|
+
|
|
157
|
+
### `features`
|
|
158
|
+
|
|
159
|
+
Object containing the detected feature configuration:
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
{
|
|
163
|
+
colorDepth : 1 | 3 | 4 | 8 | 24;
|
|
164
|
+
style : boolean;
|
|
165
|
+
caret : boolean;
|
|
166
|
+
erase : boolean;
|
|
167
|
+
scroll : boolean;
|
|
168
|
+
terminal : boolean;
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## License
|
|
173
|
+
|
|
174
|
+
MIT
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/features/build.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/features/build.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,UAAU,EAAE,QAAQ,EAAC,MAAM,SAAS,CAAC;AAWlD,wBAAgB,KAAK,CACpB,KAAK,EAAQ,OAAO,EACpB,UAAU,EAAG,UAAU,EACvB,KAAK,CAAC,EAAO,OAAO,EACpB,KAAK,CAAC,EAAO,OAAO,EACpB,KAAK,CAAC,EAAO,OAAO,EACpB,MAAM,CAAC,EAAM,OAAO,EACpB,QAAQ,CAAC,EAAI,OAAO,GAClB,QAAQ,CAmBV;AAED,eAAO,MAAM,OAAO,GAAI,OAAO,OAAO,EAAE,SAAS,OAAO,KAAG,QAC7B,CAAC;AAE/B,eAAO,MAAM,MAAM,GAAI,OAAO,OAAO,EAAE,YAAY,UAAU,KAAG,QACvC,CAAC;AAE1B,eAAO,MAAM,GAAG,GAAI,QAAQ,MAAM,CAAC,WAAW,KAAG,QACd,CAAC;AAEpC,eAAO,MAAM,IAAI,QAAO,QACM,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/features/build.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/features/build.ts"],"names":[],"mappings":";;;AAaA,sBA2BC;AAxCD,qCAA6D;AAI7D,SAAS,mBAAmB,CAAC,UAAkB;IAC9C,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACpC,IAAI,UAAU,IAAI,EAAE;QAAE,OAAO,EAAE,CAAC;IAChC,IAAI,UAAU,IAAI,CAAC;QAAG,OAAO,CAAC,CAAC;IAC/B,IAAI,UAAU,IAAI,CAAC;QAAG,OAAO,CAAC,CAAC;IAC/B,IAAI,UAAU,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,CAAC,CAAC;AACV,CAAC;AAED,SAAgB,KAAK,CACpB,KAAoB,EACpB,UAAuB,EACvB,KAAoB,EACpB,KAAoB,EACpB,KAAoB,EACpB,MAAoB,EACpB,QAAoB;IAEpB,IACC,KAAK,KAAQ,SAAS;QACtB,KAAK,KAAQ,SAAS;QACtB,KAAK,KAAQ,SAAS;QACtB,MAAM,KAAO,SAAS;QACtB,QAAQ,KAAK,SAAS;QAEtB,OAAO,EAAC,UAAU,EAAE,mBAAmB,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAC,CAAC;IAE7F,MAAM,OAAO,GAAG,IAAA,6BAAoB,EAAC,KAAK,EAAE,UAAU,CAAC,CAAC;IACxD,OAAO;QACN,UAAU,EAAG,mBAAmB,CAAC,UAAU,CAAC;QAC5C,KAAK,EAAQ,KAAK,IAAO,OAAO,CAAC,KAAK;QACtC,KAAK,EAAQ,KAAK,IAAO,OAAO,CAAC,KAAK;QACtC,KAAK,EAAQ,KAAK,IAAO,OAAO,CAAC,KAAK;QACtC,MAAM,EAAO,MAAM,IAAM,OAAO,CAAC,MAAM;QACvC,QAAQ,EAAK,QAAQ,IAAI,OAAO,CAAC,QAAQ;KACzC,CAAC;AACH,CAAC;AAEM,MAAM,OAAO,GAAG,CAAC,KAAc,EAAE,OAAgB,EAAY,EAAE,CACrE,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AADlB,QAAA,OAAO,WACW;AAExB,MAAM,MAAM,GAAG,CAAC,KAAc,EAAE,UAAsB,EAAY,EAAE,CAC1E,KAAK,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;AADb,QAAA,MAAM,UACO;AAEnB,MAAM,GAAG,GAAG,CAAC,MAA0B,EAAY,EAAE,CAC3D,KAAK,CAAC,IAAI,EAAE,IAAA,sBAAa,EAAC,MAAM,CAAC,CAAC,CAAC;AADvB,QAAA,GAAG,OACoB;AAE7B,MAAM,IAAI,GAAG,GAAa,EAAE,CAClC,KAAK,CAAC,KAAK,EAAE,IAAA,sBAAa,GAAE,CAAC,CAAC;AADlB,QAAA,IAAI,QACc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../../src/features/detect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../../src/features/detect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,UAAU,EAAE,QAAQ,EAAC,MAAM,SAAS,CAAC;AAElD,wBAAgB,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,WAAW,GAAG,UAAU,CAmBrE;AAED,wBAAgB,oBAAoB,CACnC,KAAK,EAAQ,OAAO,EACpB,UAAU,EAAG,UAAU,GACrB,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAC,CAS9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detect.js","sourceRoot":"","sources":["../../src/features/detect.ts"],"names":[],"mappings":";;AAEA,sCAmBC;AAED,
|
|
1
|
+
{"version":3,"file":"detect.js","sourceRoot":"","sources":["../../src/features/detect.ts"],"names":[],"mappings":";;AAEA,sCAmBC;AAED,oDAYC;AAjCD,SAAgB,aAAa,CAAC,MAA2B;IACxD,IAAI,MAAM,EAAE,KAAK;QAChB,OAAO,MAAM,CAAC,aAAa,EAAgB,CAAC;IAE7C,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,mBAAmB;QAC1D,OAAO,CAAC,CAAC;IAEV,QAAQ,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;QACjC,KAAK,EAAE,CAAC;QACR,KAAK,MAAM,CAAC;QACZ,KAAK,GAAG;YACP,OAAO,CAAC,CAAC;QACV,KAAK,GAAG;YACP,OAAO,CAAC,CAAC;QACV,KAAK,GAAG;YACP,OAAO,EAAE,CAAC;QACX;YACC,OAAO,CAAC,CAAC;IACX,CAAC;AACF,CAAC;AAED,SAAgB,oBAAoB,CACnC,KAAoB,EACpB,UAAuB;IAEvB,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,KAAK,MAAM,IAAI,KAAK,CAAC;IACrD,OAAO;QACN,KAAK,EAAM,UAAU,GAAG,CAAC;QACzB,KAAK,EAAM,OAAO;QAClB,KAAK,EAAM,OAAO;QAClB,MAAM,EAAK,OAAO;QAClB,QAAQ,EAAG,OAAO;KAClB,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features.d.ts","sourceRoot":"","sources":["../../src/features/features.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"features.d.ts","sourceRoot":"","sources":["../../src/features/features.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAiC,UAAU,CAAC;AAK3D,OAAO,KAAK,EAAC,UAAU,EAAE,QAAQ,EAAC,MAAM,SAAS,CAAC;AAElD,MAAM,MAAM,IAAI,GACb,CAAC,OAAO,EAAM,OAAO,EAAY,MAAM,CAAC,EAAE,MAAM,CAAC,WAAW,CAAC,GAC7D,CAAC,UAAU,EAAG,UAAU,EAAS,MAAM,CAAC,EAAE,MAAM,CAAC,WAAW,CAAC,GAC7D,CAAC,QAAQ,EAAK,OAAO,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,WAAW,CAAC,GAC7D,CAAC,MAAM,EAAO,MAAM,CAAC,GACrB,CAAC,MAAM,CAAC,EAAM,MAAM,CAAC,WAAW,CAAC,CAAC;AAErC,wBAAgB,WAAW,CAAC,GAAG,IAAI,EAAE,IAAI,GAAG,QAAQ,CA6BnD"}
|
|
@@ -6,20 +6,19 @@ const node_tty_1 = require("node:tty");
|
|
|
6
6
|
const build_1 = require("./build");
|
|
7
7
|
const detect_1 = require("./detect");
|
|
8
8
|
function getFeatures(...args) {
|
|
9
|
-
|
|
10
|
-
if (typeof
|
|
11
|
-
return (0, build_1.boolean)((
|
|
12
|
-
if (typeof
|
|
13
|
-
return (0, build_1.number)((
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (input instanceof node_net_1.Socket)
|
|
9
|
+
let [features, stream] = args;
|
|
10
|
+
if (typeof features === "boolean")
|
|
11
|
+
return (0, build_1.boolean)((stream ?? process.stdout).isTTY, features);
|
|
12
|
+
if (typeof features === "number")
|
|
13
|
+
return (0, build_1.number)((stream ?? process.stdout).isTTY, features);
|
|
14
|
+
if (!features || typeof features !== "object")
|
|
15
|
+
features = (stream ?? process.stdout);
|
|
16
|
+
if (features instanceof node_tty_1.WriteStream)
|
|
17
|
+
return (0, build_1.tty)(features);
|
|
18
|
+
if (features instanceof node_net_1.Socket)
|
|
20
19
|
return (0, build_1.pipe)();
|
|
21
|
-
const { colorDepth, style, caret, erase, scroll, terminal } =
|
|
22
|
-
|
|
20
|
+
const { colorDepth, style, caret, erase, scroll, terminal } = features;
|
|
21
|
+
stream ?? (stream = process.stdout);
|
|
23
22
|
if (colorDepth)
|
|
24
23
|
(0, build_1.build)(stream.isTTY, colorDepth, style, caret, erase, scroll, terminal);
|
|
25
24
|
if (stream.isTTY)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features.js","sourceRoot":"","sources":["../../src/features/features.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"features.js","sourceRoot":"","sources":["../../src/features/features.ts"],"names":[],"mappings":";;AAcA,kCA6BC;AA3CD,uCAA2D;AAC3D,uCAA2D;AAC3D,mCAA0D;AAC1D,qCAA2D;AAW3D,SAAgB,WAAW,CAAC,GAAG,IAAU;IACxC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;IAE9B,IAAI,OAAO,QAAQ,KAAK,SAAS;QAChC,OAAO,IAAA,eAAO,EAAC,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAE5D,IAAI,OAAO,QAAQ,KAAK,QAAQ;QAC/B,OAAO,IAAA,cAAM,EAAC,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAE3D,IAAI,CAAC,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ;QAC5C,QAAQ,GAAG,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAEvC,IAAI,QAAQ,YAAY,sBAAW;QAClC,OAAO,IAAA,WAAG,EAAC,QAAQ,CAAC,CAAC;IAEtB,IAAI,QAAQ,YAAY,iBAAM;QAC7B,OAAO,IAAA,YAAI,GAAE,CAAC;IAEf,MAAM,EAAC,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAC,GAAG,QAAQ,CAAC;IAErE,MAAM,KAAN,MAAM,GAAK,OAAO,CAAC,MAAM,EAAC;IAE1B,IAAI,UAAU;QACb,IAAA,aAAK,EAAC,MAAM,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IAExE,IAAI,MAAM,CAAC,KAAK;QACf,OAAO,IAAA,aAAK,EAAC,IAAI,EAAE,IAAA,sBAAa,EAAC,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IAElF,OAAO,IAAA,aAAK,EAAC,KAAK,EAAE,IAAA,sBAAa,GAAE,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;AAC7E,CAAC"}
|
package/dist/pad.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pad the given text at the end with the specified fill string to the target visible length without
|
|
3
|
+
* counting ANSI escape codes.
|
|
4
|
+
*/
|
|
1
5
|
export declare const padEnd: (text: string, targetLength: number, fillString?: string) => string;
|
|
6
|
+
/**
|
|
7
|
+
* Pad the given text at the start with the specified fill string to the target visible length
|
|
8
|
+
* without counting ANSI escape codes.
|
|
9
|
+
*/
|
|
2
10
|
export declare const padStart: (text: string, targetLength: number, fillString?: string) => string;
|
|
3
11
|
//# sourceMappingURL=pad.d.ts.map
|
package/dist/pad.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pad.d.ts","sourceRoot":"","sources":["../src/pad.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM,GAAI,MAAM,MAAM,EAAE,cAAc,MAAM,EAAE,mBAAgB,KAAG,MACgB,CAAC;AAE/F,eAAO,MAAM,QAAQ,GAAI,MAAM,MAAM,EAAE,cAAc,MAAM,EAAE,mBAAgB,KAAG,MACc,CAAC"}
|
|
1
|
+
{"version":3,"file":"pad.d.ts","sourceRoot":"","sources":["../src/pad.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,MAAM,GAAI,MAAM,MAAM,EAAE,cAAc,MAAM,EAAE,mBAAgB,KAAG,MACgB,CAAC;AAE/F;;;GAGG;AACH,eAAO,MAAM,QAAQ,GAAI,MAAM,MAAM,EAAE,cAAc,MAAM,EAAE,mBAAgB,KAAG,MACc,CAAC"}
|
package/dist/pad.js
CHANGED
|
@@ -2,8 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.padStart = exports.padEnd = void 0;
|
|
4
4
|
const strip_1 = require("./strip");
|
|
5
|
+
/**
|
|
6
|
+
* Pad the given text at the end with the specified fill string to the target visible length without
|
|
7
|
+
* counting ANSI escape codes.
|
|
8
|
+
*/
|
|
5
9
|
const padEnd = (text, targetLength, fillString = " ") => text + fillString.repeat(Math.max(0, targetLength - (0, strip_1.visibleLength)(text)) / fillString.length);
|
|
6
10
|
exports.padEnd = padEnd;
|
|
11
|
+
/**
|
|
12
|
+
* Pad the given text at the start with the specified fill string to the target visible length
|
|
13
|
+
* without counting ANSI escape codes.
|
|
14
|
+
*/
|
|
7
15
|
const padStart = (text, targetLength, fillString = " ") => fillString.repeat(Math.max(0, targetLength - (0, strip_1.visibleLength)(text)) / fillString.length) + text;
|
|
8
16
|
exports.padStart = padStart;
|
|
9
17
|
//# sourceMappingURL=pad.js.map
|
package/dist/pad.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pad.js","sourceRoot":"","sources":["../src/pad.ts"],"names":[],"mappings":";;;AAAA,mCAAsC;
|
|
1
|
+
{"version":3,"file":"pad.js","sourceRoot":"","sources":["../src/pad.ts"],"names":[],"mappings":";;;AAAA,mCAAsC;AAEtC;;;GAGG;AACI,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,YAAoB,EAAE,UAAU,GAAG,GAAG,EAAU,EAAE,CACtF,IAAI,GAAG,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,GAAG,IAAA,qBAAa,EAAC,IAAI,CAAC,CAAC,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;AADlF,QAAA,MAAM,UAC4E;AAE/F;;;GAGG;AACI,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,YAAoB,EAAE,UAAU,GAAG,GAAG,EAAU,EAAE,CACxF,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,GAAG,IAAA,qBAAa,EAAC,IAAI,CAAC,CAAC,GAAG,UAAU,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;AADlF,QAAA,QAAQ,YAC0E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/sgr/color/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/sgr/color/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAajE;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAYhE;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAgBhE;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAM/D;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;AACxC,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC"}
|
package/dist/sgr/color/utils.js
CHANGED
|
@@ -6,8 +6,11 @@ exports.rgbToX16 = rgbToX16;
|
|
|
6
6
|
exports.rgbToX8 = rgbToX8;
|
|
7
7
|
exports.clip = clip;
|
|
8
8
|
function rgbToX256(r, g, b) {
|
|
9
|
-
if (r === g && g === b)
|
|
9
|
+
if (r === g && g === b) {
|
|
10
|
+
// grayscale
|
|
10
11
|
return 232 + Math.floor(r * 24 / 256);
|
|
12
|
+
}
|
|
13
|
+
// 6x6x6 color cube
|
|
11
14
|
return (16 +
|
|
12
15
|
Math.floor(r * 6 / 256) * 36 +
|
|
13
16
|
Math.floor(g * 6 / 256) * 6 +
|
|
@@ -15,6 +18,7 @@ function rgbToX256(r, g, b) {
|
|
|
15
18
|
}
|
|
16
19
|
function x256ToRgb(code) {
|
|
17
20
|
if (code >= 232) {
|
|
21
|
+
// grayscale
|
|
18
22
|
const gray = Math.round((code - 232) * 255 / 24);
|
|
19
23
|
return [gray, gray, gray];
|
|
20
24
|
}
|
|
@@ -25,13 +29,17 @@ function x256ToRgb(code) {
|
|
|
25
29
|
return [r, g, b];
|
|
26
30
|
}
|
|
27
31
|
function rgbToX16(r, g, b) {
|
|
32
|
+
// First calculate it as a 4x4x4 cube.
|
|
28
33
|
r = Math.min(2, Math.floor(r / 85));
|
|
29
34
|
g = Math.min(2, Math.floor(g / 85));
|
|
30
35
|
b = Math.min(2, Math.floor(b / 85));
|
|
36
|
+
// Which channels are "on" determines the hue (ANSI color index 0–7).
|
|
31
37
|
const index = (r ? 1 : 0) | (g ? 2 : 0) | (b ? 4 : 0);
|
|
38
|
+
// The bright bit is derived from the max channel level across all three.
|
|
32
39
|
const twos = (r === 2 ? 1 : 0) + (g === 2 ? 1 : 0) + (b === 2 ? 1 : 0);
|
|
33
40
|
const ones = (r === 1 ? 1 : 0) + (g === 1 ? 1 : 0) + (b === 1 ? 1 : 0);
|
|
34
41
|
const bright = twos > 0 && twos >= ones;
|
|
42
|
+
// Return value uses the SGR offset scheme: 0–7 for normal, 60–67 for bright.
|
|
35
43
|
return index + (bright ? 60 : 0);
|
|
36
44
|
}
|
|
37
45
|
function rgbToX8(r, g, b) {
|
|
@@ -41,9 +49,9 @@ function rgbToX8(r, g, b) {
|
|
|
41
49
|
return (r ? 1 : 0) | (g ? 2 : 0) | (b ? 4 : 0);
|
|
42
50
|
}
|
|
43
51
|
function clip(...args) {
|
|
44
|
-
return args.length === 1
|
|
45
|
-
|
|
46
|
-
|
|
52
|
+
return args.length === 1 ?
|
|
53
|
+
Math.max(0, Math.min(255, Math.floor(args[0]))) :
|
|
54
|
+
[
|
|
47
55
|
Math.max(0, Math.min(255, Math.floor(args[0]))),
|
|
48
56
|
Math.max(0, Math.min(255, Math.floor(args[1]))),
|
|
49
57
|
Math.max(0, Math.min(255, Math.floor(args[2]))),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/sgr/color/utils.ts"],"names":[],"mappings":";;AAAA,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/sgr/color/utils.ts"],"names":[],"mappings":";;AAAA,8BAaC;AAED,8BAYC;AAED,4BAgBC;AAED,0BAMC;AAID,oBAUC;AAnED,SAAgB,SAAS,CA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C,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SAC/C,CAAC;AACJ,CAAC"}
|
package/dist/sgr/sgr.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sgr.d.ts","sourceRoot":"","sources":["../../src/sgr/sgr.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC;AAErC,MAAM,WAAW,GAAG;IACnB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,IAAI,EAAM,MAAM,CAAC;IACjB,KAAK,EAAK,MAAM,CAAC;IACjB,KAAK,EAAK;QAAC,IAAI,EAAE,IAAI,CAAC;QAAC,KAAK,EAAE,IAAI,CAAA;KAAC,CAAC;IACpC,OAAO,EAAG,CAAC,GAAG,MAAM,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;CACpC;
|
|
1
|
+
{"version":3,"file":"sgr.d.ts","sourceRoot":"","sources":["../../src/sgr/sgr.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC;AAErC,MAAM,WAAW,GAAG;IACnB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,IAAI,EAAM,MAAM,CAAC;IACjB,KAAK,EAAK,MAAM,CAAC;IACjB,KAAK,EAAK;QAAC,IAAI,EAAE,IAAI,CAAC;QAAC,KAAK,EAAE,IAAI,CAAA;KAAC,CAAC;IACpC,OAAO,EAAG,CAAC,GAAG,MAAM,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;CACpC;AAqBD,iBAAS,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,UAAQ,GAAG,GAAG,CAwBxD;AAWD,eAAO,MAAM,OAAO,GAAI,iBAAc,KAAG,OAAO,GAA+B,CAAC"}
|
package/dist/sgr/sgr.js
CHANGED
|
@@ -4,14 +4,16 @@ exports.makeSGR = void 0;
|
|
|
4
4
|
function combine(code, codes) {
|
|
5
5
|
if (!codes.length)
|
|
6
6
|
return code;
|
|
7
|
-
const
|
|
7
|
+
const set = new Set(Array.isArray(code) ? [...code] : [code]);
|
|
8
8
|
for (const c of codes) {
|
|
9
|
-
if (Array.isArray(c))
|
|
10
|
-
|
|
9
|
+
if (Array.isArray(c)) {
|
|
10
|
+
for (const code of c)
|
|
11
|
+
set.add(code);
|
|
12
|
+
}
|
|
11
13
|
else
|
|
12
|
-
|
|
14
|
+
set.add(c);
|
|
13
15
|
}
|
|
14
|
-
return
|
|
16
|
+
return Array.from(set);
|
|
15
17
|
}
|
|
16
18
|
const codeSequence = (code) => Array.isArray(code) ? code.join(";") : code;
|
|
17
19
|
function sgr(open, close, reset = false) {
|
|
@@ -30,8 +32,7 @@ function sgr(open, close, reset = false) {
|
|
|
30
32
|
combine: (...styles) => sgr(combine(open, styles.map(s => s.codes.open)), combine(close, styles.map(s => s.codes.close))),
|
|
31
33
|
});
|
|
32
34
|
}
|
|
33
|
-
|
|
34
|
-
disabledSGR = Object.assign((s) => s, {
|
|
35
|
+
const disabledSGR = Object.assign((s) => s, {
|
|
35
36
|
codes: { open: 0, close: 0 },
|
|
36
37
|
open: "",
|
|
37
38
|
close: "",
|
package/dist/sgr/sgr.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sgr.js","sourceRoot":"","sources":["../../src/sgr/sgr.ts"],"names":[],"mappings":";;;AAUA,SAAS,OAAO,CAAC,IAAU,EAAE,KAAa;IACzC,IAAI,CAAC,KAAK,CAAC,MAAM;QAChB,OAAO,IAAI,CAAC;IAEb,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAA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IAAI,EAAc,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC;AAAnE,QAAA,OAAO,WAA4D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atom.d.ts","sourceRoot":"","sources":["../../src/simplify/atom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"atom.d.ts","sourceRoot":"","sources":["../../src/simplify/atom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,SAAS,CAAC;AAEvC,eAAO,MAAM,sBAAsB,EAAE,SAapC,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,SAoBhC,CAAC"}
|
package/dist/simplify/atom.js
CHANGED
|
@@ -21,10 +21,17 @@ const buildIntensityAtom = (attribute, codes, index, state) => {
|
|
|
21
21
|
if (code === 22)
|
|
22
22
|
return { attribute, code: [code] };
|
|
23
23
|
const current = state.get("intensity");
|
|
24
|
-
if (
|
|
24
|
+
if (
|
|
25
|
+
// If there is no intensity currently in the state, then we can just set the new state.
|
|
26
|
+
!current ||
|
|
27
|
+
// If the current intensity is normal (22), then we can just set the new state.
|
|
28
|
+
// Note that while the ultimate transition may return a code sequence of `[22, 1]` or
|
|
29
|
+
// `[22, 2]`, in our state representation, the only two-code intensity is `[1, 2]`.
|
|
25
30
|
current[0] === 22 ||
|
|
31
|
+
// If the current intensity is equal to the new intensity, then return the same state.
|
|
26
32
|
current.length === 1 && current[0] === code)
|
|
27
33
|
return { attribute, code: [code] };
|
|
34
|
+
// Otherwise, we need to set both intensity codes.
|
|
28
35
|
return { attribute, code: [1, 2] };
|
|
29
36
|
};
|
|
30
37
|
exports.buildIntensityAtom = buildIntensityAtom;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atom.js","sourceRoot":"","sources":["../../src/simplify/atom.ts"],"names":[],"mappings":";;;AAEO,MAAM,sBAAsB,GAAc,CA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B,0BAajC;AAEK,MAAM,kBAAkB,GAAc,CAAC,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;IAC/E,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;IAC1B,IAAI,IAAI,KAAK,EAAE;QACd,OAAO,EAAC,SAAS,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,EAAC,CAAC;IAElC,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACvC;IACC,uFAAuF;IACvF,CAAC,OAAO;QACR,+EAA+E;QAC/E,qFAAqF;QACrF,mFAAmF;QACnF,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE;QACjB,sFAAsF;QACtF,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,IAAI;QAE3C,OAAO,EAAC,SAAS,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,EAAC,CAAC;IAElC,kDAAkD;IAClD,OAAO,EAAC,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAC,CAAC;AAClC,CAAC,CAAC;AApBW,QAAA,kBAAkB,sBAoB7B"}
|
package/dist/slice.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slice.d.ts","sourceRoot":"","sources":["../src/slice.ts"],"names":[],"mappings":"AAqCA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"slice.d.ts","sourceRoot":"","sources":["../src/slice.ts"],"names":[],"mappings":"AAqCA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CA6BtE"}
|
package/dist/slice.js
CHANGED
|
@@ -64,6 +64,7 @@ function slice(text, start, end) {
|
|
|
64
64
|
const endIndex = startIndex < text.length && visibleSkipped < end
|
|
65
65
|
? scanCSI(text, startIndex, end - visibleSkipped).index
|
|
66
66
|
: text.length;
|
|
67
|
+
// Start and end the string in the same terminal state it would be in if the string weren't sliced.
|
|
67
68
|
const leadingSequences = skippedSequences(text, 0, startIndex);
|
|
68
69
|
const trailingSequences = skippedSequences(text, endIndex);
|
|
69
70
|
return leadingSequences + text.slice(startIndex, endIndex) + trailingSequences;
|
package/dist/slice.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slice.js","sourceRoot":"","sources":["../src/slice.ts"],"names":[],"mappings":";;AAwDA,
|
|
1
|
+
{"version":3,"file":"slice.js","sourceRoot":"","sources":["../src/slice.ts"],"names":[],"mappings":";;AAwDA,sBA6BC;AArFD,yCAAyC;AACzC,yCAAyC;AACzC,mCAAsC;AAEtC,SAAS,OAAO,CACf,IAAwB,EACxB,eAAwB,EACxB,YAAwB;IAExB,gEAAgE;IAChE,MAAM,EAAE,GAAG,IAAI,MAAM,CAAC,gBAAK,CAAC,CAAC;IAE7B,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,IAAI,KAAK,GAAI,eAAe,CAAC;IAE7B,OAAO,KAAK,GAAG,IAAI,CAAC,MAAM,IAAI,MAAM,GAAG,YAAY,EAAE,CAAC;QACrD,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,MAAM,EAAE,CAAC;YAC5B,EAAE,CAAC,SAAS,GAAG,KAAK,CAAC;YACrB,MAAM,KAAK,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC5B,IAAI,KAAK,EAAE,KAAK,KAAK,KAAK,EAAE,CAAC;gBAC5B,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;gBACzB,SAAS;YACV,CAAC;QACF,CAAC;QAED,KAAK,EA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AAE,UAAU,EAAE,MAAM,EAAE,cAAc,EAAC,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;IAE5E,MAAM,QAAQ,GACb,UAAU,GAAG,IAAI,CAAC,MAAM,IAAI,cAAc,GAAG,GAAG;QAC/C,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,GAAG,cAAc,CAAC,CAAC,KAAK;QACvD,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;IAEhB,mGAAmG;IACnG,MAAM,gBAAgB,GAAI,gBAAgB,CAAC,IAAI,EAAE,CAAC,EAAE,UAAU,CAAC,CAAC;IAChE,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAE3D,OAAO,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,QAAQ,CAAC,GAAG,iBAAiB,CAAC;AAChF,CAAC"}
|
package/dist/strip.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
/** Remove all ANSI escape codes from the given text. */
|
|
1
2
|
export declare const strip: (text: string) => string;
|
|
3
|
+
/** Calculate the visible length of a string with ANSI escape codes stripped. */
|
|
2
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. */
|
|
3
6
|
export declare const sanitize: (text: string) => string;
|
|
4
7
|
//# sourceMappingURL=strip.d.ts.map
|
package/dist/strip.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strip.d.ts","sourceRoot":"","sources":["../src/strip.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,KAAK,GAAY,MAAM,MAAM,KAAG,MAA6C,CAAC;
|
|
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
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sanitize = exports.visibleLength = exports.strip = void 0;
|
|
4
4
|
const patterns_1 = require("./patterns");
|
|
5
|
+
/** Remove all ANSI escape codes from the given text. */
|
|
5
6
|
const strip = (text) => text.replace(new RegExp(patterns_1.rxCSI), "");
|
|
6
7
|
exports.strip = strip;
|
|
8
|
+
/** Calculate the visible length of a string with ANSI escape codes stripped. */
|
|
7
9
|
const visibleLength = (text) => (0, exports.strip)(text).length;
|
|
8
10
|
exports.visibleLength = visibleLength;
|
|
11
|
+
/** Remove all ANSI escape codes except SGR codes (m), which are used for color and styling. */
|
|
9
12
|
const sanitize = (text) => text.replace(new RegExp(patterns_1.rxUnsafe), "");
|
|
10
13
|
exports.sanitize = sanitize;
|
|
11
14
|
//# sourceMappingURL=strip.js.map
|
package/dist/strip.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strip.js","sourceRoot":"","sources":["../src/strip.ts"],"names":[],"mappings":";;;AAAA,yCAA2C;
|
|
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/package.json
CHANGED
|
@@ -1,22 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name" : "@peteanderson/ansi",
|
|
3
|
-
"version" : "1.0.
|
|
3
|
+
"version" : "1.0.1",
|
|
4
4
|
"description" : "ANSI escape sequence generation with automatic feature detection",
|
|
5
|
+
"author" : {
|
|
6
|
+
"name" : "Pete Anderson",
|
|
7
|
+
"email" : "pete.the.anderson@gmail.com"
|
|
8
|
+
},
|
|
9
|
+
"repository" : {
|
|
10
|
+
"type" : "git",
|
|
11
|
+
"url" : "git+https://github.com/anderson-pete/ansi.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords" : ["ansi", "nodejs", "color", "terminal", "cli"],
|
|
14
|
+
"engines" : {"node": ">=18"},
|
|
5
15
|
"files" : ["dist", "src"],
|
|
6
|
-
"exports" : {
|
|
7
|
-
".": {
|
|
8
|
-
"require" : "./dist/index.js",
|
|
9
|
-
"types" : "./dist/index.d.ts"
|
|
10
|
-
}},
|
|
11
16
|
"main" : "dist/index.js",
|
|
12
17
|
"types" : "dist/index.d.ts",
|
|
13
|
-
"
|
|
18
|
+
"exports" : {
|
|
19
|
+
".": {
|
|
20
|
+
"types" : "./dist/index.d.ts",
|
|
21
|
+
"require" : "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"license" : "MIT",
|
|
14
25
|
"scripts" : {
|
|
15
|
-
"
|
|
16
|
-
"build
|
|
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",
|
|
30
|
+
"tag-all" : "tsx --tsconfig scripts/tsconfig.json scripts/tag-all.ts"
|
|
17
31
|
},
|
|
18
32
|
"devDependencies" : {
|
|
19
33
|
"@types/node" : "^26.0.0",
|
|
34
|
+
"tsx" : "^4.22.4",
|
|
20
35
|
"typescript" : "^6.0.3"
|
|
21
36
|
}
|
|
22
37
|
}
|
package/src/features/build.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { getColorDepth
|
|
2
|
-
|
|
1
|
+
import {detectFeatureSupport, getColorDepth} from "./detect";
|
|
2
|
+
|
|
3
|
+
import type {ColorDepth, Features} from "./types";
|
|
3
4
|
|
|
4
5
|
function normalizeColorDepth(colorDepth: number): ColorDepth {
|
|
5
6
|
colorDepth = Math.floor(colorDepth);
|
|
@@ -49,4 +50,4 @@ export const tty = (stream: NodeJS.WriteStream): Features =>
|
|
|
49
50
|
build(true, getColorDepth(stream));
|
|
50
51
|
|
|
51
52
|
export const pipe = (): Features =>
|
|
52
|
-
build(false, getColorDepth());
|
|
53
|
+
build(false, getColorDepth());
|
package/src/features/detect.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {ColorDepth, Features} from "./types";
|
|
2
2
|
|
|
3
3
|
export function getColorDepth(stream?: NodeJS.WriteStream): ColorDepth {
|
|
4
4
|
if (stream?.isTTY)
|
|
@@ -21,7 +21,10 @@ export function getColorDepth(stream?: NodeJS.WriteStream): ColorDepth {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export function detectFeatureSupport(
|
|
24
|
+
export function detectFeatureSupport(
|
|
25
|
+
isTTY : boolean,
|
|
26
|
+
colorDepth : ColorDepth,
|
|
27
|
+
): Omit<Features, "colorDepth"> {
|
|
25
28
|
const enabled = process.env.TERM !== "dumb" && isTTY;
|
|
26
29
|
return {
|
|
27
30
|
style : colorDepth > 1,
|
|
@@ -30,4 +33,4 @@ export function detectFeatureSupport(isTTY: boolean, colorDepth: ColorDepth): Om
|
|
|
30
33
|
scroll : enabled,
|
|
31
34
|
terminal : enabled,
|
|
32
35
|
};
|
|
33
|
-
}
|
|
36
|
+
}
|
package/src/features/features.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { build,
|
|
4
|
-
import {
|
|
5
|
-
|
|
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";
|
|
5
|
+
|
|
6
|
+
import type {ColorDepth, Features} from "./types";
|
|
6
7
|
|
|
7
8
|
export type Args =
|
|
8
9
|
| [enabled : boolean, stream?: NodeJS.WriteStream]
|
|
@@ -12,31 +13,26 @@ export type Args =
|
|
|
12
13
|
| [stream? : NodeJS.WriteStream];
|
|
13
14
|
|
|
14
15
|
export function getFeatures(...args: Args): Features {
|
|
15
|
-
|
|
16
|
-
boolean | ColorDepth | Partial<Features> | Socket | NodeJS.WriteStream | undefined,
|
|
17
|
-
NodeJS.WriteStream | undefined,
|
|
18
|
-
];
|
|
16
|
+
let [features, stream] = args;
|
|
19
17
|
|
|
20
|
-
if (typeof
|
|
21
|
-
return boolean((
|
|
18
|
+
if (typeof features === "boolean")
|
|
19
|
+
return boolean((stream ?? process.stdout).isTTY, features);
|
|
22
20
|
|
|
23
|
-
if (typeof
|
|
24
|
-
return number((
|
|
21
|
+
if (typeof features === "number")
|
|
22
|
+
return number((stream ?? process.stdout).isTTY, features);
|
|
25
23
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
? second ?? process.stdout
|
|
29
|
-
: first;
|
|
24
|
+
if (!features || typeof features !== "object")
|
|
25
|
+
features = (stream ?? process.stdout);
|
|
30
26
|
|
|
31
|
-
if (
|
|
32
|
-
return tty(
|
|
27
|
+
if (features instanceof WriteStream)
|
|
28
|
+
return tty(features);
|
|
33
29
|
|
|
34
|
-
if (
|
|
30
|
+
if (features instanceof Socket)
|
|
35
31
|
return pipe();
|
|
36
32
|
|
|
37
|
-
const {colorDepth, style, caret, erase, scroll, terminal} =
|
|
33
|
+
const {colorDepth, style, caret, erase, scroll, terminal} = features;
|
|
38
34
|
|
|
39
|
-
|
|
35
|
+
stream ??= process.stdout;
|
|
40
36
|
|
|
41
37
|
if (colorDepth)
|
|
42
38
|
build(stream.isTTY, colorDepth, style, caret, erase, scroll, terminal);
|
|
@@ -45,4 +41,4 @@ export function getFeatures(...args: Args): Features {
|
|
|
45
41
|
return build(true, getColorDepth(stream), style, caret, erase, scroll, terminal);
|
|
46
42
|
|
|
47
43
|
return build(false, getColorDepth(), style, caret, erase, scroll, terminal);
|
|
48
|
-
}
|
|
44
|
+
}
|
package/src/features/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./features";
|
|
1
|
+
export * from "./features";
|
package/src/features/types.ts
CHANGED
package/src/pad.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import {visibleLength} from "./strip";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Pad the given text at the end with the specified fill string to the target visible length without
|
|
5
|
+
* counting ANSI escape codes.
|
|
6
|
+
*/
|
|
3
7
|
export const padEnd = (text: string, targetLength: number, fillString = " "): string =>
|
|
4
8
|
text + fillString.repeat(Math.max(0, targetLength - visibleLength(text)) / fillString.length);
|
|
5
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Pad the given text at the start with the specified fill string to the target visible length
|
|
12
|
+
* without counting ANSI escape codes.
|
|
13
|
+
*/
|
|
6
14
|
export const padStart = (text: string, targetLength: number, fillString = " "): string =>
|
|
7
15
|
fillString.repeat(Math.max(0, targetLength - visibleLength(text)) / fillString.length) + text;
|
package/src/sgr/color/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./color";
|
|
1
|
+
export * from "./color";
|
package/src/sgr/color/utils.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export function rgbToX256(r: number, g: number, b: number): number {
|
|
2
|
-
if (r === g && g === b)
|
|
2
|
+
if (r === g && g === b) {
|
|
3
|
+
// grayscale
|
|
3
4
|
return 232 + Math.floor(r * 24 / 256);
|
|
5
|
+
}
|
|
4
6
|
|
|
7
|
+
// 6x6x6 color cube
|
|
5
8
|
return (
|
|
6
9
|
16 +
|
|
7
10
|
Math.floor(r * 6 / 256) * 36 +
|
|
@@ -12,6 +15,7 @@ export function rgbToX256(r: number, g: number, b: number): number {
|
|
|
12
15
|
|
|
13
16
|
export function x256ToRgb(code: number): [number, number, number] {
|
|
14
17
|
if (code >= 232) {
|
|
18
|
+
// grayscale
|
|
15
19
|
const gray = Math.round((code - 232) * 255 / 24);
|
|
16
20
|
return [gray, gray, gray];
|
|
17
21
|
}
|
|
@@ -24,16 +28,20 @@ export function x256ToRgb(code: number): [number, number, number] {
|
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
export function rgbToX16(r: number, g: number, b: number): number {
|
|
31
|
+
// First calculate it as a 4x4x4 cube.
|
|
27
32
|
r = Math.min(2, Math.floor(r / 85));
|
|
28
33
|
g = Math.min(2, Math.floor(g / 85));
|
|
29
34
|
b = Math.min(2, Math.floor(b / 85));
|
|
30
35
|
|
|
36
|
+
// Which channels are "on" determines the hue (ANSI color index 0–7).
|
|
31
37
|
const index = (r ? 1 : 0) | (g ? 2 : 0) | (b ? 4 : 0);
|
|
32
38
|
|
|
39
|
+
// The bright bit is derived from the max channel level across all three.
|
|
33
40
|
const twos = (r === 2 ? 1 : 0) + (g === 2 ? 1 : 0) + (b === 2 ? 1 : 0);
|
|
34
41
|
const ones = (r === 1 ? 1 : 0) + (g === 1 ? 1 : 0) + (b === 1 ? 1 : 0);
|
|
35
42
|
const bright = twos > 0 && twos >= ones;
|
|
36
43
|
|
|
44
|
+
// Return value uses the SGR offset scheme: 0–7 for normal, 60–67 for bright.
|
|
37
45
|
return index + (bright ? 60 : 0);
|
|
38
46
|
}
|
|
39
47
|
|
|
@@ -47,10 +55,12 @@ export function rgbToX8(r: number, g: number, b: number): number {
|
|
|
47
55
|
|
|
48
56
|
export function clip(x: number): number;
|
|
49
57
|
export function clip(r: number, g: number, b: number): [number, number, number];
|
|
50
|
-
export function clip(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
58
|
+
export function clip(
|
|
59
|
+
...args: [number] | [number, number, number]
|
|
60
|
+
): number | [number, number, number] {
|
|
61
|
+
return args.length === 1 ?
|
|
62
|
+
Math.max(0, Math.min(255, Math.floor(args[0]))) :
|
|
63
|
+
[
|
|
54
64
|
Math.max(0, Math.min(255, Math.floor(args[0]))),
|
|
55
65
|
Math.max(0, Math.min(255, Math.floor(args[1]))),
|
|
56
66
|
Math.max(0, Math.min(255, Math.floor(args[2]))),
|
package/src/sgr/sgr.ts
CHANGED
|
@@ -12,16 +12,17 @@ function combine(code: Code, codes: Code[]): Code {
|
|
|
12
12
|
if (!codes.length)
|
|
13
13
|
return code;
|
|
14
14
|
|
|
15
|
-
const
|
|
15
|
+
const set = new Set(Array.isArray(code) ? [...code] : [code]);
|
|
16
16
|
|
|
17
17
|
for (const c of codes) {
|
|
18
|
-
if (Array.isArray(c))
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
if (Array.isArray(c)) {
|
|
19
|
+
for (const code of c)
|
|
20
|
+
set.add(code);
|
|
21
|
+
} else
|
|
22
|
+
set.add(c);
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
return
|
|
25
|
+
return Array.from(set);
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
const codeSequence = (code: Code): string | number => Array.isArray(code) ? code.join(";") : code;
|
|
@@ -52,17 +53,13 @@ function sgr(open: Code, close: Code, reset = false): SGR {
|
|
|
52
53
|
});
|
|
53
54
|
}
|
|
54
55
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
close : "",
|
|
62
|
-
combine : (): SGR => disabledSGR,
|
|
63
|
-
},
|
|
64
|
-
);
|
|
56
|
+
const disabledSGR: SGR = Object.assign((s: string) => s, {
|
|
57
|
+
codes : {open: 0, close: 0},
|
|
58
|
+
open : "",
|
|
59
|
+
close : "",
|
|
60
|
+
combine : (): SGR => disabledSGR,
|
|
61
|
+
});
|
|
65
62
|
|
|
66
|
-
const disabled = ()
|
|
63
|
+
const disabled: typeof sgr = () => disabledSGR;
|
|
67
64
|
|
|
68
65
|
export const makeSGR = (enabled = true): typeof sgr => enabled ? sgr : disabled;
|
package/src/simplify/atom.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {BuildAtom} from "./types";
|
|
2
2
|
|
|
3
3
|
export const buildExtendedColorAtom: BuildAtom = (attribute, codes, index) => {
|
|
4
4
|
switch (codes[index + 1]) {
|
|
@@ -20,13 +20,19 @@ export const buildIntensityAtom: BuildAtom = (attribute, codes, index, state) =>
|
|
|
20
20
|
if (code === 22)
|
|
21
21
|
return {attribute, code: [code]};
|
|
22
22
|
|
|
23
|
-
const current = state.get("intensity"
|
|
23
|
+
const current = state.get("intensity");
|
|
24
24
|
if (
|
|
25
|
+
// If there is no intensity currently in the state, then we can just set the new state.
|
|
25
26
|
!current ||
|
|
27
|
+
// If the current intensity is normal (22), then we can just set the new state.
|
|
28
|
+
// Note that while the ultimate transition may return a code sequence of `[22, 1]` or
|
|
29
|
+
// `[22, 2]`, in our state representation, the only two-code intensity is `[1, 2]`.
|
|
26
30
|
current[0] === 22 ||
|
|
31
|
+
// If the current intensity is equal to the new intensity, then return the same state.
|
|
27
32
|
current.length === 1 && current[0] === code
|
|
28
33
|
)
|
|
29
34
|
return {attribute, code: [code]};
|
|
30
35
|
|
|
36
|
+
// Otherwise, we need to set both intensity codes.
|
|
31
37
|
return {attribute, code: [1, 2]};
|
|
32
38
|
};
|
package/src/slice.ts
CHANGED
|
@@ -78,6 +78,7 @@ export function slice(text: string, start: number, end: number): string {
|
|
|
78
78
|
? scanCSI(text, startIndex, end - visibleSkipped).index
|
|
79
79
|
: text.length;
|
|
80
80
|
|
|
81
|
+
// Start and end the string in the same terminal state it would be in if the string weren't sliced.
|
|
81
82
|
const leadingSequences = skippedSequences(text, 0, startIndex);
|
|
82
83
|
const trailingSequences = skippedSequences(text, endIndex);
|
|
83
84
|
|
package/src/strip.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import {rxCSI, rxUnsafe} from "./patterns";
|
|
2
2
|
|
|
3
|
+
/** Remove all ANSI escape codes from the given text. */
|
|
3
4
|
export const strip = (text: string): string => text.replace(new RegExp(rxCSI), "");
|
|
5
|
+
|
|
6
|
+
/** Calculate the visible length of a string with ANSI escape codes stripped. */
|
|
4
7
|
export const visibleLength = (text: string): number => strip(text).length;
|
|
8
|
+
|
|
9
|
+
/** Remove all ANSI escape codes except SGR codes (m), which are used for color and styling. */
|
|
5
10
|
export const sanitize = (text: string): string => text.replace(new RegExp(rxUnsafe), "");
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"test-rgb.d.ts","sourceRoot":"","sources":["../../../src/sgr/color/test-rgb.ts"],"names":[],"mappings":""}
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env -S npx tsx
|
|
2
|
-
"use strict";
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const __1 = __importDefault(require("../.."));
|
|
8
|
-
const log_1 = require("/home/pete/bin/lib/combo-input/log");
|
|
9
|
-
const terminal_1 = require("/home/pete/bin/lib/combo-input/terminal");
|
|
10
|
-
const defaultM = 6;
|
|
11
|
-
const defaultN = 1;
|
|
12
|
-
let m = defaultM;
|
|
13
|
-
let n = defaultN;
|
|
14
|
-
let x = 0;
|
|
15
|
-
let y = 0;
|
|
16
|
-
let show = 3;
|
|
17
|
-
let xOffset = 0;
|
|
18
|
-
let yOffset = 0;
|
|
19
|
-
const { columns, rows } = terminal_1.Terminal;
|
|
20
|
-
const width = Math.max();
|
|
21
|
-
const getParams = [
|
|
22
|
-
(a, b) => [a * m, b * m, y],
|
|
23
|
-
(a, b) => [a * m, y, b * m],
|
|
24
|
-
(a, b) => [y, a * m, b * m],
|
|
25
|
-
];
|
|
26
|
-
const paramNames = ["(a, b, y)", "(a, y, b)", "(y, a, b)"];
|
|
27
|
-
const d24 = (0, __1.default)(24);
|
|
28
|
-
const d8 = (0, __1.default)(8);
|
|
29
|
-
const d4 = (0, __1.default)(4);
|
|
30
|
-
const depths = [d24, d8, d4];
|
|
31
|
-
function fit() {
|
|
32
|
-
// const squareWidth = (256 / m | 0) * 2;
|
|
33
|
-
// const squaresWidth = squareWidth * depths.length + 4 * (depths.length - 1);
|
|
34
|
-
// const desiredSquaresWidth = columns
|
|
35
|
-
// const barWidth = 256 / n | 0;
|
|
36
|
-
// const infoHeight = 4;
|
|
37
|
-
// const height = infoHeight + 1 + (show & )
|
|
38
|
-
(0, log_1.log)(JSON.stringify({
|
|
39
|
-
columns,
|
|
40
|
-
"depths.length": depths.length,
|
|
41
|
-
"4 * (depths.length - 1)": 4 * (depths.length - 1),
|
|
42
|
-
"columns - 4 * (depths.length - 1)": columns - 4 * (depths.length - 1),
|
|
43
|
-
"512 * depths.length / (columns - 4 * (depths.length - 1))": 512 * depths.length / (columns - 4 * (depths.length - 1)),
|
|
44
|
-
currentWidth: (256 / m | 0) * 2 * depths.length + 4 * (depths.length - 1),
|
|
45
|
-
}, undefined, "\t"));
|
|
46
|
-
m = Math.ceil(512 * depths.length / (columns - 4 * (depths.length - 1)));
|
|
47
|
-
}
|
|
48
|
-
const buildFrame = () => ({
|
|
49
|
-
lines: [
|
|
50
|
-
`params : ${paramNames[x]}`,
|
|
51
|
-
`y : ${y}`,
|
|
52
|
-
`m : ${m}`,
|
|
53
|
-
`n : ${n}`,
|
|
54
|
-
"",
|
|
55
|
-
...!(show & 1) ? [] : Array.from({ length: 256 / m | 0 }, (_, b) => depths.map(d => Array.from({ length: 256 / m | 0 }, (_, a) => d.fg.rgb(...getParams[x](a, b))("██")).join("")).join(" ")),
|
|
56
|
-
...!(show & 2) ? [] : depths.flatMap(d => [
|
|
57
|
-
"",
|
|
58
|
-
Array.from({ length: 256 / n | 0 }, (_, i) => i === 100 ? "1" : i === 200 ? "2" : " ").join(""),
|
|
59
|
-
Array.from({ length: 256 / n | 0 }, (_, i) => i && (i % 10 === 0) ? String((i % 100) / 10) : " ").join(""),
|
|
60
|
-
Array.from({ length: 256 / n | 0 }, (_, i) => String(i % 10)).join(""),
|
|
61
|
-
Array.from({ length: 256 / n | 0 }, (_, i) => d.fg.rgb(n * i, n * 0, n * 0)("█")).join(""),
|
|
62
|
-
Array.from({ length: 256 / n | 0 }, (_, i) => d.fg.rgb(n * i, n * i / 2, n * 0)("█")).join(""),
|
|
63
|
-
Array.from({ length: 256 / n | 0 }, (_, i) => d.fg.rgb(n * i, n * i, n * 0)("█")).join(""),
|
|
64
|
-
Array.from({ length: 256 / n | 0 }, (_, i) => d.fg.rgb(n * i / 2, n * i, n * 0)("█")).join(""),
|
|
65
|
-
Array.from({ length: 256 / n | 0 }, (_, i) => d.fg.rgb(n * 0, n * i, n * 0)("█")).join(""),
|
|
66
|
-
Array.from({ length: 256 / n | 0 }, (_, i) => d.fg.rgb(n * 0, n * i, n * i / 2)("█")).join(""),
|
|
67
|
-
Array.from({ length: 256 / n | 0 }, (_, i) => d.fg.rgb(n * 0, n * i, n * i)("█")).join(""),
|
|
68
|
-
Array.from({ length: 256 / n | 0 }, (_, i) => d.fg.rgb(n * 0, n * i / 2, n * i)("█")).join(""),
|
|
69
|
-
Array.from({ length: 256 / n | 0 }, (_, i) => d.fg.rgb(n * 0, n * 0, n * i)("█")).join(""),
|
|
70
|
-
Array.from({ length: 256 / n | 0 }, (_, i) => d.fg.rgb(n * i / 2, n * 0, n * i)("█")).join(""),
|
|
71
|
-
Array.from({ length: 256 / n | 0 }, (_, i) => d.fg.rgb(n * i, n * 0, n * i)("█")).join(""),
|
|
72
|
-
]),
|
|
73
|
-
...!(show & 2) ? [] : [
|
|
74
|
-
"",
|
|
75
|
-
...depths.map(d => Array.from({ length: 256 / n | 0 }, (_, i) => d.fg.rgb(n * i, n * i, n * i)("█")).join("")),
|
|
76
|
-
],
|
|
77
|
-
],
|
|
78
|
-
caret: -1 //3 + length + depths.length * 12 + 1 + depths.length + 1,
|
|
79
|
-
});
|
|
80
|
-
const terminal = new terminal_1.Terminal(true, data => {
|
|
81
|
-
switch (data.key) {
|
|
82
|
-
case "up":
|
|
83
|
-
y = Math.min(y + 1, 255);
|
|
84
|
-
break;
|
|
85
|
-
case "down":
|
|
86
|
-
y = Math.max(y - 1, 0);
|
|
87
|
-
break;
|
|
88
|
-
case "left":
|
|
89
|
-
x = (x - 1 + 3) % 3;
|
|
90
|
-
break;
|
|
91
|
-
case "right":
|
|
92
|
-
x = (x + 1) % 3;
|
|
93
|
-
break;
|
|
94
|
-
case "pageup":
|
|
95
|
-
y = Math.min(y + 8, 255);
|
|
96
|
-
break;
|
|
97
|
-
case "pagedown":
|
|
98
|
-
y = Math.max(y - 8, 0);
|
|
99
|
-
break;
|
|
100
|
-
case "space":
|
|
101
|
-
show++;
|
|
102
|
-
show &= 3;
|
|
103
|
-
break;
|
|
104
|
-
case "!F":
|
|
105
|
-
m = defaultM;
|
|
106
|
-
n = defaultN;
|
|
107
|
-
break;
|
|
108
|
-
case "f":
|
|
109
|
-
fit();
|
|
110
|
-
break;
|
|
111
|
-
case "!M":
|
|
112
|
-
m++;
|
|
113
|
-
break;
|
|
114
|
-
case "m":
|
|
115
|
-
m = Math.max(m - 1, 1);
|
|
116
|
-
break;
|
|
117
|
-
case "!N":
|
|
118
|
-
n++;
|
|
119
|
-
break;
|
|
120
|
-
case "n":
|
|
121
|
-
n = Math.max(n - 1, 1);
|
|
122
|
-
break;
|
|
123
|
-
case "^c":
|
|
124
|
-
case "escape":
|
|
125
|
-
case "q":
|
|
126
|
-
cleanUp().catch(() => { });
|
|
127
|
-
return;
|
|
128
|
-
default: return;
|
|
129
|
-
}
|
|
130
|
-
render();
|
|
131
|
-
});
|
|
132
|
-
const frameWriter = new terminal_1.FrameWriter(terminal, 1, true);
|
|
133
|
-
const render = () => frameWriter.writeFrame(buildFrame()).catch(E => {
|
|
134
|
-
console.error(E);
|
|
135
|
-
});
|
|
136
|
-
render();
|
|
137
|
-
let closed = false;
|
|
138
|
-
async function cleanUp() {
|
|
139
|
-
if (closed)
|
|
140
|
-
return;
|
|
141
|
-
closed = true;
|
|
142
|
-
try {
|
|
143
|
-
await frameWriter.cleanUp();
|
|
144
|
-
}
|
|
145
|
-
finally {
|
|
146
|
-
terminal.cleanUp();
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
//# sourceMappingURL=test-rgb.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"test-rgb.js","sourceRoot":"","sources":["../../../src/sgr/color/test-rgb.ts"],"names":[],"mappings":";;;;;;AAEA,8CAA4C;AAC5C,4DAAyE;AACzE,sEAA8E;AAE9E,MAAM,QAAQ,GAAG,CAAC,CAAC;AACnB,MAAM,QAAQ,GAAG,CAAC,CAAC;AAEnB,IAAI,CAAC,GAAG,QAAQ,CAAC;AACjB,IAAI,CAAC,GAAG,QAAQ,CAAC;AAEjB,IAAI,CAAC,GAAG,CAAC,CAAC;AACV,IAAI,CAAC,GAAG,CAAC,CAAC;AAEV,IAAI,IAAI,GAAG,CAAC,CAAC;AAEb,IAAI,OAAO,GAAG,CAAC,CAAC;AAChB,IAAI,OAAO,GAAG,CAAC,CAAC;AAEhB,MAAM,EAAC,OAAO,EAAE,IAAI,EAAC,GAAG,mBAA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I,CAAQ;QACjB,KAAK,QAAQ,CAAI;QACjB,KAAK,GAAG;YAAU,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;YAAC,OAAO;QACpD,OAAgB,CAAC,CAAC,OAAO;IAC1B,CAAC;IAED,MAAM,EAAE,CAAC;AACV,CAAC,CAAC,CAAC;AAEH,MAAM,WAAW,GAAG,IAAI,sBAAW,CAAC,QAAQ,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;AAEvD,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,WAAW,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;IACnE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,MAAM,EAAE,CAAC;AAET,IAAI,MAAM,GAAG,KAAK,CAAC;AAEnB,KAAK,UAAU,OAAO;IACrB,IAAI,MAAM;QACT,OAAO;IAER,MAAM,GAAG,IAAI,CAAC;IAEd,IAAI,CAAC;QACJ,MAAM,WAAW,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;YAAS,CAAC;QACV,QAAQ,CAAC,OAAO,EAAE,CAAC;IACpB,CAAC;AACF,CAAC"}
|
package/dist/simplify/test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../../src/simplify/test.ts"],"names":[],"mappings":""}
|
package/dist/simplify/test.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const chalk_1 = __importDefault(require("/tmp/chalk/node_modules/chalk"));
|
|
7
|
-
const __1 = __importDefault(require(".."));
|
|
8
|
-
const patterns_1 = require("../patterns");
|
|
9
|
-
const simplify_1 = require("./simplify");
|
|
10
|
-
function showCodes(s) {
|
|
11
|
-
let result = ` ${__1.default.fg.green(JSON.stringify(s).replace(/\\u00/g, "\\x"))}\n`;
|
|
12
|
-
const parts = s.split(patterns_1.rxSGR);
|
|
13
|
-
result += ` [\n ${__1.default.fg.green(JSON.stringify(parts[0]))},\n`;
|
|
14
|
-
let longest = 0;
|
|
15
|
-
for (let i = 1; i < parts.length; i += 2) {
|
|
16
|
-
const text = parts[i].replace(/;/g, ", ");
|
|
17
|
-
if (text.length > longest)
|
|
18
|
-
longest = text.length;
|
|
19
|
-
}
|
|
20
|
-
for (let i = 1; i < parts.length; i += 2) {
|
|
21
|
-
const codes = parts[i].split(";");
|
|
22
|
-
const codeLength = codes.join(", ").length;
|
|
23
|
-
const padding = " ".repeat(longest - codeLength);
|
|
24
|
-
result += ` [${codes.map(__1.default.fg.yellow).join(", ")}], ${padding}${__1.default.fg.green(JSON.stringify(parts[i + 1]))},\n`;
|
|
25
|
-
}
|
|
26
|
-
result += " ]";
|
|
27
|
-
return result;
|
|
28
|
-
}
|
|
29
|
-
function test(s) {
|
|
30
|
-
const simplified = (0, simplify_1.simplify)(s);
|
|
31
|
-
console.log("original :\n" + showCodes(s));
|
|
32
|
-
console.log("simplified :\n" + showCodes(simplified));
|
|
33
|
-
console.log();
|
|
34
|
-
console.log("original :", s + __1.default.reset);
|
|
35
|
-
console.log("simplified :", simplified + __1.default.reset);
|
|
36
|
-
console.log("------------------------------");
|
|
37
|
-
}
|
|
38
|
-
const style = (name) => __1.default.style[name](name);
|
|
39
|
-
const fg = Object.assign((name) => __1.default.fg[name](name), {
|
|
40
|
-
rgb: (r, g, b) => __1.default.fg.rgb(r, g, b)(`rgb(${r}, ${g}, ${b})`),
|
|
41
|
-
x256: (r, g, b) => __1.default.fg.x256(r, g, b)(`x256(${r}, ${g}, ${b})`),
|
|
42
|
-
});
|
|
43
|
-
const bg = Object.assign((name) => __1.default.bg[name](`bg:${name}`), {
|
|
44
|
-
rgb: (r, g, b) => __1.default.bg.rgb(r, g, b)(`bg:rgb(${r}, ${g}, ${b})`),
|
|
45
|
-
x256: (r, g, b) => __1.default.bg.x256(r, g, b)(`bg:x256(${r}, ${g}, ${b})`),
|
|
46
|
-
});
|
|
47
|
-
debugger;
|
|
48
|
-
test("1: " + style("bold") + style("dim") + "default");
|
|
49
|
-
test("2: " + style("italic") + style("underline") + "default");
|
|
50
|
-
test("3: " + style("inverse") + style("hidden") + "default");
|
|
51
|
-
test("4: " + style("strikethrough") + "default");
|
|
52
|
-
test("5: " + fg("red") + fg("blue") + "default");
|
|
53
|
-
test("6: " + fg("red") + bg("blue") + "default");
|
|
54
|
-
test("7: " + fg.rgb(255, 0, 0) + bg.rgb(0, 0, 255) + "default");
|
|
55
|
-
test("8: " + fg.x256(0, 80, 0) + bg.x256(0, 0, 80) + "default");
|
|
56
|
-
test(`${__1.default.style.bold(`bold ${__1.default.style.dim("dim-bold")} bold again`)} ${__1.default.style.dim(`dim ${__1.default.style.bold(`bold-dim ${__1.default.style.dim("still dim")} still bold-dim`)} dim again`)} default`);
|
|
57
|
-
test(`${chalk_1.default.bold(`bold ${chalk_1.default.dim("dim-bold")} bold again`)} ${chalk_1.default.dim(`dim ${chalk_1.default.bold(`bold-dim ${chalk_1.default.dim("still dim")} still bold-dim`)} dim again`)} default`);
|
|
58
|
-
test(`reset in the middle: ${style("bold")}${__1.default.reset} reset`);
|
|
59
|
-
test(`reset at the end: ${style("bold")} default${__1.default.reset}`);
|
|
60
|
-
test(`multiple resets: ${style("bold")} default${__1.default.reset}${__1.default.reset} default`);
|
|
61
|
-
test(`codes after a reset: ${style("bold")} default${__1.default.reset}${__1.default.fg.default}${style("italic")} ${style("bold")} default`);
|
|
62
|
-
test(__1.default.fg.brightWhite(__1.default.bg.red(__1.default.style.underline("bright white on red with underline"))));
|
|
63
|
-
test(chalk_1.default.whiteBright.bgRed.underline("bright white on red with underline"));
|
|
64
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