@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 CHANGED
@@ -5,7 +5,7 @@
5
5
  "name": "gesslar",
6
6
  "url": "https://gesslar.dev"
7
7
  },
8
- "version": "3.29.0",
8
+ "version": "3.30.0",
9
9
  "license": "Unlicense",
10
10
  "homepage": "https://github.com/gesslar/toolkit#readme",
11
11
  "repository": {
@@ -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: [level, text] where `level` maps to an ansiColors alias
227
- * (e.g. success, info, warn, error, modified).
228
- * - a tuple: [level, text, [openBracket,closeBracket]] where `level` maps to an ansiColors alias
229
- * (e.g. success, info, warn, error, modified). These are rendered as
230
- * colourised bracketed segments: [TEXT].
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 {void}
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 style level and the text. The first element ("level") maps to an
273
- * `ansiColors` alias (e.g. success, info, warn, error, modified) and is
274
- * used both for the inner text colour and to locate its matching
275
- * "-bracket" alias for the surrounding square brackets. The second
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: every element of `parts` must be a string; otherwise
279
- * an `Sass` error is thrown. (Additional elements beyond the first two are
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 coloured
284
- * brackets + inner text (assuming colour support is available in the
285
- * terminal).
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 {Array<string>} parts - Tuple: [level, text]. Additional entries ignored.
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 any element of `parts` is not a string.
312
+ * @throws {Sass} If colourCode or text is not a string.
293
313
  */
294
- static terminalBracket([level, text, brackets=["[","]"]]) {
295
- if(!(typeof level === "string" && typeof text === "string"))
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
- // Simplified version without color support - just return bracketed text
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
  /**
@@ -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: [level, text] where `level` maps to an ansiColors alias
117
- * (e.g. success, info, warn, error, modified).
118
- * - a tuple: [level, text, [openBracket,closeBracket]] where `level` maps to an ansiColors alias
119
- * (e.g. success, info, warn, error, modified). These are rendered as
120
- * colourised bracketed segments: [TEXT].
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 {void}
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]>): void;
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 style level and the text. The first element ("level") maps to an
136
- * `ansiColors` alias (e.g. success, info, warn, error, modified) and is
137
- * used both for the inner text colour and to locate its matching
138
- * "-bracket" alias for the surrounding square brackets. The second
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: every element of `parts` must be a string; otherwise
142
- * an `Sass` error is thrown. (Additional elements beyond the first two are
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 coloured
147
- * brackets + inner text (assuming colour support is available in the
148
- * terminal).
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 {Array<string>} parts - Tuple: [level, text]. Additional entries ignored.
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 any element of `parts` is not a string.
168
+ * @throws {Sass} If colourCode or text is not a string.
156
169
  */
157
- static terminalBracket([level, text, brackets]: Array<string>): string;
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":"AAQA;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,EA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