@gesslar/toolkit 3.29.0 → 3.30.0
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/package.json +1 -1
- package/src/node/lib/Term.js +44 -25
- package/types/node/lib/Term.d.ts +36 -23
- package/types/node/lib/Term.d.ts.map +1 -1
package/package.json
CHANGED
package/src/node/lib/Term.js
CHANGED
|
@@ -3,9 +3,29 @@ import process from "node:process"
|
|
|
3
3
|
import {Writable} from "node:stream"
|
|
4
4
|
import supportsColor from "supports-color"
|
|
5
5
|
import {stripVTControlCharacters} from "node:util"
|
|
6
|
+
import c from "@gesslar/colours"
|
|
6
7
|
|
|
7
8
|
import Sass from "./Sass.js"
|
|
8
9
|
|
|
10
|
+
c.alias.set("success", "{F035}")
|
|
11
|
+
c.alias.set("info", "{F033}")
|
|
12
|
+
c.alias.set("warn", "{F208}")
|
|
13
|
+
c.alias.set("error", "{F032}")
|
|
14
|
+
c.alias.set("modified", "{F147}")
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Terminal output utilities with ANSI colour support.
|
|
18
|
+
*
|
|
19
|
+
* Provides console logging wrappers, cursor control, and formatted message
|
|
20
|
+
* output with colour styling via `@gesslar/colours`.
|
|
21
|
+
*
|
|
22
|
+
* Predefined colour aliases:
|
|
23
|
+
* - `success` - green (F035)
|
|
24
|
+
* - `info` - blue (F033)
|
|
25
|
+
* - `warn` - orange (F208)
|
|
26
|
+
* - `error` - red (F032)
|
|
27
|
+
* - `modified` - purple (F147)
|
|
28
|
+
*/
|
|
9
29
|
export default class Term {
|
|
10
30
|
static #cache = new Map()
|
|
11
31
|
|
|
@@ -217,17 +237,17 @@ export default class Term {
|
|
|
217
237
|
}
|
|
218
238
|
|
|
219
239
|
/**
|
|
220
|
-
* Constructs a formatted status line.
|
|
240
|
+
* Constructs a formatted status line with optional colour styling.
|
|
221
241
|
*
|
|
222
242
|
* Input forms:
|
|
223
243
|
* - string: printed as-is
|
|
224
244
|
* - array: each element is either:
|
|
225
245
|
* - a plain string (emitted unchanged), or
|
|
226
|
-
* - a tuple: [
|
|
227
|
-
* (e.g. success, info, warn, error, modified)
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
246
|
+
* - a tuple: [colourCode, text] where `colourCode` is a colour alias
|
|
247
|
+
* (e.g. success, info, warn, error, modified) or any valid
|
|
248
|
+
* `@gesslar/colours` format string.
|
|
249
|
+
* - a tuple: [colourCode, text, [openBracket, closeBracket]] for custom
|
|
250
|
+
* brackets around the colourised text.
|
|
231
251
|
*
|
|
232
252
|
* The function performs a shallow validation: tuple elements must both be
|
|
233
253
|
* strings; otherwise a TypeError is thrown. Nested arrays beyond depth 1 are
|
|
@@ -236,8 +256,8 @@ export default class Term {
|
|
|
236
256
|
* Recursion: array input is normalised into a single string then re-dispatched
|
|
237
257
|
* through `status` to leverage the string branch (keeps logic DRY).
|
|
238
258
|
*
|
|
239
|
-
* @param {string | Array<string | [string, string] | [string, string, string]>} argList - Message spec.
|
|
240
|
-
* @returns {
|
|
259
|
+
* @param {string | Array<string | [string, string] | [string, string, [string, string]]>} argList - Message spec.
|
|
260
|
+
* @returns {string} The formatted message string.
|
|
241
261
|
*/
|
|
242
262
|
static terminalMessage(argList) {
|
|
243
263
|
if(typeof argList === "string")
|
|
@@ -269,34 +289,33 @@ export default class Term {
|
|
|
269
289
|
|
|
270
290
|
/**
|
|
271
291
|
* Construct a single coloured bracketed segment from a tuple specifying
|
|
272
|
-
* the
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
* element is the raw text to display.
|
|
292
|
+
* the colour code and text. The first element is a colour code that can be
|
|
293
|
+
* a predefined alias (success, info, warn, error, modified) or any valid
|
|
294
|
+
* `@gesslar/colours` format string. The brackets are coloured while the
|
|
295
|
+
* inner text remains uncoloured.
|
|
277
296
|
*
|
|
278
|
-
* Input validation:
|
|
279
|
-
*
|
|
280
|
-
* ignored – the method destructures only the first pair.)
|
|
297
|
+
* Input validation: colourCode and text must both be strings; otherwise
|
|
298
|
+
* a `Sass` error is thrown.
|
|
281
299
|
*
|
|
282
300
|
* Example:
|
|
283
|
-
* terminalBracket(["success", "COMPILED"]) → "[COMPILED]" with
|
|
284
|
-
* brackets
|
|
285
|
-
*
|
|
301
|
+
* terminalBracket(["success", "COMPILED"]) → "[COMPILED]" with green
|
|
302
|
+
* brackets (assuming colour support is available in the terminal).
|
|
303
|
+
*
|
|
304
|
+
* terminalBracket(["info", "STATUS", ["<", ">"]]) → "<STATUS>" with blue
|
|
305
|
+
* angle brackets.
|
|
286
306
|
*
|
|
287
307
|
* This method does not append trailing spaces; callers are responsible for
|
|
288
308
|
* joining multiple segments with appropriate separators.
|
|
289
309
|
*
|
|
290
|
-
* @param {
|
|
310
|
+
* @param {[string, string, [string, string]?]} parts - Tuple: [colourCode, text, brackets?].
|
|
291
311
|
* @returns {string} Colourised bracketed segment (e.g. "[TEXT]").
|
|
292
|
-
* @throws {Sass} If
|
|
312
|
+
* @throws {Sass} If colourCode or text is not a string.
|
|
293
313
|
*/
|
|
294
|
-
static terminalBracket([
|
|
295
|
-
if(!(typeof
|
|
314
|
+
static terminalBracket([colourCode="", text, brackets=["[","]"]]) {
|
|
315
|
+
if(!(typeof colourCode === "string" && typeof text === "string"))
|
|
296
316
|
throw Sass.new("Each element must be a string.")
|
|
297
317
|
|
|
298
|
-
|
|
299
|
-
return `${brackets[0]}${text}${brackets[1]}`
|
|
318
|
+
return this.#preformat(c`{${colourCode}}${brackets[0]}{/}${text}{${colourCode}}${brackets[1]}{/}`)
|
|
300
319
|
}
|
|
301
320
|
|
|
302
321
|
/**
|
package/types/node/lib/Term.d.ts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Terminal output utilities with ANSI colour support.
|
|
3
|
+
*
|
|
4
|
+
* Provides console logging wrappers, cursor control, and formatted message
|
|
5
|
+
* output with colour styling via `@gesslar/colours`.
|
|
6
|
+
*
|
|
7
|
+
* Predefined colour aliases:
|
|
8
|
+
* - `success` - green (F035)
|
|
9
|
+
* - `info` - blue (F033)
|
|
10
|
+
* - `warn` - orange (F208)
|
|
11
|
+
* - `error` - red (F032)
|
|
12
|
+
* - `modified` - purple (F147)
|
|
13
|
+
*/
|
|
1
14
|
export default class Term {
|
|
2
15
|
static "__#private@#cache": Map<any, any>;
|
|
3
16
|
static "__#private@#preformat"(text: any): any;
|
|
@@ -107,17 +120,17 @@ export default class Term {
|
|
|
107
120
|
silent: boolean;
|
|
108
121
|
}): void;
|
|
109
122
|
/**
|
|
110
|
-
* Constructs a formatted status line.
|
|
123
|
+
* Constructs a formatted status line with optional colour styling.
|
|
111
124
|
*
|
|
112
125
|
* Input forms:
|
|
113
126
|
* - string: printed as-is
|
|
114
127
|
* - array: each element is either:
|
|
115
128
|
* - a plain string (emitted unchanged), or
|
|
116
|
-
* - a tuple: [
|
|
117
|
-
* (e.g. success, info, warn, error, modified)
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
129
|
+
* - a tuple: [colourCode, text] where `colourCode` is a colour alias
|
|
130
|
+
* (e.g. success, info, warn, error, modified) or any valid
|
|
131
|
+
* `@gesslar/colours` format string.
|
|
132
|
+
* - a tuple: [colourCode, text, [openBracket, closeBracket]] for custom
|
|
133
|
+
* brackets around the colourised text.
|
|
121
134
|
*
|
|
122
135
|
* The function performs a shallow validation: tuple elements must both be
|
|
123
136
|
* strings; otherwise a TypeError is thrown. Nested arrays beyond depth 1 are
|
|
@@ -126,35 +139,35 @@ export default class Term {
|
|
|
126
139
|
* Recursion: array input is normalised into a single string then re-dispatched
|
|
127
140
|
* through `status` to leverage the string branch (keeps logic DRY).
|
|
128
141
|
*
|
|
129
|
-
* @param {string | Array<string | [string, string] | [string, string, string]>} argList - Message spec.
|
|
130
|
-
* @returns {
|
|
142
|
+
* @param {string | Array<string | [string, string] | [string, string, [string, string]]>} argList - Message spec.
|
|
143
|
+
* @returns {string} The formatted message string.
|
|
131
144
|
*/
|
|
132
|
-
static terminalMessage(argList: string | Array<string | [string, string] | [string, string, string]>):
|
|
145
|
+
static terminalMessage(argList: string | Array<string | [string, string] | [string, string, [string, string]]>): string;
|
|
133
146
|
/**
|
|
134
147
|
* Construct a single coloured bracketed segment from a tuple specifying
|
|
135
|
-
* the
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
* element is the raw text to display.
|
|
148
|
+
* the colour code and text. The first element is a colour code that can be
|
|
149
|
+
* a predefined alias (success, info, warn, error, modified) or any valid
|
|
150
|
+
* `@gesslar/colours` format string. The brackets are coloured while the
|
|
151
|
+
* inner text remains uncoloured.
|
|
140
152
|
*
|
|
141
|
-
* Input validation:
|
|
142
|
-
*
|
|
143
|
-
* ignored – the method destructures only the first pair.)
|
|
153
|
+
* Input validation: colourCode and text must both be strings; otherwise
|
|
154
|
+
* a `Sass` error is thrown.
|
|
144
155
|
*
|
|
145
156
|
* Example:
|
|
146
|
-
* terminalBracket(["success", "COMPILED"]) → "[COMPILED]" with
|
|
147
|
-
* brackets
|
|
148
|
-
*
|
|
157
|
+
* terminalBracket(["success", "COMPILED"]) → "[COMPILED]" with green
|
|
158
|
+
* brackets (assuming colour support is available in the terminal).
|
|
159
|
+
*
|
|
160
|
+
* terminalBracket(["info", "STATUS", ["<", ">"]]) → "<STATUS>" with blue
|
|
161
|
+
* angle brackets.
|
|
149
162
|
*
|
|
150
163
|
* This method does not append trailing spaces; callers are responsible for
|
|
151
164
|
* joining multiple segments with appropriate separators.
|
|
152
165
|
*
|
|
153
|
-
* @param {
|
|
166
|
+
* @param {[string, string, [string, string]?]} parts - Tuple: [colourCode, text, brackets?].
|
|
154
167
|
* @returns {string} Colourised bracketed segment (e.g. "[TEXT]").
|
|
155
|
-
* @throws {Sass} If
|
|
168
|
+
* @throws {Sass} If colourCode or text is not a string.
|
|
156
169
|
*/
|
|
157
|
-
static terminalBracket([
|
|
170
|
+
static terminalBracket([colourCode, text, brackets]: [string, string, [string, string]?]): string;
|
|
158
171
|
/**
|
|
159
172
|
* ANSI escape sequence to move cursor to start of line.
|
|
160
173
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Term.d.ts","sourceRoot":"","sources":["../../../src/node/lib/Term.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Term.d.ts","sourceRoot":"","sources":["../../../src/node/lib/Term.js"],"names":[],"mappings":"AAeA;;;;;;;;;;;;GAYG;AACH;IACE,0CAAyB;IAEzB,+CAIC;IAED;;;;OAIG;IACH,sBAFU,MAAM,GAAG,SAAS,CAI3B;IAED;;;;OAIG;IACH,mBAFU,MAAM,GAAG,SAAS,CAI3B;IAED;;;;OAIG;IACH,kBAFU;QAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;QAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAA;KAAC,CAIhE;IAED;;;;OAIG;IACH,4BAFU,OAAO,CAMhB;IAED;;;;OAIG;IACH,uBAFU,OAAO,CAMhB;IAED;;;;OAIG;IACH,oBAFc,OAAO,EAAA,QAIpB;IAED;;;;OAIG;IACH,qBAFc,OAAO,EAAA,QAIpB;IAED;;;;OAIG;IACH,qBAFc,OAAO,EAAA,QAIpB;IAED;;;;OAIG;IACH,sBAFc,OAAO,EAAA,QAIpB;IAED;;;;OAIG;IACH,sBAFc,OAAO,EAAA,QAIpB;IAED;;;;OAIG;IACH,sBAFc,OAAO,EAAA,QAIpB;IAED;;OAEG;IACH,wBAEC;IAED;;;;;;;;OAQG;IACH,0BANW,MAAM,QAAQ,YAEtB;QAAgC,UAAU,GAAlC,KAAK,CAAC,MAAM,CAAC;QACK,UAAU,GAA5B,OAAO;QACW,aAAa,GAA/B,OAAO;KACjB,QA2DA;IAED;;;;;;;;;;;;;;OAcG;IACH,oBALW,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,eAEjD;QAAyB,MAAM,EAAvB,OAA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