@promptctl/rich-js 0.18.1 → 0.20.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 (169) hide show
  1. package/README.md +11 -8
  2. package/dist/core/box.d.ts +3 -1
  3. package/dist/core/box.js +6 -13
  4. package/dist/core/cells.d.ts +61 -28
  5. package/dist/core/cells.js +171 -124
  6. package/dist/core/clock.d.ts +48 -0
  7. package/dist/core/clock.js +42 -0
  8. package/dist/core/color.d.ts +99 -18
  9. package/dist/core/color.js +334 -146
  10. package/dist/core/console.d.ts +38 -7
  11. package/dist/core/console.js +159 -90
  12. package/dist/core/easing.d.ts +86 -0
  13. package/dist/core/easing.js +171 -0
  14. package/dist/core/env.d.ts +16 -0
  15. package/dist/core/env.js +16 -0
  16. package/dist/core/export-html.js +1 -4
  17. package/dist/core/export-lines.d.ts +22 -13
  18. package/dist/core/export-lines.js +37 -19
  19. package/dist/core/export-svg.d.ts +49 -0
  20. package/dist/core/export-svg.js +213 -0
  21. package/dist/core/fnv1a.d.ts +10 -0
  22. package/dist/core/fnv1a.js +17 -0
  23. package/dist/core/highlighter.d.ts +2 -2
  24. package/dist/core/highlighter.js +113 -47
  25. package/dist/core/json.js +1 -1
  26. package/dist/core/markup.d.ts +28 -7
  27. package/dist/core/markup.js +235 -312
  28. package/dist/core/measure.d.ts +3 -3
  29. package/dist/core/measure.js +12 -7
  30. package/dist/core/memo.d.ts +19 -0
  31. package/dist/core/memo.js +34 -0
  32. package/dist/core/noise.d.ts +31 -0
  33. package/dist/core/noise.js +94 -0
  34. package/dist/core/osc8.d.ts +6 -6
  35. package/dist/core/osc8.js +9 -21
  36. package/dist/core/paint.d.ts +107 -0
  37. package/dist/core/paint.js +161 -0
  38. package/dist/core/place.d.ts +1 -1
  39. package/dist/core/place.js +4 -6
  40. package/dist/core/pretty.d.ts +126 -2
  41. package/dist/core/pretty.js +571 -105
  42. package/dist/core/protocol.d.ts +43 -3
  43. package/dist/core/protocol.js +23 -2
  44. package/dist/core/render.d.ts +33 -30
  45. package/dist/core/render.js +43 -83
  46. package/dist/core/segment.d.ts +6 -5
  47. package/dist/core/segment.js +11 -15
  48. package/dist/core/selection.d.ts +12 -0
  49. package/dist/core/selection.js +14 -0
  50. package/dist/core/strip.d.ts +116 -74
  51. package/dist/core/strip.js +266 -217
  52. package/dist/core/style.d.ts +27 -7
  53. package/dist/core/style.js +106 -41
  54. package/dist/core/text.d.ts +43 -16
  55. package/dist/core/text.js +180 -59
  56. package/dist/core/wrap.d.ts +5 -0
  57. package/dist/core/wrap.js +16 -3
  58. package/dist/host/app.d.ts +95 -17
  59. package/dist/host/app.js +201 -61
  60. package/dist/host/index.d.ts +4 -1
  61. package/dist/host/index.js +1 -0
  62. package/dist/host/input.d.ts +84 -0
  63. package/dist/host/input.js +498 -0
  64. package/dist/host/terminal-host.d.ts +15 -2
  65. package/dist/host/terminal-host.js +2 -0
  66. package/dist/index.d.ts +26 -14
  67. package/dist/index.js +17 -7
  68. package/dist/node/prompt.d.ts +13 -0
  69. package/dist/node/prompt.js +30 -9
  70. package/dist/node/save.d.ts +4 -3
  71. package/dist/node/save.js +6 -3
  72. package/dist/node/terminal-host.d.ts +10 -2
  73. package/dist/node/terminal-host.js +7 -0
  74. package/dist/node/traceback.d.ts +2 -1
  75. package/dist/node/traceback.js +3 -39
  76. package/dist/renderables/align.js +2 -9
  77. package/dist/renderables/columns.d.ts +45 -29
  78. package/dist/renderables/columns.js +142 -103
  79. package/dist/renderables/constrain.js +6 -12
  80. package/dist/renderables/effect.d.ts +113 -0
  81. package/dist/renderables/effect.js +182 -0
  82. package/dist/renderables/effects.d.ts +252 -0
  83. package/dist/renderables/effects.js +565 -0
  84. package/dist/renderables/embed.d.ts +94 -31
  85. package/dist/renderables/embed.js +141 -45
  86. package/dist/renderables/group.d.ts +6 -3
  87. package/dist/renderables/group.js +5 -0
  88. package/dist/renderables/layout.d.ts +6 -23
  89. package/dist/renderables/layout.js +24 -113
  90. package/dist/renderables/list-view.d.ts +42 -0
  91. package/dist/renderables/list-view.js +78 -0
  92. package/dist/renderables/live.d.ts +40 -16
  93. package/dist/renderables/live.js +96 -83
  94. package/dist/renderables/markdown.d.ts +16 -2
  95. package/dist/renderables/markdown.js +521 -118
  96. package/dist/renderables/padding.d.ts +22 -1
  97. package/dist/renderables/padding.js +30 -24
  98. package/dist/renderables/panel.d.ts +31 -33
  99. package/dist/renderables/panel.js +137 -141
  100. package/dist/renderables/progress.d.ts +110 -16
  101. package/dist/renderables/progress.js +212 -81
  102. package/dist/renderables/progressBar.d.ts +24 -4
  103. package/dist/renderables/progressBar.js +78 -23
  104. package/dist/renderables/prompt.d.ts +37 -15
  105. package/dist/renderables/prompt.js +125 -85
  106. package/dist/renderables/ratio.d.ts +123 -0
  107. package/dist/renderables/ratio.js +213 -0
  108. package/dist/renderables/rule.d.ts +3 -2
  109. package/dist/renderables/rule.js +50 -52
  110. package/dist/renderables/spinner.d.ts +28 -2
  111. package/dist/renderables/spinner.js +52 -19
  112. package/dist/renderables/status.d.ts +13 -7
  113. package/dist/renderables/status.js +15 -29
  114. package/dist/renderables/syntax.d.ts +37 -7
  115. package/dist/renderables/syntax.js +134 -83
  116. package/dist/renderables/table.d.ts +58 -20
  117. package/dist/renderables/table.js +373 -197
  118. package/dist/renderables/traceback.d.ts +5 -4
  119. package/dist/renderables/traceback.js +239 -68
  120. package/dist/renderables/tree.d.ts +10 -2
  121. package/dist/renderables/tree.js +61 -34
  122. package/dist/renderables/viewport.d.ts +30 -0
  123. package/dist/renderables/viewport.js +61 -7
  124. package/dist/template-bindings/color-funcs.d.ts +31 -9
  125. package/dist/template-bindings/color-funcs.js +40 -14
  126. package/dist/template-bindings/helpers.d.ts +4 -2
  127. package/dist/template-bindings/helpers.js +5 -20
  128. package/dist/template-bindings/index.d.ts +29 -17
  129. package/dist/template-bindings/index.js +36 -20
  130. package/dist/template-bindings/palette-funcs.d.ts +3 -1
  131. package/dist/template-bindings/palette-funcs.js +11 -7
  132. package/dist/template-bindings/style-funcs.js +4 -2
  133. package/dist/themes/buildPalette.d.ts +24 -3
  134. package/dist/themes/buildPalette.js +52 -8
  135. package/dist/themes/colorMath.d.ts +29 -17
  136. package/dist/themes/colorMath.js +74 -48
  137. package/dist/themes/colorRef.d.ts +2 -17
  138. package/dist/themes/colorRef.js +13 -31
  139. package/dist/themes/palette.d.ts +24 -0
  140. package/dist/themes/palette.js +46 -3
  141. package/dist/themes/ramp.d.ts +21 -34
  142. package/dist/themes/ramp.js +23 -42
  143. package/dist/themes/registry.js +39 -28
  144. package/dist/widgets/button.d.ts +2 -6
  145. package/dist/widgets/button.js +9 -40
  146. package/dist/widgets/checkbox.d.ts +2 -5
  147. package/dist/widgets/checkbox.js +9 -31
  148. package/dist/widgets/dropdown.d.ts +2 -5
  149. package/dist/widgets/dropdown.js +17 -51
  150. package/dist/widgets/event-router.d.ts +31 -40
  151. package/dist/widgets/event-router.js +52 -483
  152. package/dist/widgets/index.d.ts +2 -1
  153. package/dist/widgets/ink.d.ts +22 -0
  154. package/dist/widgets/ink.js +31 -0
  155. package/dist/widgets/slider.d.ts +2 -5
  156. package/dist/widgets/slider.js +11 -34
  157. package/dist/widgets/text-input.d.ts +19 -10
  158. package/dist/widgets/text-input.js +156 -147
  159. package/dist/widgets/themed-widget.d.ts +20 -0
  160. package/dist/widgets/themed-widget.js +89 -0
  161. package/dist/widgets/toggle.d.ts +2 -5
  162. package/dist/widgets/toggle.js +8 -31
  163. package/dist/widgets/types.d.ts +8 -25
  164. package/dist/widgets/types.js +8 -0
  165. package/dist/widgets/widget-app.d.ts +24 -7
  166. package/dist/widgets/widget-app.js +35 -18
  167. package/dist/widgets/widget-base.d.ts +2 -0
  168. package/dist/widgets/widget-base.js +9 -2
  169. package/package.json +31 -17
@@ -24,6 +24,11 @@ export interface PrettyOptions {
24
24
  indent?: number;
25
25
  expandAll?: boolean;
26
26
  maxLength?: number;
27
+ /**
28
+ * How many characters of a string to show before cutting it, counting the
29
+ * rest after the closing quote. A character is a grapheme cluster, not a
30
+ * UTF-16 code unit: `"😀😀"` is two, though its `length` is four.
31
+ */
27
32
  maxString?: number;
28
33
  /**
29
34
  * How many levels of nesting to descend before eliding. Unbounded by default.
@@ -34,6 +39,11 @@ export interface PrettyOptions {
34
39
  * `Set {...}` — visible, so the reader knows the value continues.
35
40
  */
36
41
  maxDepth?: number;
42
+ /**
43
+ * Draw a `│` in the first cell of each level of indent. Off by default, as
44
+ * the reference's is, and never drawn on an ASCII-only console, where the
45
+ * reference draws none.
46
+ */
37
47
  indentGuides?: boolean;
38
48
  /**
39
49
  * Who colours the formatted text. Defaults to a `ReprHighlighter`.
@@ -43,9 +53,46 @@ export interface PrettyOptions {
43
53
  * `highlighter` have to reach the output the same way they reach a printed
44
54
  * string — a `Pretty` reaching for its own singleton would silently outrank
45
55
  * both. `NullHighlighter` is the "none" case.
56
+ *
57
+ * It reads each `Map` entry's `=>` as `= `: the arrow is this formatter's
58
+ * punctuation, not the data's, and its `>` would close a repr tag opened by
59
+ * any `<` before it.
46
60
  */
47
61
  highlighter?: Highlighter;
48
62
  }
63
+ /**
64
+ * What a value is bounded by when whoever formats it has not seen it:
65
+ * `Console.print`'s data arguments, and a thrown value `Traceback` reports.
66
+ *
67
+ * Such a caller has to assume nothing about the value's size, in any of the
68
+ * three ways a value can be large. Unbounded, a buffer emits a line per byte, a
69
+ * deeply nested object descends until the stack gives out, and a single
70
+ * response body assigned to a field arrives in full — each of them a line that
71
+ * costs megabytes or hangs the terminal. All three bounds announce themselves
72
+ * in the output (`... +N`, `{...}`, `+N` after the closing quote), so this
73
+ * truncates visibly and never silently. [LAW:no-silent-failure]
74
+ *
75
+ * A caller constructing a `Pretty` has seen their data and gets no defaults;
76
+ * these belong to the paths that format what they were handed, not to the
77
+ * formatter.
78
+ */
79
+ export declare const UNSEEN_DATA_BOUNDS: {
80
+ readonly maxLength: 100;
81
+ readonly maxDepth: 16;
82
+ readonly maxString: 1000;
83
+ };
84
+ /**
85
+ * Whether `Pretty` lays a value out as a container — brackets and positions —
86
+ * rather than spelling it as one piece of text. Emptiness and the depth cap do
87
+ * not enter into it; `[]` is still a container that happens to print on one
88
+ * line. This is Python Rich's `is_expandable`, and `Console.print` reads it to
89
+ * give a container lines of its own.
90
+ *
91
+ * A value whose reflection throws is not one, as in the reference's
92
+ * `_safe_isinstance`: `Pretty` then formats it as text, and the throw reaches
93
+ * the output as `threw`'s marker rather than taking the print down.
94
+ */
95
+ export declare function isExpandable(value: unknown): boolean;
49
96
  export declare class Pretty implements Renderable, Measurable {
50
97
  readonly data: unknown;
51
98
  readonly indent: number;
@@ -55,6 +102,7 @@ export declare class Pretty implements Renderable, Measurable {
55
102
  readonly maxDepth: number;
56
103
  readonly indentGuides: boolean;
57
104
  readonly highlighter: Highlighter;
105
+ private readonly cutStrings;
58
106
  constructor(data: unknown, options?: PrettyOptions);
59
107
  render(options: RenderOptions): Iterable<Segment>;
60
108
  /** The value laid out for `options.maxWidth` and highlighted: the text this renders. */
@@ -72,6 +120,42 @@ export declare class Pretty implements Renderable, Measurable {
72
120
  * traversals.
73
121
  */
74
122
  private _scalar;
123
+ /**
124
+ * `value` quoted, and cut to `maxString` when it is longer.
125
+ *
126
+ * The dropped count is an annotation about the value, not part of it, so it
127
+ * goes after the closing quote — the way `maxLength`'s `... +N` sits beside
128
+ * the kept entries rather than inside the last one. Inside the quotes it
129
+ * reads as content, and copying it out yields a string the program never
130
+ * held.
131
+ *
132
+ * A cluster is at least one code unit, so a string no longer than the cap in
133
+ * code units is within it in clusters, and needs no segmenting.
134
+ */
135
+ private _string;
136
+ /**
137
+ * A key as an object literal would spell it: bare when it is a name or an
138
+ * index, which reads as itself, and quoted as a string otherwise. Rich reprs
139
+ * every key; printed raw, `"a b"` was indistinguishable from two words and a
140
+ * `\r` in one was dropped by `RichText`, so the key shown was not the key held.
141
+ * Quoting only what needs it keeps the JavaScript reading `{ a: 1 }`. A
142
+ * quoted key is a string and `maxString` cuts it; a bare one is a name.
143
+ */
144
+ private _key;
145
+ /**
146
+ * `value` cut to `max` grapheme clusters, with the rest counted after the
147
+ * closing quote.
148
+ *
149
+ * The unit is the cluster of the value, counted before `quoted` escapes it. A code unit cut can keep half a surrogate pair, which
150
+ * JSON.stringify prints as a `\ud83d` escape; a code point cut can keep half
151
+ * a flag or a ZWJ family. Either way the kept prefix shows something the
152
+ * value never held, and the dropped count is in a unit nobody can see.
153
+ *
154
+ * Counting clusters reads the whole string, and the traversals ask for the
155
+ * same scalar once per probe at every level above it, so the answer is
156
+ * memoised per value.
157
+ */
158
+ private _cutString;
75
159
  /**
76
160
  * A container, or the text standing in for one that is empty or past the
77
161
  * depth cap.
@@ -100,6 +184,24 @@ export declare class Pretty implements Renderable, Measurable {
100
184
  private _format;
101
185
  /** The arms for a non-null object, with `value` already on the open path. */
102
186
  private _formatObject;
187
+ /**
188
+ * Where a container starts: where it stands, or — when its opener will not
189
+ * fit after what precedes it on its line and will fit on a hanging line —
190
+ * that hanging line, with `lead` the break that reaches it.
191
+ *
192
+ * This is `_place`'s rule for one-piece text, with `open` as the first word:
193
+ * a bracket is a literal no cut can shorten, so moving is the only way it
194
+ * fits. A container moved there is on a line of that indent, its children
195
+ * and closer included, so it reads as its key's value rather than its key's
196
+ * sibling. It moves only to fit: past the edge, the hanging line has no more
197
+ * room than this one.
198
+ */
199
+ private _opening;
200
+ /**
201
+ * `at` on a line that starts at `inset`. The one place a hang is derived: a
202
+ * line's continuation rows and its children both sit one indent past it.
203
+ */
204
+ private _onLine;
103
205
  /**
104
206
  * One position, with every value in it laid out.
105
207
  *
@@ -113,7 +215,8 @@ export declare class Pretty implements Renderable, Measurable {
113
215
  * of the same fact. `_joinOneLine`'s probe sibling tracks the analogous
114
216
  * thing via `budget` shrinking instead, because a probe already discards
115
217
  * anything that overruns and so never needs to know where a multi-line
116
- * insert's last line ends.
218
+ * insert's last line ends. Where that line *starts* is the one fact `out`
219
+ * cannot give back, so it comes from each piece's `Laid.inset` instead.
117
220
  *
118
221
  * Each hole's `reserve` is its own `tail` plus, only for the slot's last
119
222
  * hole, whatever `at.reserve` already asked this whole slot to leave room
@@ -122,6 +225,28 @@ export declare class Pretty implements Renderable, Measurable {
122
225
  * `out` grows past it.
123
226
  */
124
227
  private _expandSlot;
228
+ /**
229
+ * Text that is one piece — a scalar, a value that spells itself, a marker —
230
+ * set down at `at.column` on a line this formatter owns.
231
+ *
232
+ * A container that will not fit expands; one piece of text has no structure
233
+ * to expand into, so it wraps, and the wrap is laid out here rather than left
234
+ * to `RichText`. Left there, it broke at the console's edge and resumed at
235
+ * column 0 — under the enclosing key, or under nothing — which is the
236
+ * structure a reader of nested data relies on, broken. So every line after the
237
+ * first hangs at `at.hang`, a line of the value's own (`Error`'s message, a
238
+ * multi-line `toString`) as much as a wrapped one, and each is cut to the
239
+ * width left there. Every row of the last line also leaves `at.reserve`, as a
240
+ * container's compact try does, for the `,` or `" => "` that follows it.
241
+ *
242
+ * The first line is where the text already stands. When not even its first
243
+ * word fits there, it starts on a hanging line instead — the only case that
244
+ * moves it, and one taken only when that line starts further left and so has
245
+ * more room; otherwise the word is folded where it stands. A Map value after
246
+ * a long key is the case: `[1, 2, 3, 10] =>` ends the line and `"v"` hangs
247
+ * beneath it, where it used to wrap to column 0.
248
+ */
249
+ private _place;
125
250
  /** The one-line form of a value, or `null` when it will not fit `at.budget`. */
126
251
  private _oneLine;
127
252
  /**
@@ -140,5 +265,4 @@ export declare class Pretty implements Renderable, Measurable {
140
265
  private _joinOneLine;
141
266
  /** One position on one line, or `null` when any value in it will not fit. */
142
267
  private _slotOneLine;
143
- private _addIndentGuides;
144
268
  }