@retrovm/terminal 0.1.0 → 0.1.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/README.md +57 -13
- package/dist/node.d.ts +5 -0
- package/dist/node.js +442 -0
- package/dist/terminal.d.ts +110 -0
- package/dist/terminal.js +437 -0
- package/package.json +16 -5
- package/src/node.ts +7 -0
package/README.md
CHANGED
|
@@ -38,13 +38,21 @@ term.red('Hello ').bgBlue(' world ').reset().println()
|
|
|
38
38
|
|
|
39
39
|
`Terminal.out` and `Terminal.err` are ready-made instances wired to `Bun.stdout` and `Bun.stderr`. Both are `ITerminal | undefined` — use `Terminal.out!` if you know stdout is available.
|
|
40
40
|
|
|
41
|
-
###
|
|
41
|
+
### Node.js
|
|
42
42
|
|
|
43
43
|
```typescript
|
|
44
|
-
import {
|
|
44
|
+
import { Terminal } from '@retrovm/terminal'
|
|
45
|
+
|
|
46
|
+
const term = Terminal.out // pre-wired to process.stdout
|
|
47
|
+
term.red('Hello ').bgBlue(' world ').reset().println()
|
|
48
|
+
```
|
|
45
49
|
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
`Terminal.out` and `Terminal.err` are pre-wired to `process.stdout` and `process.stderr` via the `"node"` export condition — no configuration needed.
|
|
51
|
+
|
|
52
|
+
### Any sink (xterm.js, custom, test)
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { createTerminal } from '@retrovm/terminal'
|
|
48
56
|
|
|
49
57
|
// xterm.js
|
|
50
58
|
import { Terminal as XTerm } from '@xterm/xterm'
|
|
@@ -266,21 +274,35 @@ Named shortcuts (`term.red`, `term.bgBlue`, …) are built from the static `Colo
|
|
|
266
274
|
{
|
|
267
275
|
"exports": {
|
|
268
276
|
".": {
|
|
269
|
-
"bun":
|
|
270
|
-
"types":
|
|
271
|
-
"
|
|
277
|
+
"bun": "./src/bun.ts",
|
|
278
|
+
"node": { "types": "./dist/node.d.ts", "default": "./dist/node.js" },
|
|
279
|
+
"types": "./dist/node.d.ts",
|
|
280
|
+
"import": "./dist/terminal.js"
|
|
272
281
|
}
|
|
273
282
|
}
|
|
274
283
|
}
|
|
275
284
|
```
|
|
276
285
|
|
|
277
|
-
| Condition |
|
|
286
|
+
| Condition | Resolved to | Used by |
|
|
278
287
|
|---|---|---|
|
|
279
|
-
| `bun` | `src/bun.ts` | Bun runtime —
|
|
280
|
-
| `
|
|
281
|
-
| `
|
|
288
|
+
| `bun` | `src/bun.ts` | Bun runtime — TS source, `Terminal.out/err` via `Bun.stdout/stderr` |
|
|
289
|
+
| `node` | `dist/node.js` + `dist/node.d.ts` | Node.js — `Terminal.out/err` via `process.stdout/stderr` |
|
|
290
|
+
| `types` | `dist/node.d.ts` | TypeScript language server (VSCode, tsc) in other environments |
|
|
291
|
+
| `import` | `dist/terminal.js` | Bundlers, ESM environments without a specific condition |
|
|
282
292
|
|
|
283
|
-
|
|
293
|
+
## Building
|
|
294
|
+
|
|
295
|
+
The package distributes TypeScript source for Bun and compiled output for Node.js. To build:
|
|
296
|
+
|
|
297
|
+
```sh
|
|
298
|
+
bun run build
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
This runs two steps:
|
|
302
|
+
1. **`bun build`** — compiles `terminal.ts` and `node.ts` to `dist/` targeting Node.js
|
|
303
|
+
2. **`tsc`** — generates `dist/terminal.d.ts` and `dist/node.d.ts` via `tsconfig.build.json`
|
|
304
|
+
|
|
305
|
+
`prepublishOnly` runs the build automatically before `bun publish` / `npm publish`.
|
|
284
306
|
|
|
285
307
|
---
|
|
286
308
|
|
|
@@ -364,4 +386,26 @@ NO_COLOR=1 bun run sample/rainbow.ts # plain text, no color
|
|
|
364
386
|
|
|
365
387
|
## License
|
|
366
388
|
|
|
367
|
-
|
|
389
|
+
```
|
|
390
|
+
MIT License
|
|
391
|
+
|
|
392
|
+
Copyright (c) 2026 Juan Carlos González Amestoy
|
|
393
|
+
|
|
394
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
395
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
396
|
+
in the Software without restriction, including without limitation the rights
|
|
397
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
398
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
399
|
+
furnished to do so, subject to the following conditions:
|
|
400
|
+
|
|
401
|
+
The above copyright notice and this permission notice shall be included in all
|
|
402
|
+
copies or substantial portions of the Software.
|
|
403
|
+
|
|
404
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
405
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
406
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
407
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
408
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
409
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
410
|
+
SOFTWARE.
|
|
411
|
+
```
|
package/dist/node.d.ts
ADDED
package/dist/node.js
ADDED
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
// node_modules/@retrovm/color/dist/color.js
|
|
2
|
+
var _colors;
|
|
3
|
+
var fract = (x) => {
|
|
4
|
+
return x - Math.floor(x);
|
|
5
|
+
};
|
|
6
|
+
var interpolate = (a, b, t) => {
|
|
7
|
+
return a + (b - a) * t;
|
|
8
|
+
};
|
|
9
|
+
var clamp = (x, min = 0, max = 1) => {
|
|
10
|
+
const c = x > min ? x : min;
|
|
11
|
+
return max < c ? max : c;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
class Color {
|
|
15
|
+
_r;
|
|
16
|
+
_g;
|
|
17
|
+
_b;
|
|
18
|
+
_a;
|
|
19
|
+
_h;
|
|
20
|
+
_s;
|
|
21
|
+
_v;
|
|
22
|
+
_ansiFg;
|
|
23
|
+
_ansiBg;
|
|
24
|
+
constructor(rs, g, b, a = 1) {
|
|
25
|
+
if (typeof rs === "number" && g !== undefined && b !== undefined) {
|
|
26
|
+
this._r = rs;
|
|
27
|
+
this._g = g;
|
|
28
|
+
this._b = b;
|
|
29
|
+
this._a = a;
|
|
30
|
+
} else if (typeof rs === "string") {
|
|
31
|
+
const match = rs.match(/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})?$/i);
|
|
32
|
+
if (match) {
|
|
33
|
+
this._r = parseInt(match[1], 16) / 255;
|
|
34
|
+
this._g = parseInt(match[2], 16) / 255;
|
|
35
|
+
this._b = parseInt(match[3], 16) / 255;
|
|
36
|
+
this._a = match[4] ? parseInt(match[4], 16) / 255 : 1;
|
|
37
|
+
} else {
|
|
38
|
+
const match2 = rs.match(/^#?([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])?$/i);
|
|
39
|
+
if (match2) {
|
|
40
|
+
this._r = parseInt(match2[1], 16) / 15;
|
|
41
|
+
this._g = parseInt(match2[2], 16) / 15;
|
|
42
|
+
this._b = parseInt(match2[3], 16) / 15;
|
|
43
|
+
this._a = match2[4] ? parseInt(match2[4], 16) / 15 : 1;
|
|
44
|
+
} else {
|
|
45
|
+
throw new Error("Invalid color string");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
throw new Error("Invalid arguments");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
get r() {
|
|
53
|
+
return this._r;
|
|
54
|
+
}
|
|
55
|
+
get g() {
|
|
56
|
+
return this._g;
|
|
57
|
+
}
|
|
58
|
+
get b() {
|
|
59
|
+
return this._b;
|
|
60
|
+
}
|
|
61
|
+
get a() {
|
|
62
|
+
return this._a;
|
|
63
|
+
}
|
|
64
|
+
get h() {
|
|
65
|
+
if (this._h === undefined) {
|
|
66
|
+
const M = Math.max(this._r, this._g, this._b);
|
|
67
|
+
const m = Math.min(this._r, this._g, this._b);
|
|
68
|
+
const c = M - m;
|
|
69
|
+
if (c === 0) {
|
|
70
|
+
this._h = 0;
|
|
71
|
+
} else if (M === this._r) {
|
|
72
|
+
this._h = (this._g - this._b) / c % 6;
|
|
73
|
+
} else if (M === this._g) {
|
|
74
|
+
this._h = (this._b - this._r) / c + 2;
|
|
75
|
+
} else {
|
|
76
|
+
this._h = (this._r - this._g) / c + 4;
|
|
77
|
+
}
|
|
78
|
+
this._h *= 60;
|
|
79
|
+
if (this._h < 0) {
|
|
80
|
+
this._h += 360;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return this._h / 360;
|
|
84
|
+
}
|
|
85
|
+
get s() {
|
|
86
|
+
if (this._s === undefined) {
|
|
87
|
+
const M = Math.max(this._r, this._g, this._b);
|
|
88
|
+
const m = Math.min(this._r, this._g, this._b);
|
|
89
|
+
this._s = M !== 0 ? (M - m) / M : 0;
|
|
90
|
+
}
|
|
91
|
+
return this._s;
|
|
92
|
+
}
|
|
93
|
+
get v() {
|
|
94
|
+
if (this._v === undefined) {
|
|
95
|
+
this._v = Math.max(this._r, this._g, this._b);
|
|
96
|
+
}
|
|
97
|
+
return this._v;
|
|
98
|
+
}
|
|
99
|
+
add(c) {
|
|
100
|
+
return new Color(this._r + c._r, this._g + c._g, this._b + c._b, this._a + c._a);
|
|
101
|
+
}
|
|
102
|
+
sub(c) {
|
|
103
|
+
return new Color(this._r - c._r, this._g - c._g, this._b - c._b, this._a - c._a);
|
|
104
|
+
}
|
|
105
|
+
mul(n) {
|
|
106
|
+
return new Color(this._r * n, this._g * n, this._b * n, this._a * n);
|
|
107
|
+
}
|
|
108
|
+
div(n) {
|
|
109
|
+
return new Color(this._r / n, this._g / n, this._b / n, this._a / n);
|
|
110
|
+
}
|
|
111
|
+
interpolate(c, t) {
|
|
112
|
+
return new Color(this._r + (c._r - this._r) * t, this._g + (c._g - this._g) * t, this._b + (c._b - this._b) * t, this._a + (c._a - this._a) * t);
|
|
113
|
+
}
|
|
114
|
+
interpolateIn(c, t) {
|
|
115
|
+
this._r += (c._r - this._r) * t;
|
|
116
|
+
this._g += (c._g - this._g) * t;
|
|
117
|
+
this._b += (c._b - this._b) * t;
|
|
118
|
+
this._a += (c._a - this._a) * t;
|
|
119
|
+
this._invalidateCaches();
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
_invalidateCaches() {
|
|
123
|
+
this._h = undefined;
|
|
124
|
+
this._s = undefined;
|
|
125
|
+
this._v = undefined;
|
|
126
|
+
this._ansiFg = undefined;
|
|
127
|
+
this._ansiBg = undefined;
|
|
128
|
+
}
|
|
129
|
+
toString() {
|
|
130
|
+
return `#${Math.round(this._r * 255).toString(16).padStart(2, "0")}${Math.round(this._g * 255).toString(16).padStart(2, "0")}${Math.round(this._b * 255).toString(16).padStart(2, "0")}${Math.round(this._a * 255).toString(16).padStart(2, "0")}`;
|
|
131
|
+
}
|
|
132
|
+
toAnsiRGB() {
|
|
133
|
+
return this._ansiFg ??= `\x1B[38;2;${Math.floor(this._r * 255)};${Math.floor(this._g * 255)};${Math.floor(this._b * 255)}m`;
|
|
134
|
+
}
|
|
135
|
+
toAnsiBackgroundRGB() {
|
|
136
|
+
return this._ansiBg ??= `\x1B[48;2;${Math.floor(this._r * 255)};${Math.floor(this._g * 255)};${Math.floor(this._b * 255)}m`;
|
|
137
|
+
}
|
|
138
|
+
static fromHSV(h, s, v, a = 1) {
|
|
139
|
+
let r = h + 1;
|
|
140
|
+
let g = h + 2 / 3;
|
|
141
|
+
let b = h + 1 / 3;
|
|
142
|
+
r = Math.abs(fract(r) * 6 - 3);
|
|
143
|
+
g = Math.abs(fract(g) * 6 - 3);
|
|
144
|
+
b = Math.abs(fract(b) * 6 - 3);
|
|
145
|
+
r = v * interpolate(1, clamp(r - 1), s);
|
|
146
|
+
g = v * interpolate(1, clamp(g - 1), s);
|
|
147
|
+
b = v * interpolate(1, clamp(b - 1), s);
|
|
148
|
+
r = Math.round(r * 1e4) / 1e4;
|
|
149
|
+
g = Math.round(g * 1e4) / 1e4;
|
|
150
|
+
b = Math.round(b * 1e4) / 1e4;
|
|
151
|
+
return new Color(r, g, b, a);
|
|
152
|
+
}
|
|
153
|
+
static aliceBlue = new Color(0.941176, 0.972549, 1, 1);
|
|
154
|
+
static antiqueWhite = new Color(0.980392, 0.921569, 0.843137, 1);
|
|
155
|
+
static aqua = new Color(0, 1, 1, 1);
|
|
156
|
+
static aquamarine = new Color(0.498039, 1, 0.831373, 1);
|
|
157
|
+
static azure = new Color(0.941176, 1, 1, 1);
|
|
158
|
+
static beige = new Color(0.960784, 0.960784, 0.862745, 1);
|
|
159
|
+
static bisque = new Color(1, 0.894118, 0.768627, 1);
|
|
160
|
+
static black = new Color(0, 0, 0, 1);
|
|
161
|
+
static blanchedAlmond = new Color(1, 0.921569, 0.803922, 1);
|
|
162
|
+
static blue = new Color(0, 0, 1, 1);
|
|
163
|
+
static blueViolet = new Color(0.541176, 0.168627, 0.886275, 1);
|
|
164
|
+
static brown = new Color(0.647059, 0.164706, 0.164706, 1);
|
|
165
|
+
static burlyWood = new Color(0.870588, 0.721569, 0.529412, 1);
|
|
166
|
+
static cadetBlue = new Color(0.372549, 0.619608, 0.627451, 1);
|
|
167
|
+
static chartreuse = new Color(0.498039, 1, 0, 1);
|
|
168
|
+
static chocolate = new Color(0.823529, 0.411765, 0.117647, 1);
|
|
169
|
+
static coral = new Color(1, 0.498039, 0.313725, 1);
|
|
170
|
+
static cornflowerBlue = new Color(0.392157, 0.584314, 0.929412, 1);
|
|
171
|
+
static cornsilk = new Color(0.882353, 0.972549, 0.862745, 1);
|
|
172
|
+
static crimson = new Color(0.862745, 0.078431, 0.235294, 1);
|
|
173
|
+
static cyan = new Color(0, 1, 1, 1);
|
|
174
|
+
static darkBlue = new Color(0, 0, 0.545098, 1);
|
|
175
|
+
static darkCyan = new Color(0, 0.545098, 0.545098, 1);
|
|
176
|
+
static darkGoldenrod = new Color(0.721569, 0.52549, 0.043137, 1);
|
|
177
|
+
static darkGray = new Color(0.662745, 0.662745, 0.662745, 1);
|
|
178
|
+
static darkGreen = new Color(0, 0.392157, 0, 1);
|
|
179
|
+
static darkKhaki = new Color(0.741176, 0.717647, 0.419608, 1);
|
|
180
|
+
static darkMagenta = new Color(0.545098, 0, 0.545098, 1);
|
|
181
|
+
static darkOliveGreen = new Color(0.333333, 0.419608, 0.184314, 1);
|
|
182
|
+
static darkOrange = new Color(1, 0.54902, 0, 1);
|
|
183
|
+
static darkOrchid = new Color(0.6, 0.196078, 0.8, 1);
|
|
184
|
+
static darkRed = new Color(0.545098, 0, 0, 1);
|
|
185
|
+
static darkSalmon = new Color(0.913725, 0.588235, 0.478431, 1);
|
|
186
|
+
static darkSeaGreen = new Color(0.560784, 0.737255, 0.560784, 1);
|
|
187
|
+
static darkSlateBlue = new Color(0.282353, 0.239216, 0.545098, 1);
|
|
188
|
+
static darkSlateGray = new Color(0.184314, 0.309804, 0.309804, 1);
|
|
189
|
+
static darkTurquoise = new Color(0, 0.807843, 0.819608, 1);
|
|
190
|
+
static darkViolet = new Color(0.580392, 0, 0.827451, 1);
|
|
191
|
+
static deepPink = new Color(1, 0.078431, 0.576471, 1);
|
|
192
|
+
static deepSkyBlue = new Color(0, 0.74902, 1, 1);
|
|
193
|
+
static dimGray = new Color(0.411765, 0.411765, 0.411765, 1);
|
|
194
|
+
static dodgerBlue = new Color(0.117647, 0.564706, 1, 1);
|
|
195
|
+
static fireBrick = new Color(0.698039, 0.133333, 0.133333, 1);
|
|
196
|
+
static floralWhite = new Color(1, 0.980392, 0.941176, 1);
|
|
197
|
+
static forestGreen = new Color(0.133333, 0.545098, 0.133333, 1);
|
|
198
|
+
static fuchsia = new Color(1, 0, 1, 1);
|
|
199
|
+
static gainsboro = new Color(0.862745, 0.862745, 0.862745, 1);
|
|
200
|
+
static ghostWhite = new Color(0.972549, 0.972549, 1, 1);
|
|
201
|
+
static gold = new Color(1, 0.843137, 0, 1);
|
|
202
|
+
static goldenrod = new Color(0.854902, 0.647059, 0.12549, 1);
|
|
203
|
+
static gray = new Color(0.501961, 0.501961, 0.501961, 1);
|
|
204
|
+
static green = new Color(0, 0.501961, 0, 1);
|
|
205
|
+
static greenYellow = new Color(0.678431, 1, 0.184314, 1);
|
|
206
|
+
static honeydew = new Color(0.941176, 1, 0.941176, 1);
|
|
207
|
+
static hotPink = new Color(1, 0.411765, 0.705882, 1);
|
|
208
|
+
static indianRed = new Color(0.803922, 0.360784, 0.360784, 1);
|
|
209
|
+
static indigo = new Color(0.294118, 0, 0.509804, 1);
|
|
210
|
+
static ivory = new Color(1, 1, 0.941176, 1);
|
|
211
|
+
static khaki = new Color(0.941176, 0.901961, 0.54902, 1);
|
|
212
|
+
static lavender = new Color(0.901961, 0.901961, 0.980392, 1);
|
|
213
|
+
static lavenderBlush = new Color(1, 0.941176, 0.960784, 1);
|
|
214
|
+
static lawnGreen = new Color(0.486275, 0.988235, 0, 1);
|
|
215
|
+
static lemonChiffon = new Color(1, 0.980392, 0.803922, 1);
|
|
216
|
+
static lightBlue = new Color(0.678431, 0.847059, 0.901961, 1);
|
|
217
|
+
static lightCoral = new Color(0.941176, 0.501961, 0.501961, 1);
|
|
218
|
+
static lightCyan = new Color(0.878431, 1, 1, 1);
|
|
219
|
+
static lightGoldenrodYellow = new Color(0.980392, 0.980392, 0.823529, 1);
|
|
220
|
+
static lightGreen = new Color(0.564706, 0.933333, 0.564706, 1);
|
|
221
|
+
static lightGrey = new Color(0.827451, 0.827451, 0.827451, 1);
|
|
222
|
+
static lightPink = new Color(1, 0.713725, 0.756863, 1);
|
|
223
|
+
static lightSalmon = new Color(1, 0.627451, 0.478431, 1);
|
|
224
|
+
static lightSeaGreen = new Color(0.12549, 0.698039, 0.666667, 1);
|
|
225
|
+
static lightSkyBlue = new Color(0.529412, 0.807843, 0.980392, 1);
|
|
226
|
+
static lightSlateGray = new Color(0.466667, 0.533333, 0.6, 1);
|
|
227
|
+
static lightSteelBlue = new Color(0.690196, 0.768627, 0.870588, 1);
|
|
228
|
+
static lightYellow = new Color(1, 1, 0.878431, 1);
|
|
229
|
+
static lime = new Color(0, 1, 0, 1);
|
|
230
|
+
static limeGreen = new Color(0.196078, 0.803922, 0.196078, 1);
|
|
231
|
+
static linen = new Color(0.980392, 0.941176, 0.901961, 1);
|
|
232
|
+
static magenta = new Color(1, 0, 1, 1);
|
|
233
|
+
static maroon = new Color(0.501961, 0, 0, 1);
|
|
234
|
+
static mediumAquamarine = new Color(0.4, 0.803922, 0.666667, 1);
|
|
235
|
+
static mediumBlue = new Color(0, 0, 0.803922, 1);
|
|
236
|
+
static mediumOrchid = new Color(0.729412, 0.333333, 0.827451, 1);
|
|
237
|
+
static mediumPurple = new Color(0.576471, 0.439216, 0.858824, 1);
|
|
238
|
+
static mediumSeaGreen = new Color(0.235294, 0.701961, 0.443137, 1);
|
|
239
|
+
static mediumSlateBlue = new Color(0.482353, 0.407843, 0.933333, 1);
|
|
240
|
+
static mediumSpringGreen = new Color(0, 0.980392, 0.603922, 1);
|
|
241
|
+
static mediumTurquoise = new Color(0.282353, 0.819608, 0.8, 1);
|
|
242
|
+
static mediumVioletRed = new Color(0.780392, 0.082353, 0.521569, 1);
|
|
243
|
+
static midnightBlue = new Color(0.098039, 0.098039, 0.439216, 1);
|
|
244
|
+
static mintCream = new Color(0.960784, 1, 0.980392, 1);
|
|
245
|
+
static mistyRose = new Color(1, 0.894118, 0.882353, 1);
|
|
246
|
+
static moccasin = new Color(1, 0.894118, 0.709804, 1);
|
|
247
|
+
static navajoWhite = new Color(1, 0.870588, 0.678431, 1);
|
|
248
|
+
static navy = new Color(0, 0, 0.501961, 1);
|
|
249
|
+
static oldLace = new Color(0.992157, 0.960784, 0.901961, 1);
|
|
250
|
+
static olive = new Color(0.501961, 0.501961, 0, 1);
|
|
251
|
+
static oliveDrab = new Color(0.419608, 0.556863, 0.137255, 1);
|
|
252
|
+
static orange = new Color(1, 0.647059, 0, 1);
|
|
253
|
+
static orangeRed = new Color(1, 0.270588, 0, 1);
|
|
254
|
+
static orchid = new Color(0.854902, 0.439216, 0.839216, 1);
|
|
255
|
+
static paleGoldenrod = new Color(0.933333, 0.909804, 0.666667, 1);
|
|
256
|
+
static paleGreen = new Color(0.596078, 0.984314, 0.596078, 1);
|
|
257
|
+
static paleTurquoise = new Color(0.686275, 0.933333, 0.933333, 1);
|
|
258
|
+
static paleVioletRed = new Color(0.858824, 0.439216, 0.576471, 1);
|
|
259
|
+
static papayaWhip = new Color(1, 0.937255, 0.835294, 1);
|
|
260
|
+
static peachPuff = new Color(1, 0.854902, 0.72549, 1);
|
|
261
|
+
static peru = new Color(0.803922, 0.521569, 0.247059, 1);
|
|
262
|
+
static pink = new Color(1, 0.752941, 0.796078, 1);
|
|
263
|
+
static plum = new Color(0.866667, 0.627451, 0.866667, 1);
|
|
264
|
+
static powderBlue = new Color(0.690196, 0.878431, 0.901961, 1);
|
|
265
|
+
static purple = new Color(0.501961, 0, 0.501961, 1);
|
|
266
|
+
static red = new Color(1, 0, 0, 1);
|
|
267
|
+
static rosyBrown = new Color(0.737255, 0.560784, 0.560784, 1);
|
|
268
|
+
static royalBlue = new Color(0.254902, 0.411765, 0.882353, 1);
|
|
269
|
+
static saddleBrown = new Color(0.545098, 0.270588, 0.07451, 1);
|
|
270
|
+
static salmon = new Color(0.980392, 0.501961, 0.447059, 1);
|
|
271
|
+
static sandyBrown = new Color(0.956863, 0.643137, 0.376471, 1);
|
|
272
|
+
static seaGreen = new Color(0.180392, 0.545098, 0.380392, 1);
|
|
273
|
+
static seashell = new Color(1, 0.960784, 0.933333, 1);
|
|
274
|
+
static sienna = new Color(0.627451, 0.321569, 0.176471, 1);
|
|
275
|
+
static silver = new Color(0.752941, 0.752941, 0.752941, 1);
|
|
276
|
+
static skyBlue = new Color(0.529412, 0.807843, 0.921569, 1);
|
|
277
|
+
static slateBlue = new Color(0.415686, 0.352941, 0.803922, 1);
|
|
278
|
+
static slateGray = new Color(0.466667, 0.533333, 0.6, 1);
|
|
279
|
+
static snow = new Color(1, 0.980392, 0.980392, 1);
|
|
280
|
+
static springGreen = new Color(0, 1, 0.498039, 1);
|
|
281
|
+
static steelBlue = new Color(0.27451, 0.509804, 0.705882, 1);
|
|
282
|
+
static tan = new Color(0.823529, 0.705882, 0.54902, 1);
|
|
283
|
+
static teal = new Color(0, 0.501961, 0.501961, 1);
|
|
284
|
+
static thistle = new Color(0.847059, 0.74902, 0.847059, 1);
|
|
285
|
+
static tomato = new Color(1, 0.388235, 0.278431, 1);
|
|
286
|
+
static transparent = new Color(0, 0, 0, 0);
|
|
287
|
+
static turquoise = new Color(0.25098, 0.878431, 0.815686, 1);
|
|
288
|
+
static violet = new Color(0.933333, 0.509804, 0.933333, 1);
|
|
289
|
+
static wheat = new Color(0.960784, 0.870588, 0.701961, 1);
|
|
290
|
+
static white = new Color(1, 1, 1, 1);
|
|
291
|
+
static whiteSmoke = new Color(0.960784, 0.960784, 0.960784, 1);
|
|
292
|
+
static yellow = new Color(1, 1, 0, 1);
|
|
293
|
+
static yellowGreen = new Color(0.603922, 0.803922, 0.196078, 1);
|
|
294
|
+
static names = ["aliceBlue", "antiqueWhite", "aqua", "aquamarine", "azure", "beige", "bisque", "black", "blanchedAlmond", "blue", "blueViolet", "brown", "burlyWood", "cadetBlue", "chartreuse", "chocolate", "coral", "cornflowerBlue", "cornsilk", "crimson", "cyan", "darkBlue", "darkCyan", "darkGoldenrod", "darkGray", "darkGreen", "darkKhaki", "darkMagenta", "darkOliveGreen", "darkOrange", "darkOrchid", "darkRed", "darkSalmon", "darkSeaGreen", "darkSlateBlue", "darkSlateGray", "darkTurquoise", "darkViolet", "deepPink", "deepSkyBlue", "dimGray", "dodgerBlue", "fireBrick", "floralWhite", "forestGreen", "fuchsia", "gainsboro", "ghostWhite", "gold", "goldenrod", "gray", "green", "greenYellow", "honeydew", "hotPink", "indianRed", "indigo", "ivory", "khaki", "lavender", "lavenderBlush", "lawnGreen", "lemonChiffon", "lightBlue", "lightCoral", "lightCyan", "lightGoldenrodYellow", "lightGreen", "lightGrey", "lightPink", "lightSalmon", "lightSeaGreen", "lightSkyBlue", "lightSlateGray", "lightSteelBlue", "lightYellow", "lime", "limeGreen", "linen", "magenta", "maroon", "mediumAquamarine", "mediumBlue", "mediumOrchid", "mediumPurple", "mediumSeaGreen", "mediumSlateBlue", "mediumSpringGreen", "mediumTurquoise", "mediumVioletRed", "midnightBlue", "mintCream", "mistyRose", "moccasin", "navajoWhite", "navy", "oldLace", "olive", "oliveDrab", "orange", "orangeRed", "orchid", "paleGoldenrod", "paleGreen", "paleTurquoise", "paleVioletRed", "papayaWhip", "peachPuff", "peru", "pink", "plum", "powderBlue", "purple", "red", "rosyBrown", "royalBlue", "saddleBrown", "salmon", "sandyBrown", "seaGreen", "seashell", "sienna", "silver", "skyBlue", "slateBlue", "slateGray", "snow", "springGreen", "steelBlue", "tan", "teal", "thistle", "tomato", "transparent", "turquoise", "violet", "wheat", "white", "whiteSmoke", "yellow", "yellowGreen"];
|
|
295
|
+
static get colors() {
|
|
296
|
+
if (_colors === undefined) {
|
|
297
|
+
_colors = {};
|
|
298
|
+
const _c = _colors;
|
|
299
|
+
const o = Color;
|
|
300
|
+
Color.names.forEach((name) => {
|
|
301
|
+
_c[name] = o[name];
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
return _colors;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// src/terminal.ts
|
|
309
|
+
import { format } from "node:util";
|
|
310
|
+
|
|
311
|
+
class TerminalCore {
|
|
312
|
+
writer;
|
|
313
|
+
plain;
|
|
314
|
+
constructor(writer, options = {}) {
|
|
315
|
+
this.writer = writer;
|
|
316
|
+
const envNoColor = typeof process !== "undefined" && !!process?.env?.NO_COLOR;
|
|
317
|
+
this.plain = options.plain ?? envNoColor;
|
|
318
|
+
}
|
|
319
|
+
emit(data) {
|
|
320
|
+
this.writer.write(data);
|
|
321
|
+
}
|
|
322
|
+
style(seq, fmt, args) {
|
|
323
|
+
const text = format(fmt, ...args);
|
|
324
|
+
this.emit(this.plain ? text : seq + text);
|
|
325
|
+
return this;
|
|
326
|
+
}
|
|
327
|
+
print(fmt = "", ...args) {
|
|
328
|
+
this.emit(format(fmt, ...args));
|
|
329
|
+
return this;
|
|
330
|
+
}
|
|
331
|
+
println(fmt = "", ...args) {
|
|
332
|
+
this.emit(format(fmt, ...args) + `\r
|
|
333
|
+
`);
|
|
334
|
+
return this;
|
|
335
|
+
}
|
|
336
|
+
ink(c, fmt = "", ...args) {
|
|
337
|
+
const color = typeof c === "string" ? new Color(c) : c;
|
|
338
|
+
return this.style(color.toAnsiRGB(), fmt, args);
|
|
339
|
+
}
|
|
340
|
+
paper(c, fmt = "", ...args) {
|
|
341
|
+
const color = typeof c === "string" ? new Color(c) : c;
|
|
342
|
+
return this.style(color.toAnsiBackgroundRGB(), fmt, args);
|
|
343
|
+
}
|
|
344
|
+
reset(fmt = "", ...args) {
|
|
345
|
+
return this.style("\x1B[0m", fmt, args);
|
|
346
|
+
}
|
|
347
|
+
resetInk(fmt = "", ...args) {
|
|
348
|
+
return this.style("\x1B[39m", fmt, args);
|
|
349
|
+
}
|
|
350
|
+
resetPaper(fmt = "", ...args) {
|
|
351
|
+
return this.style("\x1B[49m", fmt, args);
|
|
352
|
+
}
|
|
353
|
+
cls() {
|
|
354
|
+
this.emit("\x1B[2J\x1B[H");
|
|
355
|
+
return this;
|
|
356
|
+
}
|
|
357
|
+
clearLine() {
|
|
358
|
+
this.emit("\x1B[K");
|
|
359
|
+
return this;
|
|
360
|
+
}
|
|
361
|
+
up(n = 1) {
|
|
362
|
+
this.emit(`\x1B[${n}A`);
|
|
363
|
+
return this;
|
|
364
|
+
}
|
|
365
|
+
down(n = 1) {
|
|
366
|
+
this.emit(`\x1B[${n}B`);
|
|
367
|
+
return this;
|
|
368
|
+
}
|
|
369
|
+
right(n = 1) {
|
|
370
|
+
this.emit(`\x1B[${n}C`);
|
|
371
|
+
return this;
|
|
372
|
+
}
|
|
373
|
+
left(n = 1) {
|
|
374
|
+
this.emit(`\x1B[${n}D`);
|
|
375
|
+
return this;
|
|
376
|
+
}
|
|
377
|
+
column(n = 1) {
|
|
378
|
+
this.emit(`\x1B[${n}G`);
|
|
379
|
+
return this;
|
|
380
|
+
}
|
|
381
|
+
row(n = 1) {
|
|
382
|
+
this.emit(`\x1B[${n}d`);
|
|
383
|
+
return this;
|
|
384
|
+
}
|
|
385
|
+
moveTo(row, col) {
|
|
386
|
+
this.emit(`\x1B[${row};${col}H`);
|
|
387
|
+
return this;
|
|
388
|
+
}
|
|
389
|
+
saveCursor() {
|
|
390
|
+
this.emit("\x1B[s");
|
|
391
|
+
return this;
|
|
392
|
+
}
|
|
393
|
+
restoreCursor() {
|
|
394
|
+
this.emit("\x1B[u");
|
|
395
|
+
return this;
|
|
396
|
+
}
|
|
397
|
+
cursor(visible = true) {
|
|
398
|
+
this.emit(visible ? "\x1B[?25h" : "\x1B[?25l");
|
|
399
|
+
return this;
|
|
400
|
+
}
|
|
401
|
+
alt(b = true) {
|
|
402
|
+
this.emit(`\x1B[?1049${b ? "h" : "l"}`);
|
|
403
|
+
return this;
|
|
404
|
+
}
|
|
405
|
+
autoWrap(b = true) {
|
|
406
|
+
this.emit(`\x1B[?7${b ? "h" : "l"}`);
|
|
407
|
+
return this;
|
|
408
|
+
}
|
|
409
|
+
scrollRegion(top, bottom) {
|
|
410
|
+
this.emit(`\x1B[${top};${bottom}r`);
|
|
411
|
+
return this;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
function installColorMethods() {
|
|
415
|
+
const proto = TerminalCore.prototype;
|
|
416
|
+
const cap = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
417
|
+
for (const key of Object.keys(Color)) {
|
|
418
|
+
const value = Color[key];
|
|
419
|
+
if (!(value instanceof Color))
|
|
420
|
+
continue;
|
|
421
|
+
const name = key;
|
|
422
|
+
proto[name] = function(fmt = "", ...args) {
|
|
423
|
+
return this.ink(value, fmt, ...args);
|
|
424
|
+
};
|
|
425
|
+
proto[`bg${cap(name)}`] = function(fmt = "", ...args) {
|
|
426
|
+
return this.paper(value, fmt, ...args);
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
installColorMethods();
|
|
431
|
+
function createTerminal(writer, options = {}) {
|
|
432
|
+
return new TerminalCore(writer, options);
|
|
433
|
+
}
|
|
434
|
+
// src/node.ts
|
|
435
|
+
var Terminal = {
|
|
436
|
+
out: createTerminal(process.stdout),
|
|
437
|
+
err: createTerminal(process.stderr)
|
|
438
|
+
};
|
|
439
|
+
export {
|
|
440
|
+
createTerminal,
|
|
441
|
+
Terminal
|
|
442
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Color } from '@retrovm/color';
|
|
2
|
+
/**
|
|
3
|
+
* Minimal sink interface. Anything with a `write(data: string)` method works:
|
|
4
|
+
* an xterm.js Terminal instance, a Node Writable, a Bun writer wrapper, or a
|
|
5
|
+
* test double that pushes to an array.
|
|
6
|
+
*/
|
|
7
|
+
export interface ITerminalWriter {
|
|
8
|
+
write(data: string): void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Extracts from `Color` only the keys whose value is an instance of `Color`,
|
|
12
|
+
* so the generated method names exactly match the available named colors.
|
|
13
|
+
* Add a color to the `Color` class and both `ink<Name>` and `bg<Name>` methods
|
|
14
|
+
* appear automatically with full type safety and autocompletion.
|
|
15
|
+
*/
|
|
16
|
+
type ColorName = {
|
|
17
|
+
[K in keyof typeof Color]: typeof Color[K] extends Color ? K : never;
|
|
18
|
+
}[keyof typeof Color];
|
|
19
|
+
type ColorMethod = (fmt?: string, ...args: unknown[]) => ITerminal;
|
|
20
|
+
type InkMethods = {
|
|
21
|
+
[K in ColorName]: ColorMethod;
|
|
22
|
+
};
|
|
23
|
+
type BgMethods = {
|
|
24
|
+
[K in ColorName as `bg${Capitalize<string & K>}`]: ColorMethod;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Public type of a Terminal instance: core methods plus all the auto-generated
|
|
28
|
+
* color shortcuts. Consumers see one cohesive type with autocompletion.
|
|
29
|
+
*/
|
|
30
|
+
export type ITerminal = TerminalCore & InkMethods & BgMethods;
|
|
31
|
+
/**
|
|
32
|
+
* Core terminal output. Wraps any object with a `write(string)` method and
|
|
33
|
+
* exposes a fluent API for ANSI styling and cursor control.
|
|
34
|
+
*
|
|
35
|
+
* Color shortcut methods (e.g. `red`, `bgBlue`) are attached at construction
|
|
36
|
+
* time from the `Color` registry. They are declared via the `ITerminal` type
|
|
37
|
+
* and dispatched through an index signature on the class.
|
|
38
|
+
*/
|
|
39
|
+
declare class TerminalCore {
|
|
40
|
+
private readonly writer;
|
|
41
|
+
/** ANSI is suppressed when true; styling/cursor methods become no-ops. */
|
|
42
|
+
plain: boolean;
|
|
43
|
+
[key: string]: unknown;
|
|
44
|
+
constructor(writer: ITerminalWriter, options?: {
|
|
45
|
+
plain?: boolean;
|
|
46
|
+
});
|
|
47
|
+
/** Internal write helper. Single point of contact with the sink. */
|
|
48
|
+
private emit;
|
|
49
|
+
/** Internal style helper: skips ANSI when `plain` is enabled. */
|
|
50
|
+
private style;
|
|
51
|
+
/** Prints formatted text. Uses `util.format` semantics (`%s`, `%d`, …). */
|
|
52
|
+
print(fmt?: string, ...args: unknown[]): this;
|
|
53
|
+
/** Prints formatted text followed by a newline. */
|
|
54
|
+
println(fmt?: string, ...args: unknown[]): this;
|
|
55
|
+
/** Sets the foreground color and optionally writes formatted text. */
|
|
56
|
+
ink(c: string | Color, fmt?: string, ...args: unknown[]): this;
|
|
57
|
+
/** Sets the background color and optionally writes formatted text. */
|
|
58
|
+
paper(c: string | Color, fmt?: string, ...args: unknown[]): this;
|
|
59
|
+
/** Resets all attributes (color, background, intensity, …). */
|
|
60
|
+
reset(fmt?: string, ...args: unknown[]): this;
|
|
61
|
+
/** Resets only the foreground color. */
|
|
62
|
+
resetInk(fmt?: string, ...args: unknown[]): this;
|
|
63
|
+
/** Resets only the background color. */
|
|
64
|
+
resetPaper(fmt?: string, ...args: unknown[]): this;
|
|
65
|
+
/** Clears the screen and homes the cursor. */
|
|
66
|
+
cls(): this;
|
|
67
|
+
/** Clears from cursor to end of line. */
|
|
68
|
+
clearLine(): this;
|
|
69
|
+
up(n?: number): this;
|
|
70
|
+
down(n?: number): this;
|
|
71
|
+
right(n?: number): this;
|
|
72
|
+
left(n?: number): this;
|
|
73
|
+
/** Moves the cursor to the given column (1-based). */
|
|
74
|
+
column(n?: number): this;
|
|
75
|
+
/** Moves the cursor to the given row (1-based). */
|
|
76
|
+
row(n?: number): this;
|
|
77
|
+
/** Moves the cursor to the given (row, col), both 1-based. */
|
|
78
|
+
moveTo(row: number, col: number): this;
|
|
79
|
+
/** Saves the current cursor position. */
|
|
80
|
+
saveCursor(): this;
|
|
81
|
+
/** Restores the previously saved cursor position. */
|
|
82
|
+
restoreCursor(): this;
|
|
83
|
+
/** Shows or hides the cursor. */
|
|
84
|
+
cursor(visible?: boolean): this;
|
|
85
|
+
/** Enables or disables the alternate screen buffer. */
|
|
86
|
+
alt(b?: boolean): this;
|
|
87
|
+
/**
|
|
88
|
+
* Enables or disables auto-wrap (DECAWM, mode 7).
|
|
89
|
+
* Note: this is the rename of the old `scroll()` method, which was
|
|
90
|
+
* misnamed — DEC private mode 7 controls wrapping, not scrolling.
|
|
91
|
+
*/
|
|
92
|
+
autoWrap(b?: boolean): this;
|
|
93
|
+
/** Sets the scrolling region (DECSTBM), both rows 1-based and inclusive. */
|
|
94
|
+
scrollRegion(top: number, bottom: number): this;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Public constructor. Accepts any object with a `write(string)` method —
|
|
98
|
+
* an xterm.js `Terminal`, a Node `Writable`, a Bun writer wrapper, or a mock.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* import { Terminal as XTerm } from '@xterm/xterm'
|
|
102
|
+
* const xterm = new XTerm()
|
|
103
|
+
* xterm.open(document.getElementById('term')!)
|
|
104
|
+
* const term = createTerminal(xterm)
|
|
105
|
+
* term.red('Hello ').bgBlue(' world ').reset().println()
|
|
106
|
+
*/
|
|
107
|
+
export declare function createTerminal(writer: ITerminalWriter, options?: {
|
|
108
|
+
plain?: boolean;
|
|
109
|
+
}): ITerminal;
|
|
110
|
+
export { TerminalCore };
|
package/dist/terminal.js
ADDED
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
// node_modules/@retrovm/color/dist/color.js
|
|
2
|
+
var _colors;
|
|
3
|
+
var fract = (x) => {
|
|
4
|
+
return x - Math.floor(x);
|
|
5
|
+
};
|
|
6
|
+
var interpolate = (a, b, t) => {
|
|
7
|
+
return a + (b - a) * t;
|
|
8
|
+
};
|
|
9
|
+
var clamp = (x, min = 0, max = 1) => {
|
|
10
|
+
const c = x > min ? x : min;
|
|
11
|
+
return max < c ? max : c;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
class Color {
|
|
15
|
+
_r;
|
|
16
|
+
_g;
|
|
17
|
+
_b;
|
|
18
|
+
_a;
|
|
19
|
+
_h;
|
|
20
|
+
_s;
|
|
21
|
+
_v;
|
|
22
|
+
_ansiFg;
|
|
23
|
+
_ansiBg;
|
|
24
|
+
constructor(rs, g, b, a = 1) {
|
|
25
|
+
if (typeof rs === "number" && g !== undefined && b !== undefined) {
|
|
26
|
+
this._r = rs;
|
|
27
|
+
this._g = g;
|
|
28
|
+
this._b = b;
|
|
29
|
+
this._a = a;
|
|
30
|
+
} else if (typeof rs === "string") {
|
|
31
|
+
const match = rs.match(/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})?$/i);
|
|
32
|
+
if (match) {
|
|
33
|
+
this._r = parseInt(match[1], 16) / 255;
|
|
34
|
+
this._g = parseInt(match[2], 16) / 255;
|
|
35
|
+
this._b = parseInt(match[3], 16) / 255;
|
|
36
|
+
this._a = match[4] ? parseInt(match[4], 16) / 255 : 1;
|
|
37
|
+
} else {
|
|
38
|
+
const match2 = rs.match(/^#?([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])?$/i);
|
|
39
|
+
if (match2) {
|
|
40
|
+
this._r = parseInt(match2[1], 16) / 15;
|
|
41
|
+
this._g = parseInt(match2[2], 16) / 15;
|
|
42
|
+
this._b = parseInt(match2[3], 16) / 15;
|
|
43
|
+
this._a = match2[4] ? parseInt(match2[4], 16) / 15 : 1;
|
|
44
|
+
} else {
|
|
45
|
+
throw new Error("Invalid color string");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
throw new Error("Invalid arguments");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
get r() {
|
|
53
|
+
return this._r;
|
|
54
|
+
}
|
|
55
|
+
get g() {
|
|
56
|
+
return this._g;
|
|
57
|
+
}
|
|
58
|
+
get b() {
|
|
59
|
+
return this._b;
|
|
60
|
+
}
|
|
61
|
+
get a() {
|
|
62
|
+
return this._a;
|
|
63
|
+
}
|
|
64
|
+
get h() {
|
|
65
|
+
if (this._h === undefined) {
|
|
66
|
+
const M = Math.max(this._r, this._g, this._b);
|
|
67
|
+
const m = Math.min(this._r, this._g, this._b);
|
|
68
|
+
const c = M - m;
|
|
69
|
+
if (c === 0) {
|
|
70
|
+
this._h = 0;
|
|
71
|
+
} else if (M === this._r) {
|
|
72
|
+
this._h = (this._g - this._b) / c % 6;
|
|
73
|
+
} else if (M === this._g) {
|
|
74
|
+
this._h = (this._b - this._r) / c + 2;
|
|
75
|
+
} else {
|
|
76
|
+
this._h = (this._r - this._g) / c + 4;
|
|
77
|
+
}
|
|
78
|
+
this._h *= 60;
|
|
79
|
+
if (this._h < 0) {
|
|
80
|
+
this._h += 360;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return this._h / 360;
|
|
84
|
+
}
|
|
85
|
+
get s() {
|
|
86
|
+
if (this._s === undefined) {
|
|
87
|
+
const M = Math.max(this._r, this._g, this._b);
|
|
88
|
+
const m = Math.min(this._r, this._g, this._b);
|
|
89
|
+
this._s = M !== 0 ? (M - m) / M : 0;
|
|
90
|
+
}
|
|
91
|
+
return this._s;
|
|
92
|
+
}
|
|
93
|
+
get v() {
|
|
94
|
+
if (this._v === undefined) {
|
|
95
|
+
this._v = Math.max(this._r, this._g, this._b);
|
|
96
|
+
}
|
|
97
|
+
return this._v;
|
|
98
|
+
}
|
|
99
|
+
add(c) {
|
|
100
|
+
return new Color(this._r + c._r, this._g + c._g, this._b + c._b, this._a + c._a);
|
|
101
|
+
}
|
|
102
|
+
sub(c) {
|
|
103
|
+
return new Color(this._r - c._r, this._g - c._g, this._b - c._b, this._a - c._a);
|
|
104
|
+
}
|
|
105
|
+
mul(n) {
|
|
106
|
+
return new Color(this._r * n, this._g * n, this._b * n, this._a * n);
|
|
107
|
+
}
|
|
108
|
+
div(n) {
|
|
109
|
+
return new Color(this._r / n, this._g / n, this._b / n, this._a / n);
|
|
110
|
+
}
|
|
111
|
+
interpolate(c, t) {
|
|
112
|
+
return new Color(this._r + (c._r - this._r) * t, this._g + (c._g - this._g) * t, this._b + (c._b - this._b) * t, this._a + (c._a - this._a) * t);
|
|
113
|
+
}
|
|
114
|
+
interpolateIn(c, t) {
|
|
115
|
+
this._r += (c._r - this._r) * t;
|
|
116
|
+
this._g += (c._g - this._g) * t;
|
|
117
|
+
this._b += (c._b - this._b) * t;
|
|
118
|
+
this._a += (c._a - this._a) * t;
|
|
119
|
+
this._invalidateCaches();
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
_invalidateCaches() {
|
|
123
|
+
this._h = undefined;
|
|
124
|
+
this._s = undefined;
|
|
125
|
+
this._v = undefined;
|
|
126
|
+
this._ansiFg = undefined;
|
|
127
|
+
this._ansiBg = undefined;
|
|
128
|
+
}
|
|
129
|
+
toString() {
|
|
130
|
+
return `#${Math.round(this._r * 255).toString(16).padStart(2, "0")}${Math.round(this._g * 255).toString(16).padStart(2, "0")}${Math.round(this._b * 255).toString(16).padStart(2, "0")}${Math.round(this._a * 255).toString(16).padStart(2, "0")}`;
|
|
131
|
+
}
|
|
132
|
+
toAnsiRGB() {
|
|
133
|
+
return this._ansiFg ??= `\x1B[38;2;${Math.floor(this._r * 255)};${Math.floor(this._g * 255)};${Math.floor(this._b * 255)}m`;
|
|
134
|
+
}
|
|
135
|
+
toAnsiBackgroundRGB() {
|
|
136
|
+
return this._ansiBg ??= `\x1B[48;2;${Math.floor(this._r * 255)};${Math.floor(this._g * 255)};${Math.floor(this._b * 255)}m`;
|
|
137
|
+
}
|
|
138
|
+
static fromHSV(h, s, v, a = 1) {
|
|
139
|
+
let r = h + 1;
|
|
140
|
+
let g = h + 2 / 3;
|
|
141
|
+
let b = h + 1 / 3;
|
|
142
|
+
r = Math.abs(fract(r) * 6 - 3);
|
|
143
|
+
g = Math.abs(fract(g) * 6 - 3);
|
|
144
|
+
b = Math.abs(fract(b) * 6 - 3);
|
|
145
|
+
r = v * interpolate(1, clamp(r - 1), s);
|
|
146
|
+
g = v * interpolate(1, clamp(g - 1), s);
|
|
147
|
+
b = v * interpolate(1, clamp(b - 1), s);
|
|
148
|
+
r = Math.round(r * 1e4) / 1e4;
|
|
149
|
+
g = Math.round(g * 1e4) / 1e4;
|
|
150
|
+
b = Math.round(b * 1e4) / 1e4;
|
|
151
|
+
return new Color(r, g, b, a);
|
|
152
|
+
}
|
|
153
|
+
static aliceBlue = new Color(0.941176, 0.972549, 1, 1);
|
|
154
|
+
static antiqueWhite = new Color(0.980392, 0.921569, 0.843137, 1);
|
|
155
|
+
static aqua = new Color(0, 1, 1, 1);
|
|
156
|
+
static aquamarine = new Color(0.498039, 1, 0.831373, 1);
|
|
157
|
+
static azure = new Color(0.941176, 1, 1, 1);
|
|
158
|
+
static beige = new Color(0.960784, 0.960784, 0.862745, 1);
|
|
159
|
+
static bisque = new Color(1, 0.894118, 0.768627, 1);
|
|
160
|
+
static black = new Color(0, 0, 0, 1);
|
|
161
|
+
static blanchedAlmond = new Color(1, 0.921569, 0.803922, 1);
|
|
162
|
+
static blue = new Color(0, 0, 1, 1);
|
|
163
|
+
static blueViolet = new Color(0.541176, 0.168627, 0.886275, 1);
|
|
164
|
+
static brown = new Color(0.647059, 0.164706, 0.164706, 1);
|
|
165
|
+
static burlyWood = new Color(0.870588, 0.721569, 0.529412, 1);
|
|
166
|
+
static cadetBlue = new Color(0.372549, 0.619608, 0.627451, 1);
|
|
167
|
+
static chartreuse = new Color(0.498039, 1, 0, 1);
|
|
168
|
+
static chocolate = new Color(0.823529, 0.411765, 0.117647, 1);
|
|
169
|
+
static coral = new Color(1, 0.498039, 0.313725, 1);
|
|
170
|
+
static cornflowerBlue = new Color(0.392157, 0.584314, 0.929412, 1);
|
|
171
|
+
static cornsilk = new Color(0.882353, 0.972549, 0.862745, 1);
|
|
172
|
+
static crimson = new Color(0.862745, 0.078431, 0.235294, 1);
|
|
173
|
+
static cyan = new Color(0, 1, 1, 1);
|
|
174
|
+
static darkBlue = new Color(0, 0, 0.545098, 1);
|
|
175
|
+
static darkCyan = new Color(0, 0.545098, 0.545098, 1);
|
|
176
|
+
static darkGoldenrod = new Color(0.721569, 0.52549, 0.043137, 1);
|
|
177
|
+
static darkGray = new Color(0.662745, 0.662745, 0.662745, 1);
|
|
178
|
+
static darkGreen = new Color(0, 0.392157, 0, 1);
|
|
179
|
+
static darkKhaki = new Color(0.741176, 0.717647, 0.419608, 1);
|
|
180
|
+
static darkMagenta = new Color(0.545098, 0, 0.545098, 1);
|
|
181
|
+
static darkOliveGreen = new Color(0.333333, 0.419608, 0.184314, 1);
|
|
182
|
+
static darkOrange = new Color(1, 0.54902, 0, 1);
|
|
183
|
+
static darkOrchid = new Color(0.6, 0.196078, 0.8, 1);
|
|
184
|
+
static darkRed = new Color(0.545098, 0, 0, 1);
|
|
185
|
+
static darkSalmon = new Color(0.913725, 0.588235, 0.478431, 1);
|
|
186
|
+
static darkSeaGreen = new Color(0.560784, 0.737255, 0.560784, 1);
|
|
187
|
+
static darkSlateBlue = new Color(0.282353, 0.239216, 0.545098, 1);
|
|
188
|
+
static darkSlateGray = new Color(0.184314, 0.309804, 0.309804, 1);
|
|
189
|
+
static darkTurquoise = new Color(0, 0.807843, 0.819608, 1);
|
|
190
|
+
static darkViolet = new Color(0.580392, 0, 0.827451, 1);
|
|
191
|
+
static deepPink = new Color(1, 0.078431, 0.576471, 1);
|
|
192
|
+
static deepSkyBlue = new Color(0, 0.74902, 1, 1);
|
|
193
|
+
static dimGray = new Color(0.411765, 0.411765, 0.411765, 1);
|
|
194
|
+
static dodgerBlue = new Color(0.117647, 0.564706, 1, 1);
|
|
195
|
+
static fireBrick = new Color(0.698039, 0.133333, 0.133333, 1);
|
|
196
|
+
static floralWhite = new Color(1, 0.980392, 0.941176, 1);
|
|
197
|
+
static forestGreen = new Color(0.133333, 0.545098, 0.133333, 1);
|
|
198
|
+
static fuchsia = new Color(1, 0, 1, 1);
|
|
199
|
+
static gainsboro = new Color(0.862745, 0.862745, 0.862745, 1);
|
|
200
|
+
static ghostWhite = new Color(0.972549, 0.972549, 1, 1);
|
|
201
|
+
static gold = new Color(1, 0.843137, 0, 1);
|
|
202
|
+
static goldenrod = new Color(0.854902, 0.647059, 0.12549, 1);
|
|
203
|
+
static gray = new Color(0.501961, 0.501961, 0.501961, 1);
|
|
204
|
+
static green = new Color(0, 0.501961, 0, 1);
|
|
205
|
+
static greenYellow = new Color(0.678431, 1, 0.184314, 1);
|
|
206
|
+
static honeydew = new Color(0.941176, 1, 0.941176, 1);
|
|
207
|
+
static hotPink = new Color(1, 0.411765, 0.705882, 1);
|
|
208
|
+
static indianRed = new Color(0.803922, 0.360784, 0.360784, 1);
|
|
209
|
+
static indigo = new Color(0.294118, 0, 0.509804, 1);
|
|
210
|
+
static ivory = new Color(1, 1, 0.941176, 1);
|
|
211
|
+
static khaki = new Color(0.941176, 0.901961, 0.54902, 1);
|
|
212
|
+
static lavender = new Color(0.901961, 0.901961, 0.980392, 1);
|
|
213
|
+
static lavenderBlush = new Color(1, 0.941176, 0.960784, 1);
|
|
214
|
+
static lawnGreen = new Color(0.486275, 0.988235, 0, 1);
|
|
215
|
+
static lemonChiffon = new Color(1, 0.980392, 0.803922, 1);
|
|
216
|
+
static lightBlue = new Color(0.678431, 0.847059, 0.901961, 1);
|
|
217
|
+
static lightCoral = new Color(0.941176, 0.501961, 0.501961, 1);
|
|
218
|
+
static lightCyan = new Color(0.878431, 1, 1, 1);
|
|
219
|
+
static lightGoldenrodYellow = new Color(0.980392, 0.980392, 0.823529, 1);
|
|
220
|
+
static lightGreen = new Color(0.564706, 0.933333, 0.564706, 1);
|
|
221
|
+
static lightGrey = new Color(0.827451, 0.827451, 0.827451, 1);
|
|
222
|
+
static lightPink = new Color(1, 0.713725, 0.756863, 1);
|
|
223
|
+
static lightSalmon = new Color(1, 0.627451, 0.478431, 1);
|
|
224
|
+
static lightSeaGreen = new Color(0.12549, 0.698039, 0.666667, 1);
|
|
225
|
+
static lightSkyBlue = new Color(0.529412, 0.807843, 0.980392, 1);
|
|
226
|
+
static lightSlateGray = new Color(0.466667, 0.533333, 0.6, 1);
|
|
227
|
+
static lightSteelBlue = new Color(0.690196, 0.768627, 0.870588, 1);
|
|
228
|
+
static lightYellow = new Color(1, 1, 0.878431, 1);
|
|
229
|
+
static lime = new Color(0, 1, 0, 1);
|
|
230
|
+
static limeGreen = new Color(0.196078, 0.803922, 0.196078, 1);
|
|
231
|
+
static linen = new Color(0.980392, 0.941176, 0.901961, 1);
|
|
232
|
+
static magenta = new Color(1, 0, 1, 1);
|
|
233
|
+
static maroon = new Color(0.501961, 0, 0, 1);
|
|
234
|
+
static mediumAquamarine = new Color(0.4, 0.803922, 0.666667, 1);
|
|
235
|
+
static mediumBlue = new Color(0, 0, 0.803922, 1);
|
|
236
|
+
static mediumOrchid = new Color(0.729412, 0.333333, 0.827451, 1);
|
|
237
|
+
static mediumPurple = new Color(0.576471, 0.439216, 0.858824, 1);
|
|
238
|
+
static mediumSeaGreen = new Color(0.235294, 0.701961, 0.443137, 1);
|
|
239
|
+
static mediumSlateBlue = new Color(0.482353, 0.407843, 0.933333, 1);
|
|
240
|
+
static mediumSpringGreen = new Color(0, 0.980392, 0.603922, 1);
|
|
241
|
+
static mediumTurquoise = new Color(0.282353, 0.819608, 0.8, 1);
|
|
242
|
+
static mediumVioletRed = new Color(0.780392, 0.082353, 0.521569, 1);
|
|
243
|
+
static midnightBlue = new Color(0.098039, 0.098039, 0.439216, 1);
|
|
244
|
+
static mintCream = new Color(0.960784, 1, 0.980392, 1);
|
|
245
|
+
static mistyRose = new Color(1, 0.894118, 0.882353, 1);
|
|
246
|
+
static moccasin = new Color(1, 0.894118, 0.709804, 1);
|
|
247
|
+
static navajoWhite = new Color(1, 0.870588, 0.678431, 1);
|
|
248
|
+
static navy = new Color(0, 0, 0.501961, 1);
|
|
249
|
+
static oldLace = new Color(0.992157, 0.960784, 0.901961, 1);
|
|
250
|
+
static olive = new Color(0.501961, 0.501961, 0, 1);
|
|
251
|
+
static oliveDrab = new Color(0.419608, 0.556863, 0.137255, 1);
|
|
252
|
+
static orange = new Color(1, 0.647059, 0, 1);
|
|
253
|
+
static orangeRed = new Color(1, 0.270588, 0, 1);
|
|
254
|
+
static orchid = new Color(0.854902, 0.439216, 0.839216, 1);
|
|
255
|
+
static paleGoldenrod = new Color(0.933333, 0.909804, 0.666667, 1);
|
|
256
|
+
static paleGreen = new Color(0.596078, 0.984314, 0.596078, 1);
|
|
257
|
+
static paleTurquoise = new Color(0.686275, 0.933333, 0.933333, 1);
|
|
258
|
+
static paleVioletRed = new Color(0.858824, 0.439216, 0.576471, 1);
|
|
259
|
+
static papayaWhip = new Color(1, 0.937255, 0.835294, 1);
|
|
260
|
+
static peachPuff = new Color(1, 0.854902, 0.72549, 1);
|
|
261
|
+
static peru = new Color(0.803922, 0.521569, 0.247059, 1);
|
|
262
|
+
static pink = new Color(1, 0.752941, 0.796078, 1);
|
|
263
|
+
static plum = new Color(0.866667, 0.627451, 0.866667, 1);
|
|
264
|
+
static powderBlue = new Color(0.690196, 0.878431, 0.901961, 1);
|
|
265
|
+
static purple = new Color(0.501961, 0, 0.501961, 1);
|
|
266
|
+
static red = new Color(1, 0, 0, 1);
|
|
267
|
+
static rosyBrown = new Color(0.737255, 0.560784, 0.560784, 1);
|
|
268
|
+
static royalBlue = new Color(0.254902, 0.411765, 0.882353, 1);
|
|
269
|
+
static saddleBrown = new Color(0.545098, 0.270588, 0.07451, 1);
|
|
270
|
+
static salmon = new Color(0.980392, 0.501961, 0.447059, 1);
|
|
271
|
+
static sandyBrown = new Color(0.956863, 0.643137, 0.376471, 1);
|
|
272
|
+
static seaGreen = new Color(0.180392, 0.545098, 0.380392, 1);
|
|
273
|
+
static seashell = new Color(1, 0.960784, 0.933333, 1);
|
|
274
|
+
static sienna = new Color(0.627451, 0.321569, 0.176471, 1);
|
|
275
|
+
static silver = new Color(0.752941, 0.752941, 0.752941, 1);
|
|
276
|
+
static skyBlue = new Color(0.529412, 0.807843, 0.921569, 1);
|
|
277
|
+
static slateBlue = new Color(0.415686, 0.352941, 0.803922, 1);
|
|
278
|
+
static slateGray = new Color(0.466667, 0.533333, 0.6, 1);
|
|
279
|
+
static snow = new Color(1, 0.980392, 0.980392, 1);
|
|
280
|
+
static springGreen = new Color(0, 1, 0.498039, 1);
|
|
281
|
+
static steelBlue = new Color(0.27451, 0.509804, 0.705882, 1);
|
|
282
|
+
static tan = new Color(0.823529, 0.705882, 0.54902, 1);
|
|
283
|
+
static teal = new Color(0, 0.501961, 0.501961, 1);
|
|
284
|
+
static thistle = new Color(0.847059, 0.74902, 0.847059, 1);
|
|
285
|
+
static tomato = new Color(1, 0.388235, 0.278431, 1);
|
|
286
|
+
static transparent = new Color(0, 0, 0, 0);
|
|
287
|
+
static turquoise = new Color(0.25098, 0.878431, 0.815686, 1);
|
|
288
|
+
static violet = new Color(0.933333, 0.509804, 0.933333, 1);
|
|
289
|
+
static wheat = new Color(0.960784, 0.870588, 0.701961, 1);
|
|
290
|
+
static white = new Color(1, 1, 1, 1);
|
|
291
|
+
static whiteSmoke = new Color(0.960784, 0.960784, 0.960784, 1);
|
|
292
|
+
static yellow = new Color(1, 1, 0, 1);
|
|
293
|
+
static yellowGreen = new Color(0.603922, 0.803922, 0.196078, 1);
|
|
294
|
+
static names = ["aliceBlue", "antiqueWhite", "aqua", "aquamarine", "azure", "beige", "bisque", "black", "blanchedAlmond", "blue", "blueViolet", "brown", "burlyWood", "cadetBlue", "chartreuse", "chocolate", "coral", "cornflowerBlue", "cornsilk", "crimson", "cyan", "darkBlue", "darkCyan", "darkGoldenrod", "darkGray", "darkGreen", "darkKhaki", "darkMagenta", "darkOliveGreen", "darkOrange", "darkOrchid", "darkRed", "darkSalmon", "darkSeaGreen", "darkSlateBlue", "darkSlateGray", "darkTurquoise", "darkViolet", "deepPink", "deepSkyBlue", "dimGray", "dodgerBlue", "fireBrick", "floralWhite", "forestGreen", "fuchsia", "gainsboro", "ghostWhite", "gold", "goldenrod", "gray", "green", "greenYellow", "honeydew", "hotPink", "indianRed", "indigo", "ivory", "khaki", "lavender", "lavenderBlush", "lawnGreen", "lemonChiffon", "lightBlue", "lightCoral", "lightCyan", "lightGoldenrodYellow", "lightGreen", "lightGrey", "lightPink", "lightSalmon", "lightSeaGreen", "lightSkyBlue", "lightSlateGray", "lightSteelBlue", "lightYellow", "lime", "limeGreen", "linen", "magenta", "maroon", "mediumAquamarine", "mediumBlue", "mediumOrchid", "mediumPurple", "mediumSeaGreen", "mediumSlateBlue", "mediumSpringGreen", "mediumTurquoise", "mediumVioletRed", "midnightBlue", "mintCream", "mistyRose", "moccasin", "navajoWhite", "navy", "oldLace", "olive", "oliveDrab", "orange", "orangeRed", "orchid", "paleGoldenrod", "paleGreen", "paleTurquoise", "paleVioletRed", "papayaWhip", "peachPuff", "peru", "pink", "plum", "powderBlue", "purple", "red", "rosyBrown", "royalBlue", "saddleBrown", "salmon", "sandyBrown", "seaGreen", "seashell", "sienna", "silver", "skyBlue", "slateBlue", "slateGray", "snow", "springGreen", "steelBlue", "tan", "teal", "thistle", "tomato", "transparent", "turquoise", "violet", "wheat", "white", "whiteSmoke", "yellow", "yellowGreen"];
|
|
295
|
+
static get colors() {
|
|
296
|
+
if (_colors === undefined) {
|
|
297
|
+
_colors = {};
|
|
298
|
+
const _c = _colors;
|
|
299
|
+
const o = Color;
|
|
300
|
+
Color.names.forEach((name) => {
|
|
301
|
+
_c[name] = o[name];
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
return _colors;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// src/terminal.ts
|
|
309
|
+
import { format } from "node:util";
|
|
310
|
+
|
|
311
|
+
class TerminalCore {
|
|
312
|
+
writer;
|
|
313
|
+
plain;
|
|
314
|
+
constructor(writer, options = {}) {
|
|
315
|
+
this.writer = writer;
|
|
316
|
+
const envNoColor = typeof process !== "undefined" && !!process?.env?.NO_COLOR;
|
|
317
|
+
this.plain = options.plain ?? envNoColor;
|
|
318
|
+
}
|
|
319
|
+
emit(data) {
|
|
320
|
+
this.writer.write(data);
|
|
321
|
+
}
|
|
322
|
+
style(seq, fmt, args) {
|
|
323
|
+
const text = format(fmt, ...args);
|
|
324
|
+
this.emit(this.plain ? text : seq + text);
|
|
325
|
+
return this;
|
|
326
|
+
}
|
|
327
|
+
print(fmt = "", ...args) {
|
|
328
|
+
this.emit(format(fmt, ...args));
|
|
329
|
+
return this;
|
|
330
|
+
}
|
|
331
|
+
println(fmt = "", ...args) {
|
|
332
|
+
this.emit(format(fmt, ...args) + `\r
|
|
333
|
+
`);
|
|
334
|
+
return this;
|
|
335
|
+
}
|
|
336
|
+
ink(c, fmt = "", ...args) {
|
|
337
|
+
const color = typeof c === "string" ? new Color(c) : c;
|
|
338
|
+
return this.style(color.toAnsiRGB(), fmt, args);
|
|
339
|
+
}
|
|
340
|
+
paper(c, fmt = "", ...args) {
|
|
341
|
+
const color = typeof c === "string" ? new Color(c) : c;
|
|
342
|
+
return this.style(color.toAnsiBackgroundRGB(), fmt, args);
|
|
343
|
+
}
|
|
344
|
+
reset(fmt = "", ...args) {
|
|
345
|
+
return this.style("\x1B[0m", fmt, args);
|
|
346
|
+
}
|
|
347
|
+
resetInk(fmt = "", ...args) {
|
|
348
|
+
return this.style("\x1B[39m", fmt, args);
|
|
349
|
+
}
|
|
350
|
+
resetPaper(fmt = "", ...args) {
|
|
351
|
+
return this.style("\x1B[49m", fmt, args);
|
|
352
|
+
}
|
|
353
|
+
cls() {
|
|
354
|
+
this.emit("\x1B[2J\x1B[H");
|
|
355
|
+
return this;
|
|
356
|
+
}
|
|
357
|
+
clearLine() {
|
|
358
|
+
this.emit("\x1B[K");
|
|
359
|
+
return this;
|
|
360
|
+
}
|
|
361
|
+
up(n = 1) {
|
|
362
|
+
this.emit(`\x1B[${n}A`);
|
|
363
|
+
return this;
|
|
364
|
+
}
|
|
365
|
+
down(n = 1) {
|
|
366
|
+
this.emit(`\x1B[${n}B`);
|
|
367
|
+
return this;
|
|
368
|
+
}
|
|
369
|
+
right(n = 1) {
|
|
370
|
+
this.emit(`\x1B[${n}C`);
|
|
371
|
+
return this;
|
|
372
|
+
}
|
|
373
|
+
left(n = 1) {
|
|
374
|
+
this.emit(`\x1B[${n}D`);
|
|
375
|
+
return this;
|
|
376
|
+
}
|
|
377
|
+
column(n = 1) {
|
|
378
|
+
this.emit(`\x1B[${n}G`);
|
|
379
|
+
return this;
|
|
380
|
+
}
|
|
381
|
+
row(n = 1) {
|
|
382
|
+
this.emit(`\x1B[${n}d`);
|
|
383
|
+
return this;
|
|
384
|
+
}
|
|
385
|
+
moveTo(row, col) {
|
|
386
|
+
this.emit(`\x1B[${row};${col}H`);
|
|
387
|
+
return this;
|
|
388
|
+
}
|
|
389
|
+
saveCursor() {
|
|
390
|
+
this.emit("\x1B[s");
|
|
391
|
+
return this;
|
|
392
|
+
}
|
|
393
|
+
restoreCursor() {
|
|
394
|
+
this.emit("\x1B[u");
|
|
395
|
+
return this;
|
|
396
|
+
}
|
|
397
|
+
cursor(visible = true) {
|
|
398
|
+
this.emit(visible ? "\x1B[?25h" : "\x1B[?25l");
|
|
399
|
+
return this;
|
|
400
|
+
}
|
|
401
|
+
alt(b = true) {
|
|
402
|
+
this.emit(`\x1B[?1049${b ? "h" : "l"}`);
|
|
403
|
+
return this;
|
|
404
|
+
}
|
|
405
|
+
autoWrap(b = true) {
|
|
406
|
+
this.emit(`\x1B[?7${b ? "h" : "l"}`);
|
|
407
|
+
return this;
|
|
408
|
+
}
|
|
409
|
+
scrollRegion(top, bottom) {
|
|
410
|
+
this.emit(`\x1B[${top};${bottom}r`);
|
|
411
|
+
return this;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
function installColorMethods() {
|
|
415
|
+
const proto = TerminalCore.prototype;
|
|
416
|
+
const cap = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
417
|
+
for (const key of Object.keys(Color)) {
|
|
418
|
+
const value = Color[key];
|
|
419
|
+
if (!(value instanceof Color))
|
|
420
|
+
continue;
|
|
421
|
+
const name = key;
|
|
422
|
+
proto[name] = function(fmt = "", ...args) {
|
|
423
|
+
return this.ink(value, fmt, ...args);
|
|
424
|
+
};
|
|
425
|
+
proto[`bg${cap(name)}`] = function(fmt = "", ...args) {
|
|
426
|
+
return this.paper(value, fmt, ...args);
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
installColorMethods();
|
|
431
|
+
function createTerminal(writer, options = {}) {
|
|
432
|
+
return new TerminalCore(writer, options);
|
|
433
|
+
}
|
|
434
|
+
export {
|
|
435
|
+
createTerminal,
|
|
436
|
+
TerminalCore
|
|
437
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@retrovm/terminal",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Fluent ANSI terminal library — 24-bit color, cursor control and screen management for Bun and Node.js",
|
|
5
5
|
"author": "Juan Carlos González Amestoy",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,18 +20,29 @@
|
|
|
20
20
|
},
|
|
21
21
|
"type": "module",
|
|
22
22
|
"module": "src/terminal.ts",
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "bun build src/terminal.ts src/node.ts --outdir dist --target node && tsc -p tsconfig.build.json",
|
|
25
|
+
"prepublishOnly": "bun run build"
|
|
26
|
+
},
|
|
23
27
|
"exports": {
|
|
24
28
|
".": {
|
|
25
29
|
"bun": "./src/bun.ts",
|
|
26
|
-
"
|
|
27
|
-
|
|
30
|
+
"node": {
|
|
31
|
+
"types": "./dist/node.d.ts",
|
|
32
|
+
"default": "./dist/node.js"
|
|
33
|
+
},
|
|
34
|
+
"types": "./dist/node.d.ts",
|
|
35
|
+
"import": "./dist/terminal.js"
|
|
28
36
|
}
|
|
29
37
|
},
|
|
30
38
|
"files": [
|
|
31
|
-
"src"
|
|
39
|
+
"src",
|
|
40
|
+
"dist"
|
|
32
41
|
],
|
|
33
42
|
"devDependencies": {
|
|
34
|
-
"@types/bun": "latest"
|
|
43
|
+
"@types/bun": "latest",
|
|
44
|
+
"@types/node": "^25.8.0",
|
|
45
|
+
"typescript": "^5"
|
|
35
46
|
},
|
|
36
47
|
"peerDependencies": {
|
|
37
48
|
"typescript": "^5"
|