console-toolkit 1.2.10 → 1.2.11
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 +4 -3
- package/llms-full.txt +429 -0
- package/llms.txt +80 -0
- package/package.json +4 -2
- package/src/charts/bars/draw-grouped.d.ts +6 -1
- package/src/charts/bars/draw-stacked.d.ts +6 -1
- package/src/charts/bars/plain.d.ts +12 -2
- package/src/charts/columns/draw-grouped.d.ts +6 -1
- package/src/charts/columns/draw-stacked.d.ts +6 -1
- package/src/draw-block.d.ts +2 -12
- package/src/table/table.d.ts +6 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[npm-img]: https://img.shields.io/npm/v/console-toolkit.svg
|
|
4
4
|
[npm-url]: https://npmjs.org/package/console-toolkit
|
|
5
5
|
|
|
6
|
-
`console-toolkit` is a
|
|
6
|
+
`console-toolkit` is a toolkit for building rich CLI/TUI applications. It provides:
|
|
7
7
|
|
|
8
8
|
- Styles based on [ANSI escape sequences](https://en.wikipedia.org/wiki/ANSI_escape_code):
|
|
9
9
|
- [SGR](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR): colors and text styles
|
|
@@ -77,14 +77,14 @@ const table = makeTable(tableData, lineTheme);
|
|
|
77
77
|
for (const line of table.toStrings()) console.log(line);
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
Output:
|
|
81
81
|
|
|
82
82
|

|
|
83
83
|
|
|
84
84
|
## Installation
|
|
85
85
|
|
|
86
86
|
```bash
|
|
87
|
-
npm install
|
|
87
|
+
npm install console-toolkit
|
|
88
88
|
```
|
|
89
89
|
|
|
90
90
|
## Modules
|
|
@@ -132,6 +132,7 @@ BSD 3-Clause License
|
|
|
132
132
|
|
|
133
133
|
## Release history
|
|
134
134
|
|
|
135
|
+
- 1.2.11 _Improved docs for brevity and clarity, added script descriptions, added AI workflows._
|
|
135
136
|
- 1.2.10 _Added TypeScript typings, JSDoc, minor bug fixes, updated dev deps._
|
|
136
137
|
- 1.2.9 _Updated dev deps._
|
|
137
138
|
- 1.2.8 _Updated dev deps._
|
package/llms-full.txt
ADDED
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
# console-toolkit
|
|
2
|
+
|
|
3
|
+
> A zero-dependency JavaScript toolkit for building rich CLI/TUI applications with styled text, boxes, tables, charts, plots, turtle graphics, and spinners.
|
|
4
|
+
|
|
5
|
+
- NPM: https://npmjs.org/package/console-toolkit
|
|
6
|
+
- GitHub: https://github.com/uhop/console-toolkit
|
|
7
|
+
- Wiki: https://github.com/uhop/console-toolkit/wiki
|
|
8
|
+
- License: BSD-3-Clause
|
|
9
|
+
- Runtime: Node.js 20+, Bun, Deno
|
|
10
|
+
- Module system: ESM only (`"type": "module"`)
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install console-toolkit
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Quick start
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
import style, {c} from 'console-toolkit/style.js';
|
|
22
|
+
import Box from 'console-toolkit/box';
|
|
23
|
+
import Panel from 'console-toolkit/panel';
|
|
24
|
+
import makeTable from 'console-toolkit/table';
|
|
25
|
+
import lineTheme from 'console-toolkit/themes/lines/unicode-rounded.js';
|
|
26
|
+
|
|
27
|
+
// Styled text
|
|
28
|
+
console.log(c`{{bold}}Hello, {{bright.cyan}}world!`);
|
|
29
|
+
|
|
30
|
+
// Box (immutable rectangular text container)
|
|
31
|
+
const box = Box.make(['Hello', 'World']);
|
|
32
|
+
const padded = box.pad(1);
|
|
33
|
+
for (const line of padded.toStrings()) console.log(line);
|
|
34
|
+
|
|
35
|
+
// Table
|
|
36
|
+
const table = makeTable([['Name', 'Value'], ['Alice', 42]], lineTheme);
|
|
37
|
+
for (const line of table.toStrings()) console.log(line);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Module: strings (`console-toolkit/strings`)
|
|
43
|
+
|
|
44
|
+
String array utilities. The simplest text container.
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
function getLength(s: string, matcher?: RegExp): number;
|
|
48
|
+
function getMaxLength(strings: string[], matcher?: RegExp): number;
|
|
49
|
+
function clipStrings(strings: string[], width: number, options?: ClipOptions): string[];
|
|
50
|
+
function toStrings(s: any): string[];
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### ClipOptions
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
interface ClipOptions {
|
|
57
|
+
ellipsis?: string; // Ellipsis string (default: '…')
|
|
58
|
+
position?: 'right' | 'left' | 'center'; // Where to clip (default: 'right')
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Module: Box (`console-toolkit/box`)
|
|
65
|
+
|
|
66
|
+
Rectangular text container where all lines have equal display width. **Immutable** — all methods return new Box instances.
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
class Box {
|
|
70
|
+
box: string[];
|
|
71
|
+
readonly width: number;
|
|
72
|
+
readonly height: number;
|
|
73
|
+
|
|
74
|
+
constructor(s: Box | string | string[], normalized?: boolean);
|
|
75
|
+
|
|
76
|
+
static make(s: any, options?: BoxMakeOptions): Box;
|
|
77
|
+
static makeBlank(width: number, height: number, symbol?: string): Box;
|
|
78
|
+
|
|
79
|
+
toStrings(): string[];
|
|
80
|
+
toBox(): Box;
|
|
81
|
+
clone(): Box;
|
|
82
|
+
clip(width: number, options?: ClipOptions): Box;
|
|
83
|
+
|
|
84
|
+
padLeftRight(left: number, right: number, symbol?: string): Box;
|
|
85
|
+
padTopBottom(top: number, bottom: number, symbol?: string): Box;
|
|
86
|
+
padRight(n: number, symbol?: string): Box;
|
|
87
|
+
padLeft(n: number, symbol?: string): Box;
|
|
88
|
+
padTop(n: number, symbol?: string): Box;
|
|
89
|
+
padBottom(n: number, symbol?: string): Box;
|
|
90
|
+
pad(t: number, r?: number | string, b?: number | string, l?: number | string, symbol?: string): Box;
|
|
91
|
+
|
|
92
|
+
removeRows(y: number, n: number): Box;
|
|
93
|
+
addBottom(box: any, options?: AddBottomOptions): Box;
|
|
94
|
+
addRight(box: any, options?: AddRightOptions): Box;
|
|
95
|
+
flipV(): Box;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function toBox(s: any, options?: BoxMakeOptions): Box; // Alias for Box.make()
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### BoxMakeOptions
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
interface BoxMakeOptions {
|
|
105
|
+
symbol?: string; // Padding character (default: ' ')
|
|
106
|
+
align?: 'left' | 'l' | 'right' | 'r' | 'center' | 'c'; // Default: 'left'
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## Module: Panel (`console-toolkit/panel`)
|
|
113
|
+
|
|
114
|
+
2D cell grid where each cell has a character symbol and an SGR state. **Mutable** — methods mutate `this` and return `this` for chaining.
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
class Panel {
|
|
118
|
+
readonly width: number;
|
|
119
|
+
readonly height: number;
|
|
120
|
+
|
|
121
|
+
constructor(width: number, height: number);
|
|
122
|
+
|
|
123
|
+
static make(s: any, options?: object): Panel;
|
|
124
|
+
|
|
125
|
+
toStrings(options?: {emptySymbol?: string; emptyState?: object}): string[];
|
|
126
|
+
toBox(options?: object): Box;
|
|
127
|
+
extract(x?: number, y?: number, width?: number, height?: number): Panel;
|
|
128
|
+
clone(): Panel;
|
|
129
|
+
|
|
130
|
+
copyFrom(x: number, y: number, width: number, height: number, panel: Panel, x1?: number, y1?: number): this;
|
|
131
|
+
put(x: number, y: number, text: any, options?: {emptySymbol?: string}): this;
|
|
132
|
+
applyFn(x: number | Function, y?: number, width?: number, height?: number, fn?: Function, options?: object): this;
|
|
133
|
+
|
|
134
|
+
fill(x: number | string, y?: number, width?: number, height?: number, symbol?: string, state?: object): this;
|
|
135
|
+
fillState(x: number | object, y?: number, width?: number, height?: number, options?: object): this;
|
|
136
|
+
fillNonEmptyState(x: number | object, y?: number, width?: number, height?: number, options?: object): this;
|
|
137
|
+
combineStateBefore(x: number | object, y?: number, width?: number, height?: number, options?: object): this;
|
|
138
|
+
combineStateAfter(x: number | object, y?: number, width?: number, height?: number, options?: object): this;
|
|
139
|
+
clear(x?: number, y?: number, width?: number, height?: number, options?: object): this;
|
|
140
|
+
|
|
141
|
+
padLeft(n: number): this;
|
|
142
|
+
padRight(n: number): this;
|
|
143
|
+
padTop(n: number): this;
|
|
144
|
+
padBottom(n: number): this;
|
|
145
|
+
padLeftRight(n: number, m: number): this;
|
|
146
|
+
padTopBottom(n: number, m: number): this;
|
|
147
|
+
pad(t: number, r?: number, b?: number, l?: number): this;
|
|
148
|
+
|
|
149
|
+
removeColumns(x: number, n: number): this;
|
|
150
|
+
removeRows(y: number, n: number): this;
|
|
151
|
+
insertColumns(x: number, n: number): this;
|
|
152
|
+
insertRows(y: number, n: number): this;
|
|
153
|
+
resizeH(newWidth: number, align?: 'left' | 'center' | 'right'): this;
|
|
154
|
+
resizeV(newHeight: number, align?: 'top' | 'center' | 'bottom'): this;
|
|
155
|
+
resize(newWidth: number, newHeight: number, horizontal?: string, vertical?: string): this;
|
|
156
|
+
|
|
157
|
+
addBottom(panel: Panel, options?: {align?: string}): this;
|
|
158
|
+
addRight(panel: Panel, options?: {align?: string}): this;
|
|
159
|
+
|
|
160
|
+
transpose(): Panel;
|
|
161
|
+
rotateRight(): Panel;
|
|
162
|
+
rotateLeft(): Panel;
|
|
163
|
+
flipH(): this;
|
|
164
|
+
flipV(): this;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function toPanel(s: any, options?: object): Panel; // Alias for Panel.make()
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## Module: Style (`console-toolkit/style`)
|
|
173
|
+
|
|
174
|
+
Fluent API for ANSI SGR styling.
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
class Style {
|
|
178
|
+
constructor(initState?: SgrState | string | null, currentState?: SgrState | string | null, colorDepth?: number);
|
|
179
|
+
|
|
180
|
+
// Fluent property access for SGR attributes
|
|
181
|
+
readonly bold: Style;
|
|
182
|
+
readonly dim: Style;
|
|
183
|
+
readonly italic: Style;
|
|
184
|
+
readonly underline: Style;
|
|
185
|
+
readonly blink: Style;
|
|
186
|
+
readonly inverse: Style;
|
|
187
|
+
readonly hidden: Style;
|
|
188
|
+
readonly strikethrough: Style;
|
|
189
|
+
readonly overline: Style;
|
|
190
|
+
|
|
191
|
+
// Colors (foreground)
|
|
192
|
+
readonly black: Style;
|
|
193
|
+
readonly red: Style;
|
|
194
|
+
readonly green: Style;
|
|
195
|
+
readonly yellow: Style;
|
|
196
|
+
readonly blue: Style;
|
|
197
|
+
readonly magenta: Style;
|
|
198
|
+
readonly cyan: Style;
|
|
199
|
+
readonly white: Style;
|
|
200
|
+
|
|
201
|
+
// Bright colors
|
|
202
|
+
readonly bright: ColorMethods;
|
|
203
|
+
|
|
204
|
+
// Background colors
|
|
205
|
+
readonly bg: ColorMethods;
|
|
206
|
+
|
|
207
|
+
// Extended colors
|
|
208
|
+
fg256(n: number): Style;
|
|
209
|
+
bg256(n: number): Style;
|
|
210
|
+
fgRgb(r: number, g: number, b: number): Style;
|
|
211
|
+
bgRgb(r: number, g: number, b: number): Style;
|
|
212
|
+
|
|
213
|
+
// Reset
|
|
214
|
+
readonly reset: { readonly all: Style; readonly bold: Style; /* ... */ };
|
|
215
|
+
|
|
216
|
+
// Conversion
|
|
217
|
+
toString(): string;
|
|
218
|
+
text(s: string): string;
|
|
219
|
+
addState(state: SgrState | string | null): Style;
|
|
220
|
+
getState(): SgrState;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Tagged template literals
|
|
224
|
+
const s: BqFunction; // Style persists after the string
|
|
225
|
+
const c: BqFunction; // Auto-resets style at end
|
|
226
|
+
|
|
227
|
+
// Usage: c`{{bold}}Hello, {{bright.cyan}}world!`
|
|
228
|
+
|
|
229
|
+
export default Style;
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
## Module: draw-block (`console-toolkit/draw-block.js`)
|
|
235
|
+
|
|
236
|
+
```ts
|
|
237
|
+
function drawBlock(width: number, height: number, blockTheme: object, options?: DrawBlockOptions): Box;
|
|
238
|
+
function drawFrame(width: number, height: number, blockTheme: object, options?: DrawBlockOptions): Box;
|
|
239
|
+
|
|
240
|
+
interface DrawBlockOptions {
|
|
241
|
+
top?: number; // Sub-theme for top border
|
|
242
|
+
bottom?: number; // Sub-theme for bottom border
|
|
243
|
+
left?: number; // Sub-theme for left border
|
|
244
|
+
right?: number; // Sub-theme for right border
|
|
245
|
+
vTheme?: number; // Sub-theme for vertical borders
|
|
246
|
+
hTheme?: number; // Sub-theme for horizontal borders
|
|
247
|
+
theme?: number; // Sub-theme for all borders (default: 1)
|
|
248
|
+
symbol?: string; // Fill character for interior
|
|
249
|
+
}
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
---
|
|
253
|
+
|
|
254
|
+
## Module: draw-block-frac (`console-toolkit/draw-block-frac.js`)
|
|
255
|
+
|
|
256
|
+
```ts
|
|
257
|
+
function drawRealWidthBlock(realWidth: number, height: number, drawEmptyBorder?: boolean): Box;
|
|
258
|
+
function drawRealHeightBlock(width: number, realHeight: number, drawEmptyBorder?: boolean): Box;
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
## Module: symbols (`console-toolkit/symbols.js`)
|
|
264
|
+
|
|
265
|
+
Curated Unicode constants for drawing.
|
|
266
|
+
|
|
267
|
+
```ts
|
|
268
|
+
// Block elements (1/8th increments)
|
|
269
|
+
const vBlocks8th: string[]; // Vertical blocks [space..fullBlock]
|
|
270
|
+
const hBlocks8th: string[]; // Horizontal blocks [space..fullBlock]
|
|
271
|
+
const fullBlock: string; // █
|
|
272
|
+
|
|
273
|
+
// Lines (1/8th block edges)
|
|
274
|
+
const lLine, rLine, tLine, bLine: string;
|
|
275
|
+
|
|
276
|
+
// Half blocks
|
|
277
|
+
const lHalf, rHalf, tHalf, bHalf: string;
|
|
278
|
+
|
|
279
|
+
// Quadrants
|
|
280
|
+
const tlQuadrant, trQuadrant, blQuadrant, brQuadrant: string;
|
|
281
|
+
const quadrants: string[]; // All 16 quadrant chars indexed by bitmask
|
|
282
|
+
function quadrant(tl: boolean, tr: boolean, bl: boolean, br: boolean): string;
|
|
283
|
+
|
|
284
|
+
// Shades
|
|
285
|
+
const shades: string[]; // [space, light, medium, dark, fullBlock]
|
|
286
|
+
const shadeLight, shadeMedium, shadeDark: string;
|
|
287
|
+
|
|
288
|
+
// Ellipses
|
|
289
|
+
const hellip, vellip, ctdot, utdot, dtdot: string;
|
|
290
|
+
const ellipsis: string; // Alias for hellip
|
|
291
|
+
|
|
292
|
+
// Math symbols
|
|
293
|
+
const infinity, plusMinus, minusPlus, tilde, minus: string;
|
|
294
|
+
const multiplication, division, product, sum: string;
|
|
295
|
+
const forAll, exist, degree: string;
|
|
296
|
+
const times: string; // Alias for multiplication
|
|
297
|
+
const superscriptPlus, superscriptMinus, subscriptPlus, subscriptMinus: string;
|
|
298
|
+
const permille, permyriad: string;
|
|
299
|
+
|
|
300
|
+
// Dashes
|
|
301
|
+
const hyphen, figureDash, ndash, mdash, horbar: string;
|
|
302
|
+
|
|
303
|
+
// Marks
|
|
304
|
+
const ballotBox, ballotBoxChecked, ballotBoxBoldChecked, ballotBoxX: string;
|
|
305
|
+
const checkMark, checkMarkHeavy, checkMarkLight: string;
|
|
306
|
+
const ballotX, ballotXHeavy, ballotXLight: string;
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
---
|
|
310
|
+
|
|
311
|
+
## Package: table (`console-toolkit/table`)
|
|
312
|
+
|
|
313
|
+
```ts
|
|
314
|
+
import Table from 'console-toolkit/table';
|
|
315
|
+
|
|
316
|
+
// Create a table from 2D data array with a line theme
|
|
317
|
+
const table = Table.make(data, lineTheme, options?);
|
|
318
|
+
// or use the default export (alias for Table.make)
|
|
319
|
+
const table = make(data, lineTheme, options?);
|
|
320
|
+
|
|
321
|
+
table.toStrings(); // string[]
|
|
322
|
+
table.toBox(); // Box
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
---
|
|
326
|
+
|
|
327
|
+
## Package: plot (`console-toolkit/plot`)
|
|
328
|
+
|
|
329
|
+
Bitmap plotting using quadrant characters.
|
|
330
|
+
|
|
331
|
+
```ts
|
|
332
|
+
import Bitmap from 'console-toolkit/plot';
|
|
333
|
+
|
|
334
|
+
const bmp = new Bitmap(width, height);
|
|
335
|
+
bmp.line(x0, y0, x1, y1, value?);
|
|
336
|
+
bmp.rect(x0, y0, x1, y1, value?);
|
|
337
|
+
const box = bmp.toQuads(); // Box
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
---
|
|
341
|
+
|
|
342
|
+
## Package: turtle (`console-toolkit/turtle`)
|
|
343
|
+
|
|
344
|
+
Turtle graphics for vector line drawing.
|
|
345
|
+
|
|
346
|
+
```ts
|
|
347
|
+
import Turtle from 'console-toolkit/turtle';
|
|
348
|
+
|
|
349
|
+
const t = new Turtle();
|
|
350
|
+
t.forward(10).right(90).forward(10);
|
|
351
|
+
const box = t.toBox({useArcs: true});
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
---
|
|
355
|
+
|
|
356
|
+
## Package: charts
|
|
357
|
+
|
|
358
|
+
Bar and column charts with themes.
|
|
359
|
+
|
|
360
|
+
```ts
|
|
361
|
+
// Horizontal bar chart
|
|
362
|
+
import drawChart from 'console-toolkit/charts/bars/plain.js';
|
|
363
|
+
const lines = drawChart(data, maxWidth, options?);
|
|
364
|
+
|
|
365
|
+
// Vertical column chart
|
|
366
|
+
import drawChart from 'console-toolkit/charts/columns/plain.js';
|
|
367
|
+
const box = drawChart(data, maxHeight, options?);
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
Variants: `plain`, `block`, `block-frac`, `frac`, `plain-stacked`, `block-stacked`, `plain-grouped`, `block-grouped`, `block-frac-grouped`, `frac-grouped`.
|
|
371
|
+
|
|
372
|
+
---
|
|
373
|
+
|
|
374
|
+
## Themes
|
|
375
|
+
|
|
376
|
+
### Line themes (for tables)
|
|
377
|
+
|
|
378
|
+
```ts
|
|
379
|
+
import theme from 'console-toolkit/themes/lines/unicode.js';
|
|
380
|
+
import theme from 'console-toolkit/themes/lines/unicode-bold.js';
|
|
381
|
+
import theme from 'console-toolkit/themes/lines/unicode-rounded.js';
|
|
382
|
+
import theme from 'console-toolkit/themes/lines/ascii.js';
|
|
383
|
+
import theme from 'console-toolkit/themes/lines/ascii-compact.js';
|
|
384
|
+
import theme from 'console-toolkit/themes/lines/ascii-dots.js';
|
|
385
|
+
import theme from 'console-toolkit/themes/lines/ascii-girder.js';
|
|
386
|
+
import theme from 'console-toolkit/themes/lines/ascii-github.js';
|
|
387
|
+
import theme from 'console-toolkit/themes/lines/ascii-reddit.js';
|
|
388
|
+
import theme from 'console-toolkit/themes/lines/ascii-rounded.js';
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
### Block themes (for draw-block)
|
|
392
|
+
|
|
393
|
+
```ts
|
|
394
|
+
import theme from 'console-toolkit/themes/blocks/unicode-half.js';
|
|
395
|
+
import theme from 'console-toolkit/themes/blocks/unicode-thin.js';
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
---
|
|
399
|
+
|
|
400
|
+
## Package: spinner (`console-toolkit/spinner`)
|
|
401
|
+
|
|
402
|
+
```ts
|
|
403
|
+
import spin from 'console-toolkit/spinner';
|
|
404
|
+
|
|
405
|
+
const stop = spin(message, options?);
|
|
406
|
+
// ... do async work ...
|
|
407
|
+
stop();
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
---
|
|
411
|
+
|
|
412
|
+
## Package: ansi (`console-toolkit/ansi`)
|
|
413
|
+
|
|
414
|
+
Low-level ANSI escape sequence handling.
|
|
415
|
+
|
|
416
|
+
```ts
|
|
417
|
+
import {cursorUp, cursorDown, cursorForward, cursorBack} from 'console-toolkit/ansi';
|
|
418
|
+
import {eraseScreen, eraseLine} from 'console-toolkit/ansi';
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
---
|
|
422
|
+
|
|
423
|
+
## Optional peer dependencies
|
|
424
|
+
|
|
425
|
+
For double-wide character support (CJK, emoji), optionally install:
|
|
426
|
+
- `emoji-regex` — detects double-wide emojis
|
|
427
|
+
- `get-east-asian-width` — East Asian character width detection
|
|
428
|
+
|
|
429
|
+
These are auto-detected at runtime. Not required for basic usage.
|
package/llms.txt
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# console-toolkit
|
|
2
|
+
|
|
3
|
+
> A zero-dependency JavaScript toolkit for building rich CLI/TUI applications with styled text, boxes, tables, charts, plots, turtle graphics, and spinners.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
console-toolkit provides utilities to produce fancy console output. It supports ANSI escape sequences (SGR colors/styles, CSI cursor/screen control), Unicode symbols, bitmap and vector graphics, tables with themes, and bar/column charts.
|
|
8
|
+
|
|
9
|
+
- NPM: https://npmjs.org/package/console-toolkit
|
|
10
|
+
- GitHub: https://github.com/uhop/console-toolkit
|
|
11
|
+
- Wiki: https://github.com/uhop/console-toolkit/wiki
|
|
12
|
+
- License: BSD-3-Clause
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install console-toolkit
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick start
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
import style, {c} from 'console-toolkit/style.js';
|
|
24
|
+
import Box from 'console-toolkit/box';
|
|
25
|
+
import makeTable from 'console-toolkit/table';
|
|
26
|
+
import lineTheme from 'console-toolkit/themes/lines/unicode-rounded.js';
|
|
27
|
+
|
|
28
|
+
// Styled text with tagged template literal
|
|
29
|
+
console.log(c`{{bold}}Hello, {{bright.cyan}}world!`);
|
|
30
|
+
|
|
31
|
+
// Table
|
|
32
|
+
const table = makeTable([['Name', 'Value'], ['Alice', 42]], lineTheme);
|
|
33
|
+
for (const line of table.toStrings()) console.log(line);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Modules
|
|
37
|
+
|
|
38
|
+
### Text containers
|
|
39
|
+
|
|
40
|
+
- **strings** (`console-toolkit/strings`) — string array utilities: getLength, clip, toStrings.
|
|
41
|
+
- **Box** (`console-toolkit/box`) — rectangular text container where all lines have equal display width. Immutable — methods return new Box instances. Supports padding, stacking, clipping, flipping.
|
|
42
|
+
- **Panel** (`console-toolkit/panel`) — 2D cell grid where each cell has a character and SGR state. Mutable — methods return `this`. Supports fill, copy, apply, resize, rotate, flip, transpose.
|
|
43
|
+
|
|
44
|
+
### Styling
|
|
45
|
+
|
|
46
|
+
- **Style** (`console-toolkit/style`) — fluent API for ANSI SGR states. Provides `s` and `c` tagged template literals for inline styling. `c` auto-resets at end; `s` persists style changes.
|
|
47
|
+
|
|
48
|
+
### Drawing
|
|
49
|
+
|
|
50
|
+
- **draw-block** (`console-toolkit/draw-block.js`) — draws filled blocks and frames using block themes.
|
|
51
|
+
- **draw-block-frac** (`console-toolkit/draw-block-frac.js`) — draws blocks with fractional width/height using 1/8th Unicode block characters.
|
|
52
|
+
- **symbols** (`console-toolkit/symbols.js`) — curated Unicode constants: block elements, quadrants, shades, math symbols, dashes, marks, ellipses.
|
|
53
|
+
|
|
54
|
+
### Packages
|
|
55
|
+
|
|
56
|
+
- **ansi** (`console-toolkit/ansi`) — low-level ANSI CSI/SGR sequence handling.
|
|
57
|
+
- **table** (`console-toolkit/table`) — table renderer with line themes.
|
|
58
|
+
- **charts** — bar and column chart renderers (plain, block, frac, stacked, grouped) with chart themes.
|
|
59
|
+
- **themes** — line themes (unicode, ascii variants) and block themes for drawing.
|
|
60
|
+
- **plot** (`console-toolkit/plot`) — bitmap plotting using quadrant and braille characters.
|
|
61
|
+
- **turtle** (`console-toolkit/turtle`) — turtle graphics for vector line drawing.
|
|
62
|
+
- **spinner** (`console-toolkit/spinner`) — spinner animations and updatable output.
|
|
63
|
+
- **output** — output helpers: Writer (streaming), Updater (in-place updates).
|
|
64
|
+
- **alphanumeric** — decorative Unicode number and letter sets.
|
|
65
|
+
|
|
66
|
+
## Key types
|
|
67
|
+
|
|
68
|
+
- `Box` — class with `box: string[]`, `width`, `height`, padding/stacking/clipping methods.
|
|
69
|
+
- `Panel` — class with 2D cell array, `width`, `height`, fill/copy/resize/transform methods.
|
|
70
|
+
- `Style` — class with fluent property access for SGR states (e.g., `style.bold.bright.cyan`).
|
|
71
|
+
- `SgrState` — plain object representing SGR state properties.
|
|
72
|
+
- `PanelCell` — `{symbol: string, state: SgrState}` or `{ignore: true}` or `null`.
|
|
73
|
+
|
|
74
|
+
## Optional peer dependencies
|
|
75
|
+
|
|
76
|
+
For double-wide character support (CJK, emoji), install optionally:
|
|
77
|
+
- `emoji-regex` — detects double-wide emojis.
|
|
78
|
+
- `get-east-asian-width` — East Asian character width detection.
|
|
79
|
+
|
|
80
|
+
These are auto-detected at runtime. Not required for basic usage.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "console-toolkit",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.11",
|
|
4
4
|
"description": "Toolkit to produce a fancy console output (boxes, tables, charts, colors).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -72,7 +72,9 @@
|
|
|
72
72
|
},
|
|
73
73
|
"homepage": "https://github.com/uhop/console-toolkit#readme",
|
|
74
74
|
"files": [
|
|
75
|
-
"./src"
|
|
75
|
+
"./src",
|
|
76
|
+
"llms.txt",
|
|
77
|
+
"llms-full.txt"
|
|
76
78
|
],
|
|
77
79
|
"tape6": {
|
|
78
80
|
"tests": [
|
|
@@ -28,7 +28,12 @@ export interface GroupedChartOptions {
|
|
|
28
28
|
* @param options - Optional chart options.
|
|
29
29
|
* @returns The drawn row as a string or string array.
|
|
30
30
|
*/
|
|
31
|
-
type DrawRowFn = (
|
|
31
|
+
type DrawRowFn = (
|
|
32
|
+
data: ChartDatum[],
|
|
33
|
+
width: number,
|
|
34
|
+
maxValue: number,
|
|
35
|
+
options?: GroupedChartOptions
|
|
36
|
+
) => string | string[];
|
|
32
37
|
|
|
33
38
|
/** Creates a grouped bar chart drawing function from a row-drawing function.
|
|
34
39
|
* @param drawRow - The row-drawing function.
|
|
@@ -34,7 +34,12 @@ export interface StackedChartOptions {
|
|
|
34
34
|
* @param options - Optional chart options.
|
|
35
35
|
* @returns The drawn row as a string or string array.
|
|
36
36
|
*/
|
|
37
|
-
type DrawRowFn = (
|
|
37
|
+
type DrawRowFn = (
|
|
38
|
+
data: ChartDatum[],
|
|
39
|
+
width: number,
|
|
40
|
+
maxValue: number,
|
|
41
|
+
options?: StackedChartOptions
|
|
42
|
+
) => string | string[];
|
|
38
43
|
|
|
39
44
|
/** Creates a stacked bar chart drawing function from a row-drawing function.
|
|
40
45
|
* @param drawRow - The row-drawing function.
|
|
@@ -27,7 +27,12 @@ export interface PlainBarOptions extends StackedChartOptions {
|
|
|
27
27
|
* @param options - Options.
|
|
28
28
|
* @returns The drawn string.
|
|
29
29
|
*/
|
|
30
|
-
export function defaultDrawItem(
|
|
30
|
+
export function defaultDrawItem(
|
|
31
|
+
datum: ChartDatum | null,
|
|
32
|
+
size: number,
|
|
33
|
+
info: DrawItemInfo,
|
|
34
|
+
options: PlainBarOptions
|
|
35
|
+
): string;
|
|
31
36
|
|
|
32
37
|
/** Options for `drawItemLabel()`. */
|
|
33
38
|
export interface DrawItemLabelOptions {
|
|
@@ -48,7 +53,12 @@ export interface DrawItemLabelOptions {
|
|
|
48
53
|
* @param options - Label options.
|
|
49
54
|
* @returns The drawn string.
|
|
50
55
|
*/
|
|
51
|
-
export function drawItemLabel(
|
|
56
|
+
export function drawItemLabel(
|
|
57
|
+
datum: ChartDatum | null,
|
|
58
|
+
size: number,
|
|
59
|
+
info: DrawItemInfo,
|
|
60
|
+
options: DrawItemLabelOptions
|
|
61
|
+
): string;
|
|
52
62
|
|
|
53
63
|
/** Draws a single stacked bar row.
|
|
54
64
|
* @param data - Array of chart data items.
|
|
@@ -28,7 +28,12 @@ export interface GroupedColumnChartOptions {
|
|
|
28
28
|
* @param options - Optional chart options.
|
|
29
29
|
* @returns Array of strings for the column.
|
|
30
30
|
*/
|
|
31
|
-
type DrawColumnFn = (
|
|
31
|
+
type DrawColumnFn = (
|
|
32
|
+
data: ChartDatum[],
|
|
33
|
+
width: number,
|
|
34
|
+
maxValue: number,
|
|
35
|
+
options?: GroupedColumnChartOptions
|
|
36
|
+
) => string[];
|
|
32
37
|
|
|
33
38
|
/** Creates a grouped column chart drawing function from a column-drawing function.
|
|
34
39
|
* @param drawColumn - The column-drawing function.
|
|
@@ -26,7 +26,12 @@ export interface StackedColumnChartOptions {
|
|
|
26
26
|
* @param options - Optional chart options.
|
|
27
27
|
* @returns Array of strings for the column.
|
|
28
28
|
*/
|
|
29
|
-
type DrawColumnFn = (
|
|
29
|
+
type DrawColumnFn = (
|
|
30
|
+
data: ChartDatum[],
|
|
31
|
+
width: number,
|
|
32
|
+
maxValue: number,
|
|
33
|
+
options?: StackedColumnChartOptions
|
|
34
|
+
) => string[];
|
|
30
35
|
|
|
31
36
|
/** Creates a stacked column chart drawing function from a column-drawing function.
|
|
32
37
|
* @param drawColumn - The column-drawing function.
|
package/src/draw-block.d.ts
CHANGED
|
@@ -30,12 +30,7 @@ export interface DrawBlockOptions {
|
|
|
30
30
|
* @returns A Box containing the drawn block.
|
|
31
31
|
* @see {@link https://github.com/uhop/console-toolkit/wiki/Module:-draw-block}
|
|
32
32
|
*/
|
|
33
|
-
export function drawBlock(
|
|
34
|
-
width: number,
|
|
35
|
-
height: number,
|
|
36
|
-
blockTheme: LineTheme,
|
|
37
|
-
options?: DrawBlockOptions
|
|
38
|
-
): Box;
|
|
33
|
+
export function drawBlock(width: number, height: number, blockTheme: LineTheme, options?: DrawBlockOptions): Box;
|
|
39
34
|
/** Draws a rectangular frame using a block theme. Same as `drawBlock()` but defaults the interior fill to space if `symbol` is not specified.
|
|
40
35
|
* @param width - Interior width in columns.
|
|
41
36
|
* @param height - Interior height in rows.
|
|
@@ -43,11 +38,6 @@ export function drawBlock(
|
|
|
43
38
|
* @param options - Drawing options.
|
|
44
39
|
* @returns A Box containing the drawn frame.
|
|
45
40
|
*/
|
|
46
|
-
export function drawFrame(
|
|
47
|
-
width: number,
|
|
48
|
-
height: number,
|
|
49
|
-
blockTheme: LineTheme,
|
|
50
|
-
options?: DrawBlockOptions
|
|
51
|
-
): Box;
|
|
41
|
+
export function drawFrame(width: number, height: number, blockTheme: LineTheme, options?: DrawBlockOptions): Box;
|
|
52
42
|
|
|
53
43
|
export default drawBlock;
|
package/src/table/table.d.ts
CHANGED
|
@@ -158,7 +158,12 @@ export class Table {
|
|
|
158
158
|
/** List of cells to skip (merged cell regions). */
|
|
159
159
|
skipList: {x: number; y: number; width: number; height: number}[];
|
|
160
160
|
/** Resolved table options. */
|
|
161
|
-
options: {
|
|
161
|
+
options: {
|
|
162
|
+
hAxis: string | (string | number)[];
|
|
163
|
+
vAxis: string | (string | number)[];
|
|
164
|
+
hAlign: string[];
|
|
165
|
+
vAlign: string[];
|
|
166
|
+
};
|
|
162
167
|
/** Resolved cell padding. */
|
|
163
168
|
cellPadding: Required<CellPadding>;
|
|
164
169
|
/** Horizontal axis pattern. */
|