console-toolkit 1.2.9 → 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.
Files changed (158) hide show
  1. package/README.md +74 -29
  2. package/llms-full.txt +429 -0
  3. package/llms.txt +80 -0
  4. package/package.json +29 -7
  5. package/src/alphanumeric/arrows.d.ts +48 -0
  6. package/src/alphanumeric/arrows.js +23 -0
  7. package/src/alphanumeric/fractions.d.ts +65 -0
  8. package/src/alphanumeric/fractions.js +49 -0
  9. package/src/alphanumeric/number-formatters.d.ts +91 -0
  10. package/src/alphanumeric/number-formatters.js +45 -1
  11. package/src/alphanumeric/roman.d.ts +15 -0
  12. package/src/alphanumeric/roman.js +12 -0
  13. package/src/alphanumeric/unicode-cultural-numbers.d.ts +65 -0
  14. package/src/alphanumeric/unicode-cultural-numbers.js +1 -0
  15. package/src/alphanumeric/unicode-letters.d.ts +32 -0
  16. package/src/alphanumeric/unicode-letters.js +8 -0
  17. package/src/alphanumeric/unicode-numbers.d.ts +44 -0
  18. package/src/alphanumeric/unicode-numbers.js +21 -0
  19. package/src/alphanumeric/utils.d.ts +45 -0
  20. package/src/alphanumeric/utils.js +26 -0
  21. package/src/ansi/csi.d.ts +141 -0
  22. package/src/ansi/csi.js +51 -2
  23. package/src/ansi/index.d.ts +26 -0
  24. package/src/ansi/sgr-constants.d.ts +173 -0
  25. package/src/ansi/sgr-state.d.ts +91 -0
  26. package/src/ansi/sgr-state.js +45 -0
  27. package/src/ansi/sgr.d.ts +587 -0
  28. package/src/ansi/sgr.js +426 -6
  29. package/src/box.d.ts +160 -0
  30. package/src/box.js +113 -12
  31. package/src/charts/bars/block-frac-grouped.d.ts +12 -0
  32. package/src/charts/bars/block-frac-grouped.js +6 -0
  33. package/src/charts/bars/block-frac.d.ts +34 -0
  34. package/src/charts/bars/block-frac.js +13 -0
  35. package/src/charts/bars/block-grouped.d.ts +12 -0
  36. package/src/charts/bars/block-grouped.js +6 -0
  37. package/src/charts/bars/block.d.ts +43 -0
  38. package/src/charts/bars/block.js +13 -0
  39. package/src/charts/bars/draw-grouped.d.ts +46 -0
  40. package/src/charts/bars/draw-grouped.js +4 -0
  41. package/src/charts/bars/draw-stacked.d.ts +52 -0
  42. package/src/charts/bars/draw-stacked.js +4 -0
  43. package/src/charts/bars/frac-grouped.d.ts +32 -0
  44. package/src/charts/bars/frac-grouped.js +13 -0
  45. package/src/charts/bars/plain-grouped.d.ts +12 -0
  46. package/src/charts/bars/plain-grouped.js +6 -0
  47. package/src/charts/bars/plain.d.ts +85 -0
  48. package/src/charts/bars/plain.js +27 -0
  49. package/src/charts/columns/block-frac-grouped.d.ts +12 -0
  50. package/src/charts/columns/block-frac-grouped.js +6 -0
  51. package/src/charts/columns/block-frac.d.ts +39 -0
  52. package/src/charts/columns/block-frac.js +13 -0
  53. package/src/charts/columns/block-grouped.d.ts +12 -0
  54. package/src/charts/columns/block-grouped.js +6 -0
  55. package/src/charts/columns/block.d.ts +43 -0
  56. package/src/charts/columns/block.js +13 -0
  57. package/src/charts/columns/draw-grouped.d.ts +46 -0
  58. package/src/charts/columns/draw-grouped.js +4 -0
  59. package/src/charts/columns/draw-stacked.d.ts +44 -0
  60. package/src/charts/columns/draw-stacked.js +4 -0
  61. package/src/charts/columns/frac-grouped.d.ts +37 -0
  62. package/src/charts/columns/frac-grouped.js +13 -0
  63. package/src/charts/columns/plain-grouped.d.ts +12 -0
  64. package/src/charts/columns/plain-grouped.js +6 -0
  65. package/src/charts/columns/plain.d.ts +32 -0
  66. package/src/charts/columns/plain.js +13 -0
  67. package/src/charts/themes/default.d.ts +6 -0
  68. package/src/charts/themes/default.js +1 -0
  69. package/src/charts/themes/rainbow-reversed.d.ts +6 -0
  70. package/src/charts/themes/rainbow-reversed.js +2 -1
  71. package/src/charts/themes/rainbow.d.ts +6 -0
  72. package/src/charts/themes/rainbow.js +1 -0
  73. package/src/charts/utils.d.ts +79 -0
  74. package/src/charts/utils.js +32 -4
  75. package/src/draw-block-frac.d.ts +16 -0
  76. package/src/draw-block-frac.js +14 -0
  77. package/src/draw-block.d.ts +43 -0
  78. package/src/draw-block.js +25 -1
  79. package/src/meta.d.ts +84 -0
  80. package/src/meta.js +64 -0
  81. package/src/output/show.d.ts +55 -0
  82. package/src/output/show.js +28 -0
  83. package/src/output/updater.d.ts +114 -0
  84. package/src/output/updater.js +58 -4
  85. package/src/output/writer.d.ts +87 -0
  86. package/src/output/writer.js +57 -5
  87. package/src/panel.d.ts +402 -0
  88. package/src/panel.js +219 -5
  89. package/src/plot/bitmap.d.ts +80 -0
  90. package/src/plot/bitmap.js +33 -4
  91. package/src/plot/draw-line.d.ts +13 -0
  92. package/src/plot/draw-line.js +8 -0
  93. package/src/plot/draw-rect.d.ts +13 -0
  94. package/src/plot/draw-rect.js +38 -30
  95. package/src/plot/index.d.ts +39 -0
  96. package/src/plot/index.js +22 -0
  97. package/src/plot/to-quads.d.ts +10 -0
  98. package/src/plot/to-quads.js +5 -0
  99. package/src/spinner/index.d.ts +4 -0
  100. package/src/spinner/index.js +0 -2
  101. package/src/spinner/spin.d.ts +13 -0
  102. package/src/spinner/spin.js +13 -2
  103. package/src/spinner/spinner.d.ts +69 -0
  104. package/src/spinner/spinner.js +30 -2
  105. package/src/spinner/spinners.d.ts +34 -0
  106. package/src/spinner/spinners.js +23 -9
  107. package/src/strings/clip.d.ts +21 -0
  108. package/src/strings/clip.js +10 -0
  109. package/src/strings/parse.d.ts +23 -0
  110. package/src/strings/parse.js +7 -0
  111. package/src/strings/split.d.ts +38 -0
  112. package/src/strings/split.js +15 -0
  113. package/src/strings.d.ts +44 -0
  114. package/src/strings.js +34 -4
  115. package/src/style.d.ts +462 -0
  116. package/src/style.js +58 -4
  117. package/src/symbols.d.ts +167 -0
  118. package/src/symbols.js +91 -7
  119. package/src/table/draw-borders.d.ts +38 -0
  120. package/src/table/draw-borders.js +10 -2
  121. package/src/table/index.d.ts +8 -0
  122. package/src/table/index.js +1 -0
  123. package/src/table/table.d.ts +239 -0
  124. package/src/table/table.js +59 -1
  125. package/src/themes/blocks/unicode-half.d.ts +6 -0
  126. package/src/themes/blocks/unicode-half.js +1 -0
  127. package/src/themes/blocks/unicode-thin.d.ts +6 -0
  128. package/src/themes/blocks/unicode-thin.js +1 -0
  129. package/src/themes/lines/ascii-compact.d.ts +6 -0
  130. package/src/themes/lines/ascii-compact.js +1 -0
  131. package/src/themes/lines/ascii-dots.d.ts +6 -0
  132. package/src/themes/lines/ascii-dots.js +1 -0
  133. package/src/themes/lines/ascii-girder.d.ts +6 -0
  134. package/src/themes/lines/ascii-girder.js +1 -0
  135. package/src/themes/lines/ascii-github.d.ts +6 -0
  136. package/src/themes/lines/ascii-github.js +1 -0
  137. package/src/themes/lines/ascii-reddit.d.ts +6 -0
  138. package/src/themes/lines/ascii-reddit.js +1 -0
  139. package/src/themes/lines/ascii-rounded.d.ts +6 -0
  140. package/src/themes/lines/ascii-rounded.js +1 -0
  141. package/src/themes/lines/ascii.d.ts +6 -0
  142. package/src/themes/lines/ascii.js +1 -0
  143. package/src/themes/lines/unicode-bold.d.ts +6 -0
  144. package/src/themes/lines/unicode-bold.js +1 -0
  145. package/src/themes/lines/unicode-rounded.d.ts +6 -0
  146. package/src/themes/lines/unicode-rounded.js +1 -0
  147. package/src/themes/lines/unicode.d.ts +6 -0
  148. package/src/themes/lines/unicode.js +1 -0
  149. package/src/themes/utils.d.ts +33 -0
  150. package/src/themes/utils.js +7 -0
  151. package/src/turtle/draw-line-art.d.ts +19 -0
  152. package/src/turtle/draw-line-art.js +7 -0
  153. package/src/turtle/draw-unicode.d.ts +19 -0
  154. package/src/turtle/draw-unicode.js +8 -0
  155. package/src/turtle/index.d.ts +21 -0
  156. package/src/turtle/index.js +8 -0
  157. package/src/turtle/turtle.d.ts +269 -0
  158. package/src/turtle/turtle.js +124 -4
package/README.md CHANGED
@@ -1,19 +1,19 @@
1
1
  # console-toolkit [![NPM version][npm-img]][npm-url]
2
2
 
3
- [npm-img]: https://img.shields.io/npm/v/console-toolkit.svg
4
- [npm-url]: https://npmjs.org/package/console-toolkit
3
+ [npm-img]: https://img.shields.io/npm/v/console-toolkit.svg
4
+ [npm-url]: https://npmjs.org/package/console-toolkit
5
5
 
6
- `console-toolkit` is a set of tools to create rich CLI-based applications. It provides:
6
+ `console-toolkit` is a toolkit for building rich CLI/TUI applications. It provides:
7
7
 
8
- * Styles based on [ANSI escape sequences](https://en.wikipedia.org/wiki/ANSI_escape_code):
9
- * [SGR](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR): colors and text styles
10
- * [CSI](https://en.wikipedia.org/wiki/ANSI_escape_code#CSIsection): cursor and screen control
11
- * Bitmap graphics
12
- * Vector graphics based on [Turtle graphics](https://en.wikipedia.org/wiki/Turtle_graphics)
13
- * Curated sets of Unicode symbols
14
- * Tables with themes
15
- * Bar and column charts with themes
16
- * Various helpers and examples
8
+ - Styles based on [ANSI escape sequences](https://en.wikipedia.org/wiki/ANSI_escape_code):
9
+ - [SGR](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR): colors and text styles
10
+ - [CSI](https://en.wikipedia.org/wiki/ANSI_escape_code#CSIsection): cursor and screen control
11
+ - Bitmap graphics
12
+ - Vector graphics based on [Turtle graphics](https://en.wikipedia.org/wiki/Turtle_graphics)
13
+ - Curated sets of Unicode symbols
14
+ - Tables with themes
15
+ - Bar and column charts with themes
16
+ - Various helpers and examples
17
17
 
18
18
  ## Visual examples
19
19
 
@@ -54,7 +54,15 @@ console.log(c`{{bold}}Hello, {{bright.cyan}}world!`);
54
54
 
55
55
  // chart
56
56
 
57
- const chart = drawChart([[2, 1, 2], [5, 1, 4], [1, 1], [3, 1, 3]], 50);
57
+ const chart = drawChart(
58
+ [
59
+ [2, 1, 2],
60
+ [5, 1, 4],
61
+ [1, 1],
62
+ [3, 1, 3]
63
+ ],
64
+ 50
65
+ );
58
66
  for (const line of chart) console.log(line);
59
67
 
60
68
  // table
@@ -69,19 +77,54 @@ const table = makeTable(tableData, lineTheme);
69
77
  for (const line of table.toStrings()) console.log(line);
70
78
  ```
71
79
 
72
- The output of the code is:
80
+ Output:
73
81
 
74
82
  ![Code example](https://github.com/uhop/console-toolkit/wiki/images/example-code.png)
75
83
 
76
84
  ## Installation
77
85
 
78
86
  ```bash
79
- npm install --save console-toolkit
87
+ npm install console-toolkit
80
88
  ```
81
89
 
90
+ ## Modules
91
+
92
+ ### Text containers
93
+
94
+ | Module | Import | Description |
95
+ | ----------- | ------------------------- | -------------------------------------------------------------- |
96
+ | **strings** | `console-toolkit/strings` | String array utilities: `getLength`, `clip`, `toStrings` |
97
+ | **Box** | `console-toolkit/box` | Rectangular text container — all lines equal width. Immutable. |
98
+ | **Panel** | `console-toolkit/panel` | 2D cell grid with per-cell SGR state. Mutable. |
99
+
100
+ ### Styling and drawing
101
+
102
+ | Module | Import | Description |
103
+ | ------------------- | ------------------------------------ | --------------------------------------------------------- |
104
+ | **Style** | `console-toolkit/style` | Fluent SGR styling API + `s`/`c` tagged template literals |
105
+ | **draw-block** | `console-toolkit/draw-block.js` | Draw filled blocks and frames with block themes |
106
+ | **draw-block-frac** | `console-toolkit/draw-block-frac.js` | Fractional-width/height blocks (1/8th Unicode steps) |
107
+ | **symbols** | `console-toolkit/symbols.js` | Curated Unicode constants (blocks, shades, math, marks) |
108
+
109
+ ### Packages
110
+
111
+ | Package | Import | Description |
112
+ | ---------------- | ---------------------------------- | ------------------------------------------------------------ |
113
+ | **ansi** | `console-toolkit/ansi` | Low-level ANSI CSI/SGR escape sequence handling |
114
+ | **table** | `console-toolkit/table` | Table renderer with line themes |
115
+ | **charts** | `console-toolkit/charts/...` | Bar and column charts (plain, block, frac, stacked, grouped) |
116
+ | **themes** | `console-toolkit/themes/...` | Line and block themes (unicode, ascii variants) |
117
+ | **plot** | `console-toolkit/plot` | Bitmap plotting (quadrant and braille characters) |
118
+ | **turtle** | `console-toolkit/turtle` | Turtle graphics for vector line drawing |
119
+ | **spinner** | `console-toolkit/spinner` | Spinner animations and updatable output |
120
+ | **output** | `console-toolkit/output/...` | Output helpers: Writer (streaming), Updater (in-place) |
121
+ | **alphanumeric** | `console-toolkit/alphanumeric/...` | Decorative Unicode number and letter sets |
122
+
82
123
  ## Documentation
83
124
 
84
- See [wiki](https://github.com/uhop/console-toolkit/wiki) for more details.
125
+ See [wiki](https://github.com/uhop/console-toolkit/wiki) for detailed usage docs.
126
+
127
+ For project internals see [ARCHITECTURE.md](./ARCHITECTURE.md). For development setup see [CONTRIBUTING.md](./CONTRIBUTING.md). For AI agent rules see [AGENTS.md](./AGENTS.md).
85
128
 
86
129
  ## License
87
130
 
@@ -89,16 +132,18 @@ BSD 3-Clause License
89
132
 
90
133
  ## Release history
91
134
 
92
- * 1.2.9 *Updated dev deps.*
93
- * 1.2.8 *Updated dev deps.*
94
- * 1.2.7 *Updated dev deps.*
95
- * 1.2.6 *Updated dev deps.*
96
- * 1.2.5 *Updated dev deps.*
97
- * 1.2.4 *Updated deps.*
98
- * 1.2.3 *Updated deps + more tests.*
99
- * 1.2.2 *Updated deps.*
100
- * 1.2.1 *Added support for `Bun.stringWidth()`.*
101
- * 1.2.0 *Refactored `strings`.*
102
- * 1.1.1 *Minor bugfixes in `Table`, some improvements, updated deps.*
103
- * 1.1.0 *Minor improvements, enhanced `Writer` and `Updater`.*
104
- * 1.0.0 *Initial release.*
135
+ - 1.2.11 _Improved docs for brevity and clarity, added script descriptions, added AI workflows._
136
+ - 1.2.10 _Added TypeScript typings, JSDoc, minor bug fixes, updated dev deps._
137
+ - 1.2.9 _Updated dev deps._
138
+ - 1.2.8 _Updated dev deps._
139
+ - 1.2.7 _Updated dev deps._
140
+ - 1.2.6 _Updated dev deps._
141
+ - 1.2.5 _Updated dev deps._
142
+ - 1.2.4 _Updated deps._
143
+ - 1.2.3 _Updated deps + more tests._
144
+ - 1.2.2 _Updated deps._
145
+ - 1.2.1 _Added support for `Bun.stringWidth()`._
146
+ - 1.2.0 _Refactored `strings`._
147
+ - 1.1.1 _Minor bugfixes in `Table`, some improvements, updated deps._
148
+ - 1.1.0 _Minor improvements, enhanced `Writer` and `Updater`._
149
+ - 1.0.0 _Initial release._
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.