console-toolkit 1.2.15 → 1.3.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/README.md +3 -0
- package/llms-full.txt +64 -4
- package/package.json +6 -6
- package/src/alphanumeric/arrows.js +0 -23
- package/src/alphanumeric/fractions.js +0 -49
- package/src/alphanumeric/number-formatters.js +0 -44
- package/src/alphanumeric/roman.js +0 -12
- package/src/alphanumeric/unicode-cultural-numbers.js +0 -1
- package/src/alphanumeric/unicode-letters.js +0 -8
- package/src/alphanumeric/unicode-numbers.js +0 -21
- package/src/alphanumeric/utils.js +0 -26
- package/src/ansi/csi.js +0 -49
- package/src/ansi/sgr-state.js +7 -50
- package/src/ansi/sgr.js +0 -420
- package/src/box.d.ts +4 -1
- package/src/box.js +15 -115
- package/src/charts/bars/block-frac-grouped.js +0 -6
- package/src/charts/bars/block-frac.js +1 -14
- package/src/charts/bars/block-grouped.js +0 -6
- package/src/charts/bars/block.js +1 -14
- package/src/charts/bars/draw-grouped.js +0 -4
- package/src/charts/bars/draw-stacked.js +0 -4
- package/src/charts/bars/frac-grouped.js +2 -14
- package/src/charts/bars/plain-grouped.js +0 -6
- package/src/charts/bars/plain.js +1 -28
- package/src/charts/columns/block-frac-grouped.js +0 -6
- package/src/charts/columns/block-frac.js +0 -13
- package/src/charts/columns/block-grouped.js +0 -6
- package/src/charts/columns/block.js +0 -13
- package/src/charts/columns/draw-grouped.js +1 -5
- package/src/charts/columns/draw-stacked.js +0 -4
- package/src/charts/columns/frac-grouped.js +1 -13
- package/src/charts/columns/plain-grouped.js +0 -6
- package/src/charts/columns/plain.js +0 -13
- package/src/charts/themes/default.js +0 -1
- package/src/charts/themes/rainbow-reversed.js +0 -1
- package/src/charts/themes/rainbow.js +0 -1
- package/src/charts/utils.js +2 -28
- package/src/draw-block-frac.js +0 -14
- package/src/draw-block.js +0 -24
- package/src/meta.js +0 -64
- package/src/output/show.d.ts +8 -3
- package/src/output/show.js +7 -38
- package/src/output/updater.d.ts +8 -3
- package/src/output/updater.js +4 -51
- package/src/output/writer.js +1 -53
- package/src/panel.d.ts +16 -10
- package/src/panel.js +21 -276
- package/src/plot/bitmap.js +5 -33
- package/src/plot/draw-line.js +0 -8
- package/src/plot/draw-rect.js +25 -103
- package/src/plot/index.js +0 -22
- package/src/plot/to-quads.js +3 -6
- package/src/spinner/spin.js +23 -20
- package/src/spinner/spinner.d.ts +16 -2
- package/src/spinner/spinner.js +22 -34
- package/src/spinner/spinners.js +0 -16
- package/src/strings/clip.js +0 -10
- package/src/strings/parse.js +0 -7
- package/src/strings/split.js +0 -15
- package/src/strings.d.ts +2 -0
- package/src/strings.js +2 -32
- package/src/style.js +2 -58
- package/src/symbols.js +0 -84
- package/src/table/draw-borders.js +0 -9
- package/src/table/index.d.ts +1 -1
- package/src/table/index.js +0 -1
- package/src/table/table.js +3 -58
- package/src/themes/blocks/unicode-half.js +0 -1
- package/src/themes/blocks/unicode-thin.js +0 -1
- package/src/themes/lines/ascii-compact.js +5 -9
- package/src/themes/lines/ascii-dots.js +2 -7
- package/src/themes/lines/ascii-girder.js +4 -7
- package/src/themes/lines/ascii-github.js +5 -9
- package/src/themes/lines/ascii-reddit.js +5 -9
- package/src/themes/lines/ascii-rounded.js +5 -9
- package/src/themes/lines/ascii.js +5 -9
- package/src/themes/lines/unicode-bold.js +8 -14
- package/src/themes/lines/unicode-rounded.js +8 -14
- package/src/themes/lines/unicode.js +8 -14
- package/src/themes/utils.d.ts +6 -0
- package/src/themes/utils.js +6 -7
- package/src/turtle/draw-line-art.js +26 -18
- package/src/turtle/draw-unicode.js +0 -8
- package/src/turtle/index.d.ts +1 -1
- package/src/turtle/index.js +0 -8
- package/src/turtle/turtle.js +0 -120
package/src/strings/split.js
CHANGED
|
@@ -18,14 +18,6 @@ if (!globalThis.Bun) {
|
|
|
18
18
|
|
|
19
19
|
const segmenter = new Intl.Segmenter();
|
|
20
20
|
|
|
21
|
-
/** Splits a string into graphemes (individual symbols) and calculates its display width.
|
|
22
|
-
* Optionally detects double-width characters using `emoji-regex` and `get-east-asian-width` if available.
|
|
23
|
-
* @param {string} s - The string to split.
|
|
24
|
-
* @param {object} [options] - Options.
|
|
25
|
-
* @param {boolean} [options.ignoreControlSymbols=false] - If true, control symbols are ignored.
|
|
26
|
-
* @param {boolean} [options.ambiguousAsWide=false] - If true, ambiguous East Asian characters are treated as double-wide.
|
|
27
|
-
* @returns {{graphemes: {symbol: string, width: number}[], width: number}} The graphemes and total display width.
|
|
28
|
-
*/
|
|
29
21
|
export const split = (s, options = {}) => {
|
|
30
22
|
s = String(s);
|
|
31
23
|
if (!s) return {graphemes: [], width: 0};
|
|
@@ -74,13 +66,6 @@ export const split = (s, options = {}) => {
|
|
|
74
66
|
return {graphemes, width};
|
|
75
67
|
};
|
|
76
68
|
|
|
77
|
-
/** Calculates the display width of a string, accounting for double-width characters.
|
|
78
|
-
* @param {string} s - The string to measure.
|
|
79
|
-
* @param {object} [options] - Options.
|
|
80
|
-
* @param {boolean} [options.ignoreControlSymbols=false] - If true, control symbols are ignored.
|
|
81
|
-
* @param {boolean} [options.ambiguousAsWide=false] - If true, ambiguous East Asian characters are treated as double-wide.
|
|
82
|
-
* @returns {number} The display width of the string.
|
|
83
|
-
*/
|
|
84
69
|
export const size = (s, options = {}) => {
|
|
85
70
|
s = String(s);
|
|
86
71
|
if (!s) return 0;
|
package/src/strings.d.ts
CHANGED
package/src/strings.js
CHANGED
|
@@ -2,12 +2,6 @@ import {size} from './strings/split.js';
|
|
|
2
2
|
import parse, {matchCsiNoGroups, matchCsiNoSgrNoGroups} from './strings/parse.js';
|
|
3
3
|
import clip from './strings/clip.js';
|
|
4
4
|
|
|
5
|
-
/** Returns the visible display length of a string, excluding invisible ANSI escape sequences
|
|
6
|
-
* and correctly handling Unicode code points that span multiple UTF-16 items.
|
|
7
|
-
* @param {string} s - The string to measure.
|
|
8
|
-
* @param {RegExp} [matcher=matchCsiNoGroups] - The regular expression used to match escape sequences.
|
|
9
|
-
* @returns {number} The visible display length.
|
|
10
|
-
*/
|
|
11
5
|
export const getLength = (s, matcher) => {
|
|
12
6
|
let counter = 0;
|
|
13
7
|
for (const {string} of parse(s, matcher)) {
|
|
@@ -16,36 +10,10 @@ export const getLength = (s, matcher) => {
|
|
|
16
10
|
return counter;
|
|
17
11
|
};
|
|
18
12
|
|
|
19
|
-
/** Returns the maximum visible display length among an array of strings.
|
|
20
|
-
* @param {string[]} strings - The strings to measure.
|
|
21
|
-
* @param {RegExp} [matcher=matchCsiNoGroups] - The regular expression used to match escape sequences.
|
|
22
|
-
* @returns {number} The maximum visible display length.
|
|
23
|
-
*/
|
|
24
13
|
export const getMaxLength = (strings, matcher) => strings.reduce((acc, s) => Math.max(acc, getLength(s, matcher)), 0);
|
|
25
14
|
|
|
26
|
-
/** Clips each string in an array to a specified display width.
|
|
27
|
-
* @param {string[]} strings - The strings to clip.
|
|
28
|
-
* @param {number} width - The maximum display width.
|
|
29
|
-
* @param {object} [options] - Options passed to `clip()`.
|
|
30
|
-
* @returns {string[]} The clipped strings.
|
|
31
|
-
*/
|
|
32
15
|
export const clipStrings = (strings, width, options) => strings.map(s => clip(s, width, options));
|
|
33
16
|
|
|
34
|
-
/** Converts a variety of inputs into an array of strings (the simplest text container).
|
|
35
|
-
*
|
|
36
|
-
* - A function is called (up to 10 times) and its result is re-processed.
|
|
37
|
-
* - A number or boolean returns `[String(s)]`.
|
|
38
|
-
* - A string is split by newlines.
|
|
39
|
-
* - An array is shallow-copied.
|
|
40
|
-
* - An object with `toStrings()` is called.
|
|
41
|
-
* - An object with `toBox()` returns `toBox().box`.
|
|
42
|
-
* - An object with `toPanel()` returns `toPanel().toStrings()`.
|
|
43
|
-
* - Other non-null objects are converted via `String()`.
|
|
44
|
-
* - Null/undefined returns `[]`.
|
|
45
|
-
*
|
|
46
|
-
* @param {*} s - The input to convert.
|
|
47
|
-
* @returns {string[]} An array of strings.
|
|
48
|
-
*/
|
|
49
17
|
export const toStrings = s => {
|
|
50
18
|
main: for (;;) {
|
|
51
19
|
switch (typeof s) {
|
|
@@ -55,6 +23,8 @@ export const toStrings = s => {
|
|
|
55
23
|
continue main;
|
|
56
24
|
case 'number':
|
|
57
25
|
case 'boolean':
|
|
26
|
+
case 'bigint':
|
|
27
|
+
case 'symbol':
|
|
58
28
|
return [String(s)];
|
|
59
29
|
case 'string':
|
|
60
30
|
return String(s).split(/\r?\n/g);
|
package/src/style.js
CHANGED
|
@@ -177,67 +177,34 @@ class Reset {
|
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
/** Chainable API for building SGR (Select Graphics Rendition) states.
|
|
181
|
-
* Provides namespaces for foreground (`fg`), background (`bg`), decoration colors, brightness, and reset.
|
|
182
|
-
* @see {@link https://github.com/uhop/console-toolkit/wiki/Module:-style}
|
|
183
|
-
*/
|
|
184
180
|
export class Style {
|
|
185
|
-
/**
|
|
186
|
-
* @param {object|string|null} [initState] - The initial SGR state (SgrState, string, or null for reset).
|
|
187
|
-
* @param {object|string|null} [currentState] - The current SGR state (defaults to initState).
|
|
188
|
-
* @param {number} [colorDepth=24] - Color depth (1, 4, 8, or 24).
|
|
189
|
-
*/
|
|
190
181
|
constructor(initState, currentState, colorDepth = 24) {
|
|
191
182
|
this[initStateSymbol] = toState(initState);
|
|
192
183
|
this[stateSymbol] = currentState ? toState(currentState) : this[initStateSymbol];
|
|
193
184
|
this[colorDepthSymbol] = colorDepth;
|
|
194
185
|
}
|
|
195
|
-
/** Creates a new Style with additional SGR commands applied.
|
|
196
|
-
* @param {string|string[]} [newCommands=[]] - SGR command(s) to add.
|
|
197
|
-
* @returns {Style}
|
|
198
|
-
*/
|
|
199
186
|
make(newCommands = []) {
|
|
200
187
|
if (!Array.isArray(newCommands)) newCommands = [newCommands];
|
|
201
188
|
return new Style(this[initStateSymbol], addCommandsToState(this[stateSymbol], newCommands), this[colorDepthSymbol]);
|
|
202
189
|
}
|
|
203
|
-
/** Adds SGR commands from an escape sequence string.
|
|
204
|
-
* @param {string} commandSequence - An ANSI escape sequence string.
|
|
205
|
-
* @returns {Style}
|
|
206
|
-
*/
|
|
207
190
|
add(commandSequence) {
|
|
208
191
|
const state = extractState(String(commandSequence), this[stateSymbol]);
|
|
209
192
|
return state === this[stateSymbol] ? this : new Style(this[initStateSymbol], state, this[colorDepthSymbol]);
|
|
210
193
|
}
|
|
211
|
-
/** Combines an SGR state into the current state.
|
|
212
|
-
* @param {object|string|null} state - State to combine (SgrState, string, or null).
|
|
213
|
-
* @returns {Style}
|
|
214
|
-
*/
|
|
215
194
|
addState(state) {
|
|
216
195
|
return new Style(this[initStateSymbol], combineStates(this[stateSymbol], toState(state)), this[colorDepthSymbol]);
|
|
217
196
|
}
|
|
218
|
-
/** Creates a new Style with the current state as the initial state, optionally calling a function.
|
|
219
|
-
* @param {Function} [fn] - Optional callback receiving the new Style.
|
|
220
|
-
* @returns {Style|this}
|
|
221
|
-
*/
|
|
222
197
|
mark(fn) {
|
|
223
198
|
const newStyle = new Style(this[stateSymbol], null, this[colorDepthSymbol]);
|
|
224
199
|
if (typeof fn != 'function') return newStyle;
|
|
225
200
|
fn(newStyle);
|
|
226
201
|
return this;
|
|
227
202
|
}
|
|
228
|
-
/** Returns the initial state, or passes it to a callback.
|
|
229
|
-
* @param {Function} [fn] - Optional callback.
|
|
230
|
-
* @returns {object|this}
|
|
231
|
-
*/
|
|
232
203
|
getInitialState(fn) {
|
|
233
204
|
if (typeof fn != 'function') return this[initStateSymbol];
|
|
234
205
|
fn(this[initStateSymbol]);
|
|
235
206
|
return this;
|
|
236
207
|
}
|
|
237
|
-
/** Returns the current state, or passes it to a callback.
|
|
238
|
-
* @param {Function} [fn] - Optional callback.
|
|
239
|
-
* @returns {object|this}
|
|
240
|
-
*/
|
|
241
208
|
getState(fn) {
|
|
242
209
|
if (typeof fn != 'function') return this[stateSymbol];
|
|
243
210
|
fn(this[stateSymbol]);
|
|
@@ -247,10 +214,6 @@ export class Style {
|
|
|
247
214
|
get colorDepth() {
|
|
248
215
|
return this[colorDepthSymbol]; // 1, 4, 8, 24
|
|
249
216
|
}
|
|
250
|
-
/** Creates a new Style with a different color depth.
|
|
251
|
-
* @param {number} colorDepth - New color depth (1, 4, 8, or 24).
|
|
252
|
-
* @returns {Style}
|
|
253
|
-
*/
|
|
254
217
|
setColorDepth(colorDepth) {
|
|
255
218
|
return new Style(this[initStateSymbol], this[stateSymbol], colorDepth);
|
|
256
219
|
}
|
|
@@ -369,10 +332,10 @@ export class Style {
|
|
|
369
332
|
return this[colorDepthSymbol] > 8 ? this.bgHexTrueColor(hex) : this.bgHex256(hex);
|
|
370
333
|
}
|
|
371
334
|
decorationStdRgb256(r, g, b) {
|
|
372
|
-
return this.make(sgr.getDecorationStdColor256(r, g, b));
|
|
335
|
+
return this.make(sgr.getDecorationStdColor256(sgr.colorStdRgb(r, g, b)));
|
|
373
336
|
}
|
|
374
337
|
decorationBrightStdRgb256(r, g, b) {
|
|
375
|
-
return this.make(sgr.getDecorationBrightStdColor256(r, g, b));
|
|
338
|
+
return this.make(sgr.getDecorationBrightStdColor256(sgr.colorStdRgb(r, g, b)));
|
|
376
339
|
}
|
|
377
340
|
decorationColor(c) {
|
|
378
341
|
return this.make(sgr.getDecorationRawColor256(c));
|
|
@@ -410,11 +373,6 @@ export class Style {
|
|
|
410
373
|
decorationHex(hex) {
|
|
411
374
|
return this[colorDepthSymbol] > 8 ? this.decorationHexTrueColor(hex) : this.decorationHex256(hex);
|
|
412
375
|
}
|
|
413
|
-
/** Wraps a string (or array of strings) with SGR escape sequences for the current style.
|
|
414
|
-
* Applies the style at the start and reverses it at the end.
|
|
415
|
-
* @param {string|string[]} s - String(s) to wrap.
|
|
416
|
-
* @returns {string|string[]} The styled string(s).
|
|
417
|
-
*/
|
|
418
376
|
text(s) {
|
|
419
377
|
if (Array.isArray(s)) return s.map(s => this.text(s));
|
|
420
378
|
s = String(s);
|
|
@@ -430,9 +388,6 @@ export class Style {
|
|
|
430
388
|
const cleanupCommands = stateReverseTransition(this[initStateSymbol], state);
|
|
431
389
|
return stringifyCommands(initialCommands) + s + stringifyCommands(cleanupCommands);
|
|
432
390
|
}
|
|
433
|
-
/** Converts the style to an SGR escape sequence string (transition from initial to current state).
|
|
434
|
-
* @returns {string}
|
|
435
|
-
*/
|
|
436
391
|
toString() {
|
|
437
392
|
const initialCommands = stateTransition(this[initStateSymbol], this[stateSymbol]);
|
|
438
393
|
return stringifyCommands(initialCommands);
|
|
@@ -654,21 +609,10 @@ const makeBq =
|
|
|
654
609
|
return bq(strings, ...args);
|
|
655
610
|
};
|
|
656
611
|
|
|
657
|
-
/** Tagged template literal for styled text. Style changes persist after the string.
|
|
658
|
-
* Can also be called as `s({initState, setState})` to create a configured tagger.
|
|
659
|
-
* @type {Function}
|
|
660
|
-
*/
|
|
661
612
|
export const s = makeBq(false);
|
|
662
|
-
/** Tagged template literal for styled text. Automatically resets the style at the end.
|
|
663
|
-
* Can also be called as `c({initState, setState})` to create a configured tagger.
|
|
664
|
-
* @type {Function}
|
|
665
|
-
*/
|
|
666
613
|
export const c = makeBq(true);
|
|
667
614
|
|
|
668
615
|
// singleton
|
|
669
|
-
/** The default Style singleton with an empty initial state.
|
|
670
|
-
* @type {Style}
|
|
671
|
-
*/
|
|
672
616
|
export const style = new Style({});
|
|
673
617
|
|
|
674
618
|
export default style;
|
package/src/symbols.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/** @module symbols
|
|
2
|
-
* A collection of frequently used Unicode characters for drawing lines, tables, charts, and other visual elements.
|
|
3
|
-
* @see {@link https://github.com/uhop/console-toolkit/wiki/Module:-symbols}
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
1
|
const generateSequence = (base, from, to) => {
|
|
7
2
|
const result = [];
|
|
8
3
|
|
|
@@ -21,61 +16,33 @@ const generateSequence = (base, from, to) => {
|
|
|
21
16
|
|
|
22
17
|
// blocks
|
|
23
18
|
|
|
24
|
-
/** Vertical block elements in 1/8th increments (index 0 = space, 7 = full block).
|
|
25
|
-
* @type {string[]}
|
|
26
|
-
*/
|
|
27
19
|
export const vBlocks8th = [' ', ...generateSequence(0x2581, 0, 7)];
|
|
28
|
-
/** Horizontal block elements in 1/8th increments (index 0 = space, 7 = full block).
|
|
29
|
-
* @type {string[]}
|
|
30
|
-
*/
|
|
31
20
|
export const hBlocks8th = [' ', ...generateSequence(0x2588, 7, 0)];
|
|
32
|
-
/** Full block character (█). */
|
|
33
21
|
export const fullBlock = '\u{2588}';
|
|
34
22
|
|
|
35
|
-
/** Left 1/8th block line. */
|
|
36
23
|
export const lLine = hBlocks8th[1];
|
|
37
|
-
/** Right 1/8th block line. */
|
|
38
24
|
export const rLine = `\u{2595}`;
|
|
39
|
-
/** Top 1/8th block line. */
|
|
40
25
|
export const tLine = `\u{2594}`;
|
|
41
|
-
/** Bottom 1/8th block line. */
|
|
42
26
|
export const bLine = vBlocks8th[1];
|
|
43
27
|
|
|
44
|
-
/** Left half block. */
|
|
45
28
|
export const lHalf = hBlocks8th[4];
|
|
46
|
-
/** Right half block. */
|
|
47
29
|
export const rHalf = `\u{2590}`;
|
|
48
|
-
/** Top half block. */
|
|
49
30
|
export const tHalf = `\u{2580}`;
|
|
50
|
-
/** Bottom half block. */
|
|
51
31
|
export const bHalf = vBlocks8th[4];
|
|
52
32
|
|
|
53
|
-
/** Top-left quadrant block. */
|
|
54
33
|
export const tlQuadrant = '\u{2598}';
|
|
55
|
-
/** Bottom-left quadrant block. */
|
|
56
34
|
export const blQuadrant = '\u{2596}';
|
|
57
|
-
/** Top-right quadrant block. */
|
|
58
35
|
export const trQuadrant = '\u{259D}';
|
|
59
|
-
/** Bottom-right quadrant block. */
|
|
60
36
|
export const brQuadrant = '\u{2597}';
|
|
61
37
|
|
|
62
|
-
/** Top-left + bottom-right diagonal quadrants. */
|
|
63
38
|
export const tlBrQuadrants = `\u{259A}`;
|
|
64
|
-
/** Top-right + bottom-left diagonal quadrants. */
|
|
65
39
|
export const trBlQuadrants = `\u{259E}`;
|
|
66
40
|
|
|
67
|
-
/** Negative (inverse) top-left quadrant. */
|
|
68
41
|
export const tlNegativeQuadrant = '\u{259F}';
|
|
69
|
-
/** Negative (inverse) bottom-left quadrant. */
|
|
70
42
|
export const blNegativeQuadrant = '\u{259C}';
|
|
71
|
-
/** Negative (inverse) top-right quadrant. */
|
|
72
43
|
export const trNegativeQuadrant = '\u{2599}';
|
|
73
|
-
/** Negative (inverse) bottom-right quadrant. */
|
|
74
44
|
export const brNegativeQuadrant = '\u{259B}';
|
|
75
45
|
|
|
76
|
-
/** All 16 quadrant block characters indexed by bitmask (TL=1, TR=2, BL=4, BR=8).
|
|
77
|
-
* @type {string[]}
|
|
78
|
-
*/
|
|
79
46
|
export const quadrants = [
|
|
80
47
|
' ',
|
|
81
48
|
tlQuadrant,
|
|
@@ -95,121 +62,70 @@ export const quadrants = [
|
|
|
95
62
|
fullBlock
|
|
96
63
|
];
|
|
97
64
|
|
|
98
|
-
/** Returns the quadrant character for the given corner flags.
|
|
99
|
-
* @param {boolean} tl - Top-left.
|
|
100
|
-
* @param {boolean} tr - Top-right.
|
|
101
|
-
* @param {boolean} bl - Bottom-left.
|
|
102
|
-
* @param {boolean} br - Bottom-right.
|
|
103
|
-
* @returns {string}
|
|
104
|
-
*/
|
|
105
65
|
export const quadrant = (tl, tr, bl, br) => quadrants[(tl ? 1 : 0) + (tr ? 2 : 0) + (bl ? 4 : 0) + (br ? 8 : 0)];
|
|
106
66
|
|
|
107
67
|
// shades
|
|
108
68
|
|
|
109
|
-
/** Shade characters from empty to full: space, light, medium, dark, full block.
|
|
110
|
-
* @type {string[]}
|
|
111
|
-
*/
|
|
112
69
|
export const shades = [' ', ...generateSequence(0x2591, 0, 2), fullBlock];
|
|
113
70
|
|
|
114
|
-
/** Light shade character (░). */
|
|
115
71
|
export const shadeLight = shades[1];
|
|
116
|
-
/** Medium shade character (▒). */
|
|
117
72
|
export const shadeMedium = shades[2];
|
|
118
|
-
/** Dark shade character (▓). */
|
|
119
73
|
export const shadeDark = shades[3];
|
|
120
74
|
|
|
121
75
|
// ellipses
|
|
122
76
|
|
|
123
|
-
/** Horizontal ellipsis (…). */
|
|
124
77
|
export const hellip = '\u{2026}';
|
|
125
|
-
/** Vertical ellipsis (⋮). */
|
|
126
78
|
export const vellip = '\u{22EE}';
|
|
127
|
-
/** Centered triple dots (⋯). */
|
|
128
79
|
export const ctdot = '\u{22EF}';
|
|
129
|
-
/** Up-pointing triple dots (⋰). */
|
|
130
80
|
export const utdot = '\u{22F0}';
|
|
131
|
-
/** Down-pointing triple dots (⋱). */
|
|
132
81
|
export const dtdot = '\u{22F1}';
|
|
133
82
|
|
|
134
83
|
export {hellip as ellipsis};
|
|
135
84
|
|
|
136
85
|
// math
|
|
137
86
|
|
|
138
|
-
/** Infinity symbol (∞). */
|
|
139
87
|
export const infinity = '\u{221e}';
|
|
140
|
-
/** Plus-minus sign (±). */
|
|
141
88
|
export const plusMinus = '\u{00B1}';
|
|
142
|
-
/** Minus-plus sign (∓). */
|
|
143
89
|
export const minusPlus = '\u{2213}';
|
|
144
|
-
/** Tilde operator (∼). */
|
|
145
90
|
export const tilde = '\u{223C}';
|
|
146
|
-
/** Minus sign (−). */
|
|
147
91
|
export const minus = '\u{2212}';
|
|
148
|
-
/** Multiplication sign (×). */
|
|
149
92
|
export const multiplication = '\u{00D7}';
|
|
150
|
-
/** Division sign (÷). */
|
|
151
93
|
export const division = '\u{00F7}';
|
|
152
|
-
/** N-ary product (∏). */
|
|
153
94
|
export const product = '\u{220F}';
|
|
154
|
-
/** N-ary summation (∑). */
|
|
155
95
|
export const sum = '\u{2211}';
|
|
156
|
-
/** For all (∀). */
|
|
157
96
|
export const forAll = '\u{2200}';
|
|
158
|
-
/** There exists (∃). */
|
|
159
97
|
export const exist = '\u{2203}';
|
|
160
|
-
/** Degree sign (°). */
|
|
161
98
|
export const degree = '\u{00B0}';
|
|
162
99
|
|
|
163
100
|
export {multiplication as times};
|
|
164
101
|
|
|
165
|
-
/** Superscript plus (⁺). */
|
|
166
102
|
export const superscriptPlus = '\u{207A}';
|
|
167
|
-
/** Superscript minus (⁻). */
|
|
168
103
|
export const superscriptMinus = '\u{207B}';
|
|
169
|
-
/** Subscript plus (₊). */
|
|
170
104
|
export const subscriptPlus = '\u{208A}';
|
|
171
|
-
/** Subscript minus (₋). */
|
|
172
105
|
export const subscriptMinus = '\u{208B}';
|
|
173
106
|
|
|
174
|
-
/** Per mille sign (‰). */
|
|
175
107
|
export const permille = '\u{2030}';
|
|
176
|
-
/** Per myriad sign (‱). */
|
|
177
108
|
export const permyriad = '\u{2031}';
|
|
178
109
|
|
|
179
110
|
// dashes
|
|
180
111
|
|
|
181
|
-
/** Hyphen (‐). */
|
|
182
112
|
export const hyphen = '\u{2010}';
|
|
183
|
-
/** Figure dash (‒). */
|
|
184
113
|
export const figureDash = '\u{2012}';
|
|
185
|
-
/** En dash (–). */
|
|
186
114
|
export const ndash = '\u{2013}';
|
|
187
|
-
/** Em dash (—). */
|
|
188
115
|
export const mdash = '\u{2014}';
|
|
189
|
-
/** Horizontal bar (―). */
|
|
190
116
|
export const horbar = '\u{2015}';
|
|
191
117
|
|
|
192
118
|
// marks
|
|
193
119
|
|
|
194
|
-
/** Ballot box (☐). */
|
|
195
120
|
export const ballotBox = '\u{2610}';
|
|
196
|
-
/** Ballot box with check (☑). */
|
|
197
121
|
export const ballotBoxChecked = '\u{2611}';
|
|
198
|
-
/** Ballot box with bold check (🗹). */
|
|
199
122
|
export const ballotBoxBoldChecked = '\u{1f5f9}';
|
|
200
|
-
/** Ballot box with X (☒). */
|
|
201
123
|
export const ballotBoxX = '\u{2612}';
|
|
202
124
|
|
|
203
|
-
/** Check mark (✓). */
|
|
204
125
|
export const checkMark = '\u{2713}';
|
|
205
|
-
/** Heavy check mark (✔). */
|
|
206
126
|
export const checkMarkHeavy = '\u{2714}';
|
|
207
|
-
/** Light check mark (🗸). */
|
|
208
127
|
export const checkMarkLight = '\u{1f5f8}';
|
|
209
128
|
|
|
210
|
-
/** Ballot X (✖). */
|
|
211
129
|
export const ballotX = '\u{2716}';
|
|
212
|
-
/** Heavy ballot X (✗). */
|
|
213
130
|
export const ballotXHeavy = '\u{2717}';
|
|
214
|
-
/** Light ballot X (🗷). */
|
|
215
131
|
export const ballotXLight = '\u{1f5f7}';
|
|
@@ -68,15 +68,6 @@ const drawRow = (lineTheme, hAxis, vAxis, skip, symbol, y, i) =>
|
|
|
68
68
|
})
|
|
69
69
|
.join('');
|
|
70
70
|
|
|
71
|
-
/** Draws table borders using a line theme and axis definitions.
|
|
72
|
-
* @param {object} lineTheme - The line theme defining border characters.
|
|
73
|
-
* @param {(string|number)[]} hAxis - Horizontal axis definition (alternating style/size values).
|
|
74
|
-
* @param {(string|number)[]} vAxis - Vertical axis definition (alternating style/size values).
|
|
75
|
-
* @param {object} [options] - Options.
|
|
76
|
-
* @param {{x: number, y: number, width: number, height: number}[]} [options.skip=[]] - Rectangles to skip (for merged cells).
|
|
77
|
-
* @param {string} [options.symbol=' '] - Fill character for cell interiors.
|
|
78
|
-
* @returns {import('../box.js').Box} A Box with the drawn borders.
|
|
79
|
-
*/
|
|
80
71
|
export const draw = (lineTheme, hAxis, vAxis, {skip = [], symbol = ' '} = {}) =>
|
|
81
72
|
new Box(
|
|
82
73
|
vAxis
|
package/src/table/index.d.ts
CHANGED
package/src/table/index.js
CHANGED
package/src/table/table.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Box from '../box.js';
|
|
2
|
-
import Panel from '../panel.js';
|
|
2
|
+
import Panel, {EMPTY_CELL_SENTINEL} from '../panel.js';
|
|
3
3
|
import {draw as drawBorder} from './draw-borders.js';
|
|
4
4
|
import style, {RESET_STATE} from '../style.js';
|
|
5
5
|
|
|
@@ -29,22 +29,7 @@ const dataInstructions = 'rowFirst,rowLast,columnFirst,columnLast,data,rowOdd,ro
|
|
|
29
29
|
|
|
30
30
|
const DIM_STATE = style.dim.getState();
|
|
31
31
|
|
|
32
|
-
/** Creates and renders tables with themes, supporting cell alignment, merged cells, and border drawing.
|
|
33
|
-
* @see {@link https://github.com/uhop/console-toolkit/wiki/Package:-table}
|
|
34
|
-
*/
|
|
35
32
|
export class Table {
|
|
36
|
-
/**
|
|
37
|
-
* @param {any[][]} data - 2D array of cell data. Each cell can be a value, or `{value, align, width, height}`.
|
|
38
|
-
* @param {object} lineTheme - The line theme for borders.
|
|
39
|
-
* @param {object} [options] - Options.
|
|
40
|
-
* @param {string|(string|number)[]} [options.hAxis='1'] - Horizontal axis definition.
|
|
41
|
-
* @param {string|(string|number)[]} [options.vAxis='1'] - Vertical axis definition.
|
|
42
|
-
* @param {string|string[]} [options.hAlign=[]] - Horizontal alignment per column.
|
|
43
|
-
* @param {string|string[]} [options.vAlign=[]] - Vertical alignment per row.
|
|
44
|
-
* @param {number|number[]} [options.hMin=0] - Minimum column widths.
|
|
45
|
-
* @param {number|number[]} [options.vMin=0] - Minimum row heights.
|
|
46
|
-
* @param {{l?: number, r?: number, t?: number, b?: number}} [options.cellPadding={}] - Cell padding.
|
|
47
|
-
*/
|
|
48
33
|
constructor(data, lineTheme, options = {}) {
|
|
49
34
|
let {hAxis = '1', vAxis = '1', hAlign = [], vAlign = [], hMin = 0, vMin = 0, cellPadding = {}} = options;
|
|
50
35
|
|
|
@@ -140,11 +125,6 @@ export class Table {
|
|
|
140
125
|
}
|
|
141
126
|
|
|
142
127
|
// TODO: accept `states`, draw even/odd rows/columns, support bg on lines optionally
|
|
143
|
-
/** Draws the table as a Panel with borders and cell content.
|
|
144
|
-
* @param {object} [options] - Options.
|
|
145
|
-
* @param {object} [options.lineState] - SGR state for border lines (defaults to dim).
|
|
146
|
-
* @returns {import('../panel.js').default} A Panel with the rendered table.
|
|
147
|
-
*/
|
|
148
128
|
draw({lineState = DIM_STATE} = {}) {
|
|
149
129
|
// prepare axes
|
|
150
130
|
|
|
@@ -166,8 +146,8 @@ export class Table {
|
|
|
166
146
|
|
|
167
147
|
// draw table borders
|
|
168
148
|
|
|
169
|
-
const borderBox = drawBorder(this.lineTheme, hAxis, vAxis, {skip: this.skipList, symbol:
|
|
170
|
-
panel = Panel.make(borderBox
|
|
149
|
+
const borderBox = drawBorder(this.lineTheme, hAxis, vAxis, {skip: this.skipList, symbol: EMPTY_CELL_SENTINEL}),
|
|
150
|
+
panel = Panel.make(borderBox);
|
|
171
151
|
panel.fillNonEmptyState(0, 0, panel.width, panel.height, {state: lineState});
|
|
172
152
|
|
|
173
153
|
// draw cells
|
|
@@ -200,35 +180,18 @@ export class Table {
|
|
|
200
180
|
return panel;
|
|
201
181
|
}
|
|
202
182
|
|
|
203
|
-
/** Converts the table to a Panel.
|
|
204
|
-
* @param {object} [options] - Options passed to `draw()`.
|
|
205
|
-
* @returns {import('../panel.js').default}
|
|
206
|
-
*/
|
|
207
183
|
toPanel(options) {
|
|
208
184
|
return this.draw(options);
|
|
209
185
|
}
|
|
210
186
|
|
|
211
|
-
/** Converts the table to a Box.
|
|
212
|
-
* @param {object} [options] - Options passed to `draw()`.
|
|
213
|
-
* @returns {import('../box.js').default}
|
|
214
|
-
*/
|
|
215
187
|
toBox(options) {
|
|
216
188
|
return this.toPanel(options).toBox(options);
|
|
217
189
|
}
|
|
218
190
|
|
|
219
|
-
/** Converts the table to an array of strings.
|
|
220
|
-
* @param {object} [options] - Options passed to `draw()`.
|
|
221
|
-
* @returns {string[]}
|
|
222
|
-
*/
|
|
223
191
|
toStrings(options) {
|
|
224
192
|
return this.toBox(options).toStrings();
|
|
225
193
|
}
|
|
226
194
|
|
|
227
|
-
/** Checks if a cell is visible (not hidden by a merged cell).
|
|
228
|
-
* @param {number} x - Column index.
|
|
229
|
-
* @param {number} y - Row index.
|
|
230
|
-
* @returns {boolean}
|
|
231
|
-
*/
|
|
232
195
|
isVisible(x, y) {
|
|
233
196
|
const i = 2 * y + 1,
|
|
234
197
|
j = 2 * x + 1;
|
|
@@ -239,12 +202,6 @@ export class Table {
|
|
|
239
202
|
return true;
|
|
240
203
|
}
|
|
241
204
|
|
|
242
|
-
/** Generates axis definitions and alignment arrays from a declarative options object.
|
|
243
|
-
* @param {number} width - Number of columns.
|
|
244
|
-
* @param {number} height - Number of rows.
|
|
245
|
-
* @param {object} options - Axis generation options.
|
|
246
|
-
* @returns {object} An object with `hAxis`, `vAxis`, `hAlign`, `vAlign`, `hMin`, `vMin`.
|
|
247
|
-
*/
|
|
248
205
|
static generateAxes(
|
|
249
206
|
width,
|
|
250
207
|
height,
|
|
@@ -324,11 +281,6 @@ export class Table {
|
|
|
324
281
|
return {hAxis, vAxis, hAlign, vAlign, hMin: hMinArray, vMin: vMinArray};
|
|
325
282
|
}
|
|
326
283
|
|
|
327
|
-
/** Processes data by applying styles to rows, columns, and special positions.
|
|
328
|
-
* @param {any[][]} data - The raw data.
|
|
329
|
-
* @param {object} [options] - Style options with properties like `rowFirst`, `rowLast`, `data`, `rowOdd`, etc.
|
|
330
|
-
* @returns {any[][]} The styled data.
|
|
331
|
-
*/
|
|
332
284
|
static processData(data, options) {
|
|
333
285
|
if (!options) return data;
|
|
334
286
|
|
|
@@ -373,13 +325,6 @@ export class Table {
|
|
|
373
325
|
});
|
|
374
326
|
}
|
|
375
327
|
|
|
376
|
-
/** Convenience factory that generates axes, processes data, and creates a Table.
|
|
377
|
-
* @param {any[][]} data - The raw data.
|
|
378
|
-
* @param {object} lineTheme - The line theme.
|
|
379
|
-
* @param {object} [options] - Combined axis generation and style options.
|
|
380
|
-
* @param {object} [overrides] - Additional overrides for the Table constructor options.
|
|
381
|
-
* @returns {Table}
|
|
382
|
-
*/
|
|
383
328
|
static make(data, lineTheme, options, overrides) {
|
|
384
329
|
return new Table(Table.processData(data, options?.states), lineTheme, {
|
|
385
330
|
...(options && Table.generateAxes(data.length && data[0].length, data.length, options)),
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {makeLineTheme} from '../utils.js';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
table21 = {t: ' ', m: ' ', b: ' ', v: ' ', h: '==='};
|
|
8
|
-
|
|
9
|
-
populateTheme(lineTheme, table11, 1, 1);
|
|
10
|
-
populateTheme(lineTheme, table21, 2, 1);
|
|
3
|
+
export const lineTheme = makeLineTheme([
|
|
4
|
+
[{t: ' ', m: ' ', b: ' ', v: ' ', h: '---'}, 1, 1],
|
|
5
|
+
[{t: ' ', m: ' ', b: ' ', v: ' ', h: '==='}, 2, 1]
|
|
6
|
+
]);
|
|
11
7
|
|
|
12
8
|
export default lineTheme;
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {makeLineTheme} from '../utils.js';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
export const lineTheme = {};
|
|
5
|
-
|
|
6
|
-
const dots = {t: '...', m: '.:.', b: ':::', v: ':::', h: '...'};
|
|
7
|
-
|
|
8
|
-
populateTheme(lineTheme, dots, 1, 1);
|
|
3
|
+
export const lineTheme = makeLineTheme([[{t: '...', m: '.:.', b: ':::', v: ':::', h: '...'}, 1, 1]]);
|
|
9
4
|
|
|
10
5
|
export default lineTheme;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {makeLineTheme} from '../utils.js';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const girder = {t: '//[]\\\\', m: '|][][|', b: '\\\\[]//', v: '||||||', h: '===', w: 2};
|
|
7
|
-
|
|
8
|
-
populateTheme(lineTheme, girder, 1, 1);
|
|
3
|
+
export const lineTheme = makeLineTheme([
|
|
4
|
+
[{t: '//[]\\\\', m: '|][][|', b: '\\\\[]//', v: '||||||', h: '===', w: 2}, 1, 1]
|
|
5
|
+
]);
|
|
9
6
|
|
|
10
7
|
export default lineTheme;
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {makeLineTheme} from '../utils.js';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
markdownGithub21 = {t: '|||', m: '|||', b: '|||', v: '|||', h: '==='};
|
|
8
|
-
|
|
9
|
-
populateTheme(lineTheme, markdownGithub11, 1, 1);
|
|
10
|
-
populateTheme(lineTheme, markdownGithub21, 2, 1);
|
|
3
|
+
export const lineTheme = makeLineTheme([
|
|
4
|
+
[{t: '|||', m: '|||', b: '|||', v: '|||', h: '---'}, 1, 1],
|
|
5
|
+
[{t: '|||', m: '|||', b: '|||', v: '|||', h: '==='}, 2, 1]
|
|
6
|
+
]);
|
|
11
7
|
|
|
12
8
|
export default lineTheme;
|