@promptctl/rich-js 0.1.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.
Files changed (318) hide show
  1. package/README.md +418 -0
  2. package/dist/core/box.d.ts +91 -0
  3. package/dist/core/box.d.ts.map +1 -0
  4. package/dist/core/box.js +534 -0
  5. package/dist/core/box.js.map +1 -0
  6. package/dist/core/cells.d.ts +24 -0
  7. package/dist/core/cells.d.ts.map +1 -0
  8. package/dist/core/cells.js +114 -0
  9. package/dist/core/cells.js.map +1 -0
  10. package/dist/core/color.d.ts +158 -0
  11. package/dist/core/color.d.ts.map +1 -0
  12. package/dist/core/color.js +825 -0
  13. package/dist/core/color.js.map +1 -0
  14. package/dist/core/console.d.ts +100 -0
  15. package/dist/core/console.d.ts.map +1 -0
  16. package/dist/core/console.js +353 -0
  17. package/dist/core/console.js.map +1 -0
  18. package/dist/core/emoji.d.ts +25 -0
  19. package/dist/core/emoji.d.ts.map +1 -0
  20. package/dist/core/emoji.js +392 -0
  21. package/dist/core/emoji.js.map +1 -0
  22. package/dist/core/highlighter.d.ts +33 -0
  23. package/dist/core/highlighter.d.ts.map +1 -0
  24. package/dist/core/highlighter.js +103 -0
  25. package/dist/core/highlighter.js.map +1 -0
  26. package/dist/core/markup.d.ts +69 -0
  27. package/dist/core/markup.d.ts.map +1 -0
  28. package/dist/core/markup.js +401 -0
  29. package/dist/core/markup.js.map +1 -0
  30. package/dist/core/measure.d.ts +17 -0
  31. package/dist/core/measure.d.ts.map +1 -0
  32. package/dist/core/measure.js +50 -0
  33. package/dist/core/measure.js.map +1 -0
  34. package/dist/core/protocol.d.ts +32 -0
  35. package/dist/core/protocol.d.ts.map +1 -0
  36. package/dist/core/protocol.js +17 -0
  37. package/dist/core/protocol.js.map +1 -0
  38. package/dist/core/render.d.ts +51 -0
  39. package/dist/core/render.d.ts.map +1 -0
  40. package/dist/core/render.js +69 -0
  41. package/dist/core/render.js.map +1 -0
  42. package/dist/core/segment.d.ts +104 -0
  43. package/dist/core/segment.d.ts.map +1 -0
  44. package/dist/core/segment.js +364 -0
  45. package/dist/core/segment.js.map +1 -0
  46. package/dist/core/spinnerData.d.ts +11 -0
  47. package/dist/core/spinnerData.d.ts.map +1 -0
  48. package/dist/core/spinnerData.js +116 -0
  49. package/dist/core/spinnerData.js.map +1 -0
  50. package/dist/core/strip.d.ts +159 -0
  51. package/dist/core/strip.d.ts.map +1 -0
  52. package/dist/core/strip.js +237 -0
  53. package/dist/core/strip.js.map +1 -0
  54. package/dist/core/style.d.ts +115 -0
  55. package/dist/core/style.d.ts.map +1 -0
  56. package/dist/core/style.js +662 -0
  57. package/dist/core/style.js.map +1 -0
  58. package/dist/core/text.d.ts +91 -0
  59. package/dist/core/text.d.ts.map +1 -0
  60. package/dist/core/text.js +610 -0
  61. package/dist/core/text.js.map +1 -0
  62. package/dist/index.d.ts +99 -0
  63. package/dist/index.d.ts.map +1 -0
  64. package/dist/index.js +72 -0
  65. package/dist/index.js.map +1 -0
  66. package/dist/renderables/align.d.ts +17 -0
  67. package/dist/renderables/align.d.ts.map +1 -0
  68. package/dist/renderables/align.js +47 -0
  69. package/dist/renderables/align.js.map +1 -0
  70. package/dist/renderables/columns.d.ts +28 -0
  71. package/dist/renderables/columns.d.ts.map +1 -0
  72. package/dist/renderables/columns.js +92 -0
  73. package/dist/renderables/columns.js.map +1 -0
  74. package/dist/renderables/constrain.d.ts +16 -0
  75. package/dist/renderables/constrain.d.ts.map +1 -0
  76. package/dist/renderables/constrain.js +38 -0
  77. package/dist/renderables/constrain.js.map +1 -0
  78. package/dist/renderables/flexStrip.d.ts +42 -0
  79. package/dist/renderables/flexStrip.d.ts.map +1 -0
  80. package/dist/renderables/flexStrip.js +201 -0
  81. package/dist/renderables/flexStrip.js.map +1 -0
  82. package/dist/renderables/group.d.ts +12 -0
  83. package/dist/renderables/group.d.ts.map +1 -0
  84. package/dist/renderables/group.js +16 -0
  85. package/dist/renderables/group.js.map +1 -0
  86. package/dist/renderables/json.d.ts +23 -0
  87. package/dist/renderables/json.d.ts.map +1 -0
  88. package/dist/renderables/json.js +49 -0
  89. package/dist/renderables/json.js.map +1 -0
  90. package/dist/renderables/layout.d.ts +37 -0
  91. package/dist/renderables/layout.d.ts.map +1 -0
  92. package/dist/renderables/layout.js +151 -0
  93. package/dist/renderables/layout.js.map +1 -0
  94. package/dist/renderables/live.d.ts +48 -0
  95. package/dist/renderables/live.d.ts.map +1 -0
  96. package/dist/renderables/live.js +131 -0
  97. package/dist/renderables/live.js.map +1 -0
  98. package/dist/renderables/markdown.d.ts +25 -0
  99. package/dist/renderables/markdown.d.ts.map +1 -0
  100. package/dist/renderables/markdown.js +190 -0
  101. package/dist/renderables/markdown.js.map +1 -0
  102. package/dist/renderables/padding.d.ts +26 -0
  103. package/dist/renderables/padding.d.ts.map +1 -0
  104. package/dist/renderables/padding.js +92 -0
  105. package/dist/renderables/padding.js.map +1 -0
  106. package/dist/renderables/panel.d.ts +42 -0
  107. package/dist/renderables/panel.d.ts.map +1 -0
  108. package/dist/renderables/panel.js +202 -0
  109. package/dist/renderables/panel.js.map +1 -0
  110. package/dist/renderables/pretty.d.ts +29 -0
  111. package/dist/renderables/pretty.d.ts.map +1 -0
  112. package/dist/renderables/pretty.js +141 -0
  113. package/dist/renderables/pretty.js.map +1 -0
  114. package/dist/renderables/progress.d.ts +91 -0
  115. package/dist/renderables/progress.d.ts.map +1 -0
  116. package/dist/renderables/progress.js +234 -0
  117. package/dist/renderables/progress.js.map +1 -0
  118. package/dist/renderables/progressBar.d.ts +32 -0
  119. package/dist/renderables/progressBar.d.ts.map +1 -0
  120. package/dist/renderables/progressBar.js +59 -0
  121. package/dist/renderables/progressBar.js.map +1 -0
  122. package/dist/renderables/prompt.d.ts +25 -0
  123. package/dist/renderables/prompt.d.ts.map +1 -0
  124. package/dist/renderables/prompt.js +109 -0
  125. package/dist/renderables/prompt.js.map +1 -0
  126. package/dist/renderables/rule.d.ts +25 -0
  127. package/dist/renderables/rule.d.ts.map +1 -0
  128. package/dist/renderables/rule.js +96 -0
  129. package/dist/renderables/rule.js.map +1 -0
  130. package/dist/renderables/spinner.d.ts +30 -0
  131. package/dist/renderables/spinner.d.ts.map +1 -0
  132. package/dist/renderables/spinner.js +70 -0
  133. package/dist/renderables/spinner.js.map +1 -0
  134. package/dist/renderables/status.d.ts +24 -0
  135. package/dist/renderables/status.d.ts.map +1 -0
  136. package/dist/renderables/status.js +67 -0
  137. package/dist/renderables/status.js.map +1 -0
  138. package/dist/renderables/syntax.d.ts +36 -0
  139. package/dist/renderables/syntax.d.ts.map +1 -0
  140. package/dist/renderables/syntax.js +115 -0
  141. package/dist/renderables/syntax.js.map +1 -0
  142. package/dist/renderables/table.d.ts +109 -0
  143. package/dist/renderables/table.d.ts.map +1 -0
  144. package/dist/renderables/table.js +434 -0
  145. package/dist/renderables/table.js.map +1 -0
  146. package/dist/renderables/traceback.d.ts +26 -0
  147. package/dist/renderables/traceback.d.ts.map +1 -0
  148. package/dist/renderables/traceback.js +108 -0
  149. package/dist/renderables/traceback.js.map +1 -0
  150. package/dist/renderables/tree.d.ts +30 -0
  151. package/dist/renderables/tree.d.ts.map +1 -0
  152. package/dist/renderables/tree.js +107 -0
  153. package/dist/renderables/tree.js.map +1 -0
  154. package/dist/template-bindings/index.d.ts +61 -0
  155. package/dist/template-bindings/index.d.ts.map +1 -0
  156. package/dist/template-bindings/index.js +70 -0
  157. package/dist/template-bindings/index.js.map +1 -0
  158. package/dist/template-bindings/style-funcs.d.ts +30 -0
  159. package/dist/template-bindings/style-funcs.d.ts.map +1 -0
  160. package/dist/template-bindings/style-funcs.js +172 -0
  161. package/dist/template-bindings/style-funcs.js.map +1 -0
  162. package/dist/themes/buildPalette.d.ts +31 -0
  163. package/dist/themes/buildPalette.d.ts.map +1 -0
  164. package/dist/themes/buildPalette.js +43 -0
  165. package/dist/themes/buildPalette.js.map +1 -0
  166. package/dist/themes/colorMath.d.ts +23 -0
  167. package/dist/themes/colorMath.d.ts.map +1 -0
  168. package/dist/themes/colorMath.js +99 -0
  169. package/dist/themes/colorMath.js.map +1 -0
  170. package/dist/themes/data/atom-one-dark.d.ts +4 -0
  171. package/dist/themes/data/atom-one-dark.d.ts.map +1 -0
  172. package/dist/themes/data/atom-one-dark.js +159 -0
  173. package/dist/themes/data/atom-one-dark.js.map +1 -0
  174. package/dist/themes/data/atom-one-light.d.ts +4 -0
  175. package/dist/themes/data/atom-one-light.d.ts.map +1 -0
  176. package/dist/themes/data/atom-one-light.js +159 -0
  177. package/dist/themes/data/atom-one-light.js.map +1 -0
  178. package/dist/themes/data/catppuccin-latte.d.ts +4 -0
  179. package/dist/themes/data/catppuccin-latte.d.ts.map +1 -0
  180. package/dist/themes/data/catppuccin-latte.js +159 -0
  181. package/dist/themes/data/catppuccin-latte.js.map +1 -0
  182. package/dist/themes/data/catppuccin-mocha.d.ts +4 -0
  183. package/dist/themes/data/catppuccin-mocha.d.ts.map +1 -0
  184. package/dist/themes/data/catppuccin-mocha.js +159 -0
  185. package/dist/themes/data/catppuccin-mocha.js.map +1 -0
  186. package/dist/themes/data/dracula.d.ts +4 -0
  187. package/dist/themes/data/dracula.d.ts.map +1 -0
  188. package/dist/themes/data/dracula.js +159 -0
  189. package/dist/themes/data/dracula.js.map +1 -0
  190. package/dist/themes/data/flexoki.d.ts +4 -0
  191. package/dist/themes/data/flexoki.d.ts.map +1 -0
  192. package/dist/themes/data/flexoki.js +159 -0
  193. package/dist/themes/data/flexoki.js.map +1 -0
  194. package/dist/themes/data/gruvbox.d.ts +4 -0
  195. package/dist/themes/data/gruvbox.d.ts.map +1 -0
  196. package/dist/themes/data/gruvbox.js +159 -0
  197. package/dist/themes/data/gruvbox.js.map +1 -0
  198. package/dist/themes/data/index.d.ts +29 -0
  199. package/dist/themes/data/index.d.ts.map +1 -0
  200. package/dist/themes/data/index.js +48 -0
  201. package/dist/themes/data/index.js.map +1 -0
  202. package/dist/themes/data/monokai.d.ts +4 -0
  203. package/dist/themes/data/monokai.d.ts.map +1 -0
  204. package/dist/themes/data/monokai.js +159 -0
  205. package/dist/themes/data/monokai.js.map +1 -0
  206. package/dist/themes/data/nord.d.ts +4 -0
  207. package/dist/themes/data/nord.d.ts.map +1 -0
  208. package/dist/themes/data/nord.js +159 -0
  209. package/dist/themes/data/nord.js.map +1 -0
  210. package/dist/themes/data/rose-pine-dawn.d.ts +4 -0
  211. package/dist/themes/data/rose-pine-dawn.d.ts.map +1 -0
  212. package/dist/themes/data/rose-pine-dawn.js +159 -0
  213. package/dist/themes/data/rose-pine-dawn.js.map +1 -0
  214. package/dist/themes/data/rose-pine-moon.d.ts +4 -0
  215. package/dist/themes/data/rose-pine-moon.d.ts.map +1 -0
  216. package/dist/themes/data/rose-pine-moon.js +159 -0
  217. package/dist/themes/data/rose-pine-moon.js.map +1 -0
  218. package/dist/themes/data/rose-pine.d.ts +4 -0
  219. package/dist/themes/data/rose-pine.d.ts.map +1 -0
  220. package/dist/themes/data/rose-pine.js +159 -0
  221. package/dist/themes/data/rose-pine.js.map +1 -0
  222. package/dist/themes/data/solarized-dark.d.ts +4 -0
  223. package/dist/themes/data/solarized-dark.d.ts.map +1 -0
  224. package/dist/themes/data/solarized-dark.js +159 -0
  225. package/dist/themes/data/solarized-dark.js.map +1 -0
  226. package/dist/themes/data/solarized-light.d.ts +4 -0
  227. package/dist/themes/data/solarized-light.d.ts.map +1 -0
  228. package/dist/themes/data/solarized-light.js +159 -0
  229. package/dist/themes/data/solarized-light.js.map +1 -0
  230. package/dist/themes/data/textual-ansi.d.ts +4 -0
  231. package/dist/themes/data/textual-ansi.d.ts.map +1 -0
  232. package/dist/themes/data/textual-ansi.js +159 -0
  233. package/dist/themes/data/textual-ansi.js.map +1 -0
  234. package/dist/themes/data/textual-dark.d.ts +4 -0
  235. package/dist/themes/data/textual-dark.d.ts.map +1 -0
  236. package/dist/themes/data/textual-dark.js +159 -0
  237. package/dist/themes/data/textual-dark.js.map +1 -0
  238. package/dist/themes/data/textual-light.d.ts +4 -0
  239. package/dist/themes/data/textual-light.d.ts.map +1 -0
  240. package/dist/themes/data/textual-light.js +159 -0
  241. package/dist/themes/data/textual-light.js.map +1 -0
  242. package/dist/themes/data/tokyo-night.d.ts +4 -0
  243. package/dist/themes/data/tokyo-night.d.ts.map +1 -0
  244. package/dist/themes/data/tokyo-night.js +159 -0
  245. package/dist/themes/data/tokyo-night.js.map +1 -0
  246. package/dist/themes/data/types.d.ts +15 -0
  247. package/dist/themes/data/types.d.ts.map +1 -0
  248. package/dist/themes/data/types.js +2 -0
  249. package/dist/themes/data/types.js.map +1 -0
  250. package/dist/themes/palette.d.ts +20 -0
  251. package/dist/themes/palette.d.ts.map +1 -0
  252. package/dist/themes/palette.js +27 -0
  253. package/dist/themes/palette.js.map +1 -0
  254. package/dist/themes/paletteResolver.d.ts +35 -0
  255. package/dist/themes/paletteResolver.d.ts.map +1 -0
  256. package/dist/themes/paletteResolver.js +88 -0
  257. package/dist/themes/paletteResolver.js.map +1 -0
  258. package/dist/themes/registry.d.ts +17 -0
  259. package/dist/themes/registry.d.ts.map +1 -0
  260. package/dist/themes/registry.js +33 -0
  261. package/dist/themes/registry.js.map +1 -0
  262. package/dist/themes/terminalThemes.d.ts +46 -0
  263. package/dist/themes/terminalThemes.d.ts.map +1 -0
  264. package/dist/themes/terminalThemes.js +268 -0
  265. package/dist/themes/terminalThemes.js.map +1 -0
  266. package/dist/widgets/button.d.ts +47 -0
  267. package/dist/widgets/button.d.ts.map +1 -0
  268. package/dist/widgets/button.js +183 -0
  269. package/dist/widgets/button.js.map +1 -0
  270. package/dist/widgets/checkbox.d.ts +43 -0
  271. package/dist/widgets/checkbox.d.ts.map +1 -0
  272. package/dist/widgets/checkbox.js +144 -0
  273. package/dist/widgets/checkbox.js.map +1 -0
  274. package/dist/widgets/dropdown.d.ts +67 -0
  275. package/dist/widgets/dropdown.d.ts.map +1 -0
  276. package/dist/widgets/dropdown.js +373 -0
  277. package/dist/widgets/dropdown.js.map +1 -0
  278. package/dist/widgets/event-router.d.ts +73 -0
  279. package/dist/widgets/event-router.d.ts.map +1 -0
  280. package/dist/widgets/event-router.js +479 -0
  281. package/dist/widgets/event-router.js.map +1 -0
  282. package/dist/widgets/focus-manager.d.ts +26 -0
  283. package/dist/widgets/focus-manager.d.ts.map +1 -0
  284. package/dist/widgets/focus-manager.js +179 -0
  285. package/dist/widgets/focus-manager.js.map +1 -0
  286. package/dist/widgets/index.d.ts +23 -0
  287. package/dist/widgets/index.d.ts.map +1 -0
  288. package/dist/widgets/index.js +13 -0
  289. package/dist/widgets/index.js.map +1 -0
  290. package/dist/widgets/screen.d.ts +90 -0
  291. package/dist/widgets/screen.d.ts.map +1 -0
  292. package/dist/widgets/screen.js +440 -0
  293. package/dist/widgets/screen.js.map +1 -0
  294. package/dist/widgets/slider.d.ts +55 -0
  295. package/dist/widgets/slider.d.ts.map +1 -0
  296. package/dist/widgets/slider.js +248 -0
  297. package/dist/widgets/slider.js.map +1 -0
  298. package/dist/widgets/static-item.d.ts +41 -0
  299. package/dist/widgets/static-item.d.ts.map +1 -0
  300. package/dist/widgets/static-item.js +62 -0
  301. package/dist/widgets/static-item.js.map +1 -0
  302. package/dist/widgets/text-input.d.ts +50 -0
  303. package/dist/widgets/text-input.d.ts.map +1 -0
  304. package/dist/widgets/text-input.js +242 -0
  305. package/dist/widgets/text-input.js.map +1 -0
  306. package/dist/widgets/toggle.d.ts +46 -0
  307. package/dist/widgets/toggle.d.ts.map +1 -0
  308. package/dist/widgets/toggle.js +169 -0
  309. package/dist/widgets/toggle.js.map +1 -0
  310. package/dist/widgets/types.d.ts +92 -0
  311. package/dist/widgets/types.d.ts.map +1 -0
  312. package/dist/widgets/types.js +13 -0
  313. package/dist/widgets/types.js.map +1 -0
  314. package/dist/widgets/widget-base.d.ts +41 -0
  315. package/dist/widgets/widget-base.d.ts.map +1 -0
  316. package/dist/widgets/widget-base.js +159 -0
  317. package/dist/widgets/widget-base.js.map +1 -0
  318. package/package.json +76 -0
package/README.md ADDED
@@ -0,0 +1,418 @@
1
+ # rich-js
2
+
3
+ A TypeScript port of Python's wonderful [Rich](https://github.com/Textualize/rich) library by @willmcgugan.
4
+
5
+ ## Rich text and beautiful formatting in the terminal
6
+
7
+ The rich-js API makes it easy to add color and style to terminal output. It can also render pretty tables, progress bars, markdown, syntax highlighted source code, tracebacks, and more — out of the box.
8
+
9
+ ## Compatibility
10
+
11
+ Works on Linux, macOS, and Windows. Requires Node.js >= 20. ESM-only.
12
+
13
+ ## Installing
14
+
15
+ ```sh
16
+ npm install rich-js
17
+ ```
18
+
19
+ ## Using the Console
20
+
21
+ Import and construct a `Console` object:
22
+
23
+ ```typescript
24
+ import { Console } from "rich-js";
25
+
26
+ const console = new Console();
27
+ ```
28
+
29
+ The `Console` object has a `print` method similar to the built-in `console.log`. Rich will word-wrap your text to fit within the terminal width.
30
+
31
+ ```typescript
32
+ console.print("Hello", "World!");
33
+ ```
34
+
35
+ Add color and style with a `style` argument:
36
+
37
+ ```typescript
38
+ console.print("Hello, World!", { style: "bold red" });
39
+ ```
40
+
41
+ For finer-grained styling, Rich renders markup using a syntax similar to bbcode:
42
+
43
+ ```typescript
44
+ console.print("Where there is a [bold cyan]Will[/bold cyan] there [u]is[/u] a [i]way[/i].");
45
+ ```
46
+
47
+ ## Rich Library
48
+
49
+ Rich includes a number of built-in renderables for creating elegant terminal output.
50
+
51
+ <details>
52
+ <summary>Log</summary>
53
+
54
+ The `Console` object has a `log()` method similar to `print()`, but adds a timestamp column on the left. Rich will syntax-highlight data structures automatically.
55
+
56
+ ```typescript
57
+ import { Console } from "rich-js";
58
+
59
+ const console = new Console();
60
+
61
+ console.log("Server started");
62
+ console.log({ status: 200, method: "GET", path: "/api/users" });
63
+ ```
64
+
65
+ </details>
66
+
67
+ <details>
68
+ <summary>Emoji</summary>
69
+
70
+ Insert an emoji in console output by placing the name between two colons:
71
+
72
+ ```typescript
73
+ console.print(":smiley: :vampire: :pile_of_poo: :thumbs_up: :raccoon:");
74
+ // 😃 🧛 💩 👍 🦝
75
+ ```
76
+
77
+ </details>
78
+
79
+ <details>
80
+ <summary>Tables</summary>
81
+
82
+ Rich can render flexible tables with unicode box characters. There is a large variety of formatting options for borders, styles, and cell alignment.
83
+
84
+ ```typescript
85
+ import { Console, Table } from "rich-js";
86
+
87
+ const console = new Console();
88
+
89
+ const table = new Table({ title: "Star Wars Box Office" });
90
+ table.addColumn("Date", { style: "dim", width: 12 });
91
+ table.addColumn("Title");
92
+ table.addColumn("Production Budget", { justify: "right" });
93
+ table.addColumn("Box Office", { justify: "right" });
94
+
95
+ table.addRow("Dec 20, 2019", "Star Wars: The Rise of Skywalker", "$275,000,000", "$375,126,118");
96
+ table.addRow("May 25, 2018", "[red]Solo[/red]: A Star Wars Story", "$275,000,000", "$393,151,347");
97
+ table.addRow("Dec 15, 2017", "Star Wars Ep. VIII: The Last Jedi", "$262,000,000", "[bold]$1,332,539,889[/bold]");
98
+
99
+ console.print(table);
100
+ ```
101
+
102
+ The `Table` class resizes columns to fit the available terminal width, wrapping text as required. Console markup is rendered inside cells, and any `Renderable` can be used as a cell value — including other tables.
103
+
104
+ </details>
105
+
106
+ <details>
107
+ <summary>Progress Bars</summary>
108
+
109
+ Rich can render multiple flicker-free progress bars to track long-running tasks.
110
+
111
+ For basic usage, wrap any iterable with `track`:
112
+
113
+ ```typescript
114
+ import { track } from "rich-js";
115
+
116
+ for (const step of track(Array.from({ length: 100 }), { description: "Processing..." })) {
117
+ await doStep(step);
118
+ }
119
+ ```
120
+
121
+ For multiple progress bars and custom columns, use `Progress` directly:
122
+
123
+ ```typescript
124
+ import { Progress, TextColumn, BarColumn, TaskProgressColumn, TimeRemainingColumn } from "rich-js";
125
+
126
+ const progress = new Progress(
127
+ new TextColumn("{task.description}"),
128
+ new BarColumn(),
129
+ new TaskProgressColumn(),
130
+ new TimeRemainingColumn(),
131
+ );
132
+
133
+ await progress.run(async () => {
134
+ const task1 = progress.addTask("Downloading...", { total: 100 });
135
+ const task2 = progress.addTask("Processing...", { total: 200 });
136
+ // ... update tasks
137
+ });
138
+ ```
139
+
140
+ </details>
141
+
142
+ <details>
143
+ <summary>Status</summary>
144
+
145
+ For situations where it is hard to calculate progress, use `Status` to display a spinner animation with a message:
146
+
147
+ ```typescript
148
+ import { Console } from "rich-js";
149
+
150
+ const console = new Console();
151
+
152
+ const status = new Status("[bold green]Working on tasks...", { console });
153
+ status.start();
154
+
155
+ for (const task of tasks) {
156
+ await processTask(task);
157
+ console.log(`${task} complete`);
158
+ }
159
+
160
+ status.stop();
161
+ ```
162
+
163
+ </details>
164
+
165
+ <details>
166
+ <summary>Tree</summary>
167
+
168
+ Rich can render a tree with guide lines — ideal for displaying file structures or any other hierarchical data:
169
+
170
+ ```typescript
171
+ import { Console, Tree } from "rich-js";
172
+
173
+ const console = new Console();
174
+
175
+ const tree = new Tree(":open_file_folder: root");
176
+ const branch = tree.add(":file_folder: src");
177
+ branch.add(":page_facing_up: index.ts");
178
+ branch.add(":page_facing_up: utils.ts");
179
+ tree.add(":page_facing_up: package.json");
180
+
181
+ console.print(tree);
182
+ ```
183
+
184
+ Tree labels can be plain text, markup strings, or any `Renderable`.
185
+
186
+ </details>
187
+
188
+ <details>
189
+ <summary>Columns</summary>
190
+
191
+ Rich can render content in neat columns with equal or optimal width:
192
+
193
+ ```typescript
194
+ import { Console, Columns } from "rich-js";
195
+
196
+ const console = new Console();
197
+
198
+ const items = ["apple", "banana", "cherry", "date", "elderberry", "fig", "grape"];
199
+ console.print(new Columns(items));
200
+ ```
201
+
202
+ </details>
203
+
204
+ <details>
205
+ <summary>Markdown</summary>
206
+
207
+ Rich can render Markdown and translates the formatting to the terminal:
208
+
209
+ ```typescript
210
+ import { Console, Markdown } from "rich-js";
211
+ import { readFileSync } from "fs";
212
+
213
+ const console = new Console();
214
+ const md = new Markdown(readFileSync("README.md", "utf-8"));
215
+ console.print(md);
216
+ ```
217
+
218
+ </details>
219
+
220
+ <details>
221
+ <summary>Syntax Highlighting</summary>
222
+
223
+ Rich can render syntax-highlighted source code:
224
+
225
+ ```typescript
226
+ import { Console, Syntax } from "rich-js";
227
+
228
+ const console = new Console();
229
+
230
+ const code = `
231
+ function greet(name: string): string {
232
+ return \`Hello, \${name}!\`;
233
+ }
234
+ `;
235
+
236
+ const syntax = new Syntax(code, "typescript", { theme: "monokai", lineNumbers: true });
237
+ console.print(syntax);
238
+ ```
239
+
240
+ </details>
241
+
242
+ <details>
243
+ <summary>Tracebacks</summary>
244
+
245
+ Rich can render beautiful tracebacks that are easier to read and show more context than standard Node.js errors:
246
+
247
+ ```typescript
248
+ import { Console, Traceback } from "rich-js";
249
+
250
+ const console = new Console();
251
+
252
+ try {
253
+ riskyOperation();
254
+ } catch (error) {
255
+ console.print(new Traceback(error));
256
+ }
257
+ ```
258
+
259
+ </details>
260
+
261
+ ## Custom Renderables
262
+
263
+ All Rich renderables use the `Renderable` protocol. You can implement your own:
264
+
265
+ ```typescript
266
+ import type { Renderable, RenderOptions } from "rich-js";
267
+ import { Segment } from "rich-js";
268
+
269
+ class Greeting implements Renderable {
270
+ render(options: RenderOptions): Iterable<Segment> {
271
+ return [new Segment("Hello, World!\n")];
272
+ }
273
+ }
274
+
275
+ console.print(new Greeting());
276
+ ```
277
+
278
+ ## Console Options
279
+
280
+ ```typescript
281
+ const console = new Console({
282
+ colorSystem: "truecolor", // null | "auto" | "standard" | "256" | "truecolor" | "windows"
283
+ width: 120, // override terminal width
284
+ stderr: true, // write to stderr
285
+ record: true, // record output for export
286
+ highlight: false, // disable auto-highlighting
287
+ markup: false, // disable markup processing
288
+ });
289
+ ```
290
+
291
+ When `record: true`, export output after the fact:
292
+
293
+ ```typescript
294
+ const text = console.exportText();
295
+ const html = console.exportHtml();
296
+ console.saveHtml("output.html");
297
+ ```
298
+
299
+ ## Demos
300
+
301
+ Three interactive TUI demos exercise the library's renderables against real-world use cases. Each runs in alt-screen mode with flicker-free rendering. A fourth one-shot demo prints every built-in `Joiner` for visual comparison.
302
+
303
+ ```sh
304
+ npm run demo # rich-explore: file browser
305
+ npm run sessions # claude-sessions: Claude Code session browser
306
+ npm run colors # rich-colors: interactive color palette generator
307
+ npm run strip # rich-strip: side-by-side joiner showcase (one-shot)
308
+ ```
309
+
310
+ ### rich-explore — TUI file browser + markdown/code reader
311
+
312
+ A two-pane file browser with a directory tree on the left and a file preview on the right. Navigate with vim-style keys, Tab to switch focus, Enter/arrow keys to expand/collapse directories.
313
+
314
+ ```sh
315
+ npm run demo # browse current directory
316
+ npm run demo -- /some/path # browse a specific path
317
+ ```
318
+
319
+ **Features exercised:**
320
+
321
+ | Module | How it's used |
322
+ |---|---|
323
+ | `Console` | Render orchestrator, style application, color-system detection |
324
+ | `Layout` | Row split (tree / preview), column split (header / body / footer), `ratio` and `size` allocation |
325
+ | `Panel` | Bordered panes with dynamic titles (`▸ Tree (20)`), `borderStyle`, `padding`, focus-aware styling |
326
+ | `Tree` | Recursive directory tree with guide lines, `guide_style`, mixed RichText labels |
327
+ | `Table` + `Column` | Directory listing (name, kind, size, mtime), styled headers, right-justified columns |
328
+ | `Markdown` | Renders `.md` files in the preview pane |
329
+ | `Syntax` | Syntax-highlighted source code with `lineNumbers` and per-extension language detection |
330
+ | `JSONRenderable` | Pretty-printed + highlighted JSON file preview |
331
+ | `RichText` + `Span` | Labels, headers, status bar; `.stylize()`, `.append()`, `end` control |
332
+ | `Style` | Parsed inline everywhere (`"bold cyan"`, `"reverse bold"`, `"bold white on blue"`) |
333
+ | `Segment` | Used directly in the `Window` renderable for line splitting, padding, and clipping |
334
+ | `Renderable` protocol | Custom `Window` class implements `Renderable` for viewport clipping |
335
+ | `Box` | `ROUNDED` (Panel default), `HEAVY_HEAD` (Table default) |
336
+
337
+ ### claude-sessions — Claude Code session browser
338
+
339
+ Browses `~/.claude/projects/` JSONL session files. Two-level sidebar (projects → sessions) on top, conversation viewer below. Pretty-prints every block type (human turns, assistant responses, tool calls, subagents, system events, errors) with per-block raw-JSON toggle. Includes local search, global cross-file search, subagent drill-down with session stack, and hidden-block reveal.
340
+
341
+ ```sh
342
+ npm run sessions
343
+ ```
344
+
345
+ **Key bindings:** `↑↓/jk` navigate, `→/Enter` open/drill, `←` back, `Tab` focus, `\` toggle browser, `v` raw view, `e` expand, `H` hidden blocks, `/` local search, `S` global search, `n/N` next/prev match, `p` parent, `u` pop subagent, `q` quit.
346
+
347
+ **Features exercised (incremental to rich-explore):**
348
+
349
+ | Module | How it's used |
350
+ |---|---|
351
+ | `Rule` | Turn-duration system blocks rendered as horizontal dividers; input/output separators in tool-call blocks |
352
+ | `Group` | Composes multi-section tool-call blocks (input + Rule + result) into a single renderable |
353
+ | `Pretty` | Per-block raw view (toggled with `v`) — exercises `ReprHighlighter`, indent guides, `maxString`, `expandAll` |
354
+ | `Traceback` | Error blocks with stack traces render via `Traceback` for styled frame display |
355
+ | `Markdown` | Assistant text rendering (Claude output is often markdown) |
356
+ | `Syntax` | Bash command highlighting in tool-call input summaries |
357
+ | `Panel` | Six distinct border-color schemes by block kind (cyan/blue/yellow/red/magenta/green) |
358
+ | `Layout` | Column split (browser-on-top / viewer-on-bottom), dynamic height budgeting |
359
+
360
+ ### rich-colors — Interactive color palette generator
361
+
362
+ An interactive palette generator exploring `Color`, `Style`, and terminal color math. Generates palettes from seed colors, displays color swatches, and lets you adjust parameters interactively.
363
+
364
+ ```sh
365
+ npm run colors
366
+ ```
367
+
368
+ **Features exercised (incremental to above):**
369
+
370
+ | Module | How it's used |
371
+ |---|---|
372
+ | `Color` | Direct `Color` construction, `blendRgb`, color math, palette generation |
373
+ | `TerminalTheme` | `DEFAULT_TERMINAL_THEME`, `MONOKAI`, `SVG_EXPORT_THEME` theme constants |
374
+ | `ANSI_COLOR_NAMES` | Named ANSI color enumeration and display |
375
+ | `Style` | Direct `Style` construction from `Color` objects (not just string parsing) |
376
+ | `Spinner` | Visual activity indicator in input mode |
377
+
378
+ ---
379
+
380
+ ### Coverage summary
381
+
382
+ **Exercised across demos:**
383
+
384
+ Core: `Console`, `Style`/`StyleStack`, `RichText`/`Span`, `Segment`, `Box` (multiple variants), `Color`/`blendRgb`/palettes, `Renderable`/`Measurable` protocol, `Measurement`, `cells` (transitively), `ReprHighlighter`, `JSONHighlighter`, `Spinner` data, `TerminalTheme`
385
+
386
+ Renderables: `Layout`, `Panel`, `Tree`, `Table`/`Column`, `Markdown`, `Syntax`, `JSONRenderable`, `Rule`, `Group`, `Spinner`, `Pretty`, `Traceback`
387
+
388
+ **Bugs found and fixed via demo integration:**
389
+
390
+ | Bug | Location | Impact | Fix |
391
+ |---|---|---|---|
392
+ | `Live.refresh()` strips all ANSI styles | `src/renderables/live.ts:106` | Every renderable flowing through `Live` (including `Status`, `Progress`, `Spinner`) appeared unstyled | Apply `style.render(text, colorSystem)` instead of bare `s.text` |
393
+ | `Progress.render()` drops column styles | `src/renderables/progress.ts:273` | Progress percentage, timing, and spinner styles were stripped when building table cells | Use `RichText.append(text, style)` to preserve segment styles |
394
+ | `Tree` emits double blank lines | `src/renderables/tree.ts:98,122` | Label rendering and the explicit `Segment.line()` both contributed a newline, producing blank lines between tree entries | Make `RichText` stop emitting a trailing newline so `Tree`'s explicit `yield Segment.line()` remains the only line break |
395
+ | `Spinner` constructor rejects `undefined` name | `src/renderables/spinner.ts:36` | `SpinnerColumn` (used by `Progress`) passed optional `string \| undefined` to required `string` parameter | Make `name` optional, default to `DEFAULT_SPINNER` |
396
+
397
+ **Not yet exercised — candidates for new demos or demo additions:**
398
+
399
+ | Module | Notes | Suggested coverage |
400
+ |---|---|---|
401
+ | `Status` | Spinner + message display | Loading indicator for large sessions in claude-sessions |
402
+ | `Prompt` / `IntPrompt` / `FloatPrompt` / `Confirm` | Interactive input via readline | Add a go-to-path prompt in rich-explore; incompatible with raw-mode loops so needs a modal switch |
403
+ | `emoji` | Shortcode substitution (`:smiley:` → 😃) | Enable in markup-rendered block text in claude-sessions |
404
+ | `NullHighlighter` / `RegexHighlighter` | Specialized highlighters not yet exercised | `RegexHighlighter` for search-term highlighting in claude-sessions |
405
+ | `StyleStack` / `Theme` / `DEFAULT_STYLES` | Theme customization | Add a theme switcher to rich-colors |
406
+ | `Color` downgrading | `standard` / `256` / `windows` color system fallbacks | Add a color-system picker to rich-colors |
407
+ | `Console` recording | `record`, `exportText`, `exportHtml`, `saveHtml` | Add an export-to-HTML feature to claude-sessions |
408
+ | Most `Box` variants | `ASCII`, `SQUARE`, `MINIMAL`, `HEAVY`, `DOUBLE`, `MARKDOWN`, etc. | Add a box-style picker to rich-explore's Panel borders |
409
+ | `Measurement.get()` / `measureRenderables` | Explicit width measurement | Used internally; could add a measurement debug overlay |
410
+
411
+ ## Environment Variables
412
+
413
+ | Variable | Effect |
414
+ |---|---|
415
+ | `NO_COLOR` | Disable all color |
416
+ | `FORCE_COLOR` | Enable color regardless of `TERM` |
417
+ | `TERM=dumb` | Disable color and style |
418
+ | `COLUMNS` / `LINES` | Override terminal dimensions |
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Box-drawing character sets for borders and table grids.
3
+ */
4
+ import { Segment } from "./segment.js";
5
+ import type { Style } from "./style.js";
6
+ export interface BoxChars {
7
+ topLeft: string;
8
+ top: string;
9
+ topDivider: string;
10
+ topRight: string;
11
+ headLeft: string;
12
+ headVertical: string;
13
+ headRight: string;
14
+ midLeft: string;
15
+ mid: string;
16
+ midVertical: string;
17
+ midRight: string;
18
+ bottomLeft: string;
19
+ bottom: string;
20
+ bottomDivider: string;
21
+ bottomRight: string;
22
+ left: string;
23
+ right: string;
24
+ vertical: string;
25
+ }
26
+ export type RowLevel = "head" | "row" | "foot" | "mid";
27
+ export interface SubstituteOptions {
28
+ asciiOnly?: boolean;
29
+ safe?: boolean;
30
+ }
31
+ export declare class Box {
32
+ readonly topLeft: string;
33
+ readonly top: string;
34
+ readonly topDivider: string;
35
+ readonly topRight: string;
36
+ readonly headLeft: string;
37
+ readonly headVertical: string;
38
+ readonly headRight: string;
39
+ readonly midLeft: string;
40
+ readonly mid: string;
41
+ readonly midVertical: string;
42
+ readonly midRight: string;
43
+ readonly bottomLeft: string;
44
+ readonly bottom: string;
45
+ readonly bottomDivider: string;
46
+ readonly bottomRight: string;
47
+ readonly left: string;
48
+ readonly right: string;
49
+ readonly vertical: string;
50
+ constructor(chars: BoxChars);
51
+ /**
52
+ * Renders the top border row for given column widths.
53
+ */
54
+ getTop(widths: number[], style?: Style, edge?: boolean): Segment[];
55
+ /**
56
+ * Renders a separator row.
57
+ */
58
+ getRow(widths: number[], level: RowLevel, style?: Style, edge?: boolean): Segment[];
59
+ /**
60
+ * Renders the bottom border row.
61
+ */
62
+ getBottom(widths: number[], style?: Style, edge?: boolean): Segment[];
63
+ /**
64
+ * Returns a new Box with characters substituted for ASCII or safe alternatives.
65
+ * asciiOnly: all characters become ASCII (+, -, |)
66
+ * safe: problematic characters (e.g. rounded corners) replaced with square equivalents
67
+ */
68
+ substitute(options?: SubstituteOptions): Box;
69
+ private safeSubstitute;
70
+ private getRowChars;
71
+ }
72
+ export declare const ASCII: Box;
73
+ export declare const ASCII2: Box;
74
+ export declare const ASCII_DOUBLE_HEAD: Box;
75
+ export declare const SQUARE: Box;
76
+ export declare const SQUARE_DOUBLE_HEAD: Box;
77
+ export declare const MINIMAL: Box;
78
+ export declare const MINIMAL_HEAVY_HEAD: Box;
79
+ export declare const MINIMAL_DOUBLE_HEAD: Box;
80
+ export declare const SIMPLE: Box;
81
+ export declare const SIMPLE_HEAD: Box;
82
+ export declare const SIMPLE_HEAVY: Box;
83
+ export declare const HORIZONTALS: Box;
84
+ export declare const ROUNDED: Box;
85
+ export declare const HEAVY: Box;
86
+ export declare const HEAVY_EDGE: Box;
87
+ export declare const HEAVY_HEAD: Box;
88
+ export declare const DOUBLE: Box;
89
+ export declare const DOUBLE_EDGE: Box;
90
+ export declare const MARKDOWN: Box;
91
+ //# sourceMappingURL=box.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"box.d.ts","sourceRoot":"","sources":["../../src/core/box.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EA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