@promptctl/rich-js 0.7.0 → 0.9.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 (201) hide show
  1. package/README.md +99 -31
  2. package/dist/core/box.d.ts +96 -42
  3. package/dist/core/box.d.ts.map +1 -1
  4. package/dist/core/box.js +348 -490
  5. package/dist/core/box.js.map +1 -1
  6. package/dist/core/cells.d.ts +46 -1
  7. package/dist/core/cells.d.ts.map +1 -1
  8. package/dist/core/cells.js +55 -14
  9. package/dist/core/cells.js.map +1 -1
  10. package/dist/core/color.d.ts.map +1 -1
  11. package/dist/core/color.js +22 -8
  12. package/dist/core/color.js.map +1 -1
  13. package/dist/core/console.d.ts +30 -14
  14. package/dist/core/console.d.ts.map +1 -1
  15. package/dist/core/console.js +176 -104
  16. package/dist/core/console.js.map +1 -1
  17. package/dist/core/highlighter.d.ts +2 -1
  18. package/dist/core/highlighter.d.ts.map +1 -1
  19. package/dist/core/highlighter.js +28 -6
  20. package/dist/core/highlighter.js.map +1 -1
  21. package/dist/{renderables → core}/json.d.ts +8 -3
  22. package/dist/core/json.d.ts.map +1 -0
  23. package/dist/{renderables → core}/json.js +7 -2
  24. package/dist/core/json.js.map +1 -0
  25. package/dist/core/markup.d.ts +6 -9
  26. package/dist/core/markup.d.ts.map +1 -1
  27. package/dist/core/markup.js +153 -47
  28. package/dist/core/markup.js.map +1 -1
  29. package/dist/core/measure.d.ts +11 -0
  30. package/dist/core/measure.d.ts.map +1 -1
  31. package/dist/core/measure.js +15 -3
  32. package/dist/core/measure.js.map +1 -1
  33. package/dist/core/oklch.d.ts +22 -0
  34. package/dist/core/oklch.d.ts.map +1 -1
  35. package/dist/core/oklch.js +62 -18
  36. package/dist/core/oklch.js.map +1 -1
  37. package/dist/core/pretty.d.ts +122 -0
  38. package/dist/core/pretty.d.ts.map +1 -0
  39. package/dist/core/pretty.js +398 -0
  40. package/dist/core/pretty.js.map +1 -0
  41. package/dist/core/protocol.d.ts +80 -0
  42. package/dist/core/protocol.d.ts.map +1 -1
  43. package/dist/core/protocol.js +85 -0
  44. package/dist/core/protocol.js.map +1 -1
  45. package/dist/core/segment.d.ts +26 -0
  46. package/dist/core/segment.d.ts.map +1 -1
  47. package/dist/core/segment.js +45 -0
  48. package/dist/core/segment.js.map +1 -1
  49. package/dist/core/strip.d.ts +9 -5
  50. package/dist/core/strip.d.ts.map +1 -1
  51. package/dist/core/strip.js +39 -41
  52. package/dist/core/strip.js.map +1 -1
  53. package/dist/core/style.d.ts +19 -0
  54. package/dist/core/style.d.ts.map +1 -1
  55. package/dist/core/style.js +46 -38
  56. package/dist/core/style.js.map +1 -1
  57. package/dist/core/subscription.d.ts +13 -0
  58. package/dist/core/subscription.d.ts.map +1 -0
  59. package/dist/core/subscription.js +13 -0
  60. package/dist/core/subscription.js.map +1 -0
  61. package/dist/core/text.d.ts +102 -4
  62. package/dist/core/text.d.ts.map +1 -1
  63. package/dist/core/text.js +332 -162
  64. package/dist/core/text.js.map +1 -1
  65. package/dist/core/wrap.d.ts +42 -0
  66. package/dist/core/wrap.d.ts.map +1 -0
  67. package/dist/core/wrap.js +128 -0
  68. package/dist/core/wrap.js.map +1 -0
  69. package/dist/host/host-stream.d.ts.map +1 -0
  70. package/dist/host/host-stream.js.map +1 -0
  71. package/dist/host/index.d.ts +4 -0
  72. package/dist/host/index.d.ts.map +1 -0
  73. package/dist/host/index.js +3 -0
  74. package/dist/host/index.js.map +1 -0
  75. package/dist/{widgets → host}/terminal-host.d.ts +20 -64
  76. package/dist/host/terminal-host.d.ts.map +1 -0
  77. package/dist/host/terminal-host.js +133 -0
  78. package/dist/host/terminal-host.js.map +1 -0
  79. package/dist/index.d.ts +13 -36
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +35 -22
  82. package/dist/index.js.map +1 -1
  83. package/dist/node/terminal-host.d.ts +85 -0
  84. package/dist/node/terminal-host.d.ts.map +1 -0
  85. package/dist/node/terminal-host.js +161 -0
  86. package/dist/node/terminal-host.js.map +1 -0
  87. package/dist/node/traceback.d.ts +28 -0
  88. package/dist/node/traceback.d.ts.map +1 -0
  89. package/dist/node/traceback.js +113 -0
  90. package/dist/node/traceback.js.map +1 -0
  91. package/dist/renderables/columns.d.ts +24 -2
  92. package/dist/renderables/columns.d.ts.map +1 -1
  93. package/dist/renderables/columns.js +91 -32
  94. package/dist/renderables/columns.js.map +1 -1
  95. package/dist/renderables/layout.d.ts +61 -5
  96. package/dist/renderables/layout.d.ts.map +1 -1
  97. package/dist/renderables/layout.js +191 -19
  98. package/dist/renderables/layout.js.map +1 -1
  99. package/dist/renderables/markdown.d.ts +1 -1
  100. package/dist/renderables/markdown.d.ts.map +1 -1
  101. package/dist/renderables/markdown.js +7 -14
  102. package/dist/renderables/markdown.js.map +1 -1
  103. package/dist/renderables/padding.d.ts +16 -3
  104. package/dist/renderables/padding.d.ts.map +1 -1
  105. package/dist/renderables/padding.js +96 -47
  106. package/dist/renderables/padding.js.map +1 -1
  107. package/dist/renderables/panel.d.ts +48 -7
  108. package/dist/renderables/panel.d.ts.map +1 -1
  109. package/dist/renderables/panel.js +175 -106
  110. package/dist/renderables/panel.js.map +1 -1
  111. package/dist/renderables/progress.d.ts +3 -3
  112. package/dist/renderables/progress.d.ts.map +1 -1
  113. package/dist/renderables/progress.js +11 -9
  114. package/dist/renderables/progress.js.map +1 -1
  115. package/dist/renderables/progressBar.d.ts +3 -3
  116. package/dist/renderables/progressBar.d.ts.map +1 -1
  117. package/dist/renderables/progressBar.js +9 -15
  118. package/dist/renderables/progressBar.js.map +1 -1
  119. package/dist/renderables/prompt.js +1 -1
  120. package/dist/renderables/prompt.js.map +1 -1
  121. package/dist/renderables/rule.d.ts +1 -1
  122. package/dist/renderables/rule.d.ts.map +1 -1
  123. package/dist/renderables/rule.js +5 -10
  124. package/dist/renderables/rule.js.map +1 -1
  125. package/dist/renderables/spinner.d.ts +2 -2
  126. package/dist/renderables/spinner.d.ts.map +1 -1
  127. package/dist/renderables/spinner.js +6 -11
  128. package/dist/renderables/spinner.js.map +1 -1
  129. package/dist/renderables/status.d.ts.map +1 -1
  130. package/dist/renderables/status.js +5 -11
  131. package/dist/renderables/status.js.map +1 -1
  132. package/dist/renderables/table.d.ts +90 -16
  133. package/dist/renderables/table.d.ts.map +1 -1
  134. package/dist/renderables/table.js +481 -223
  135. package/dist/renderables/table.js.map +1 -1
  136. package/dist/renderables/traceback.d.ts +7 -3
  137. package/dist/renderables/traceback.d.ts.map +1 -1
  138. package/dist/renderables/traceback.js +15 -18
  139. package/dist/renderables/traceback.js.map +1 -1
  140. package/dist/renderables/tree.d.ts +29 -4
  141. package/dist/renderables/tree.d.ts.map +1 -1
  142. package/dist/renderables/tree.js +86 -33
  143. package/dist/renderables/tree.js.map +1 -1
  144. package/dist/template-bindings/color-funcs.d.ts +3 -3
  145. package/dist/template-bindings/color-funcs.js +3 -3
  146. package/dist/template-bindings/helpers.d.ts.map +1 -1
  147. package/dist/template-bindings/helpers.js +19 -1
  148. package/dist/template-bindings/helpers.js.map +1 -1
  149. package/dist/template-bindings/index.d.ts +6 -7
  150. package/dist/template-bindings/index.d.ts.map +1 -1
  151. package/dist/template-bindings/index.js +6 -7
  152. package/dist/template-bindings/index.js.map +1 -1
  153. package/dist/template-bindings/palette-funcs.d.ts +17 -5
  154. package/dist/template-bindings/palette-funcs.d.ts.map +1 -1
  155. package/dist/template-bindings/palette-funcs.js +69 -6
  156. package/dist/template-bindings/palette-funcs.js.map +1 -1
  157. package/dist/template-bindings/style-funcs.d.ts +1 -1
  158. package/dist/template-bindings/style-funcs.js +1 -1
  159. package/dist/themes/ramp.d.ts +84 -0
  160. package/dist/themes/ramp.d.ts.map +1 -0
  161. package/dist/themes/ramp.js +123 -0
  162. package/dist/themes/ramp.js.map +1 -0
  163. package/dist/widgets/dropdown.d.ts +1 -1
  164. package/dist/widgets/dropdown.js +1 -1
  165. package/dist/widgets/event-router.d.ts +3 -2
  166. package/dist/widgets/event-router.d.ts.map +1 -1
  167. package/dist/widgets/focus-manager.d.ts +2 -1
  168. package/dist/widgets/focus-manager.d.ts.map +1 -1
  169. package/dist/widgets/index.d.ts +3 -6
  170. package/dist/widgets/index.d.ts.map +1 -1
  171. package/dist/widgets/index.js +4 -3
  172. package/dist/widgets/index.js.map +1 -1
  173. package/dist/widgets/screen.d.ts +1 -1
  174. package/dist/widgets/screen.d.ts.map +1 -1
  175. package/dist/widgets/text-input.d.ts +2 -3
  176. package/dist/widgets/text-input.d.ts.map +1 -1
  177. package/dist/widgets/text-input.js +4 -12
  178. package/dist/widgets/text-input.js.map +1 -1
  179. package/dist/widgets/types.d.ts +1 -1
  180. package/dist/widgets/types.d.ts.map +1 -1
  181. package/dist/widgets/types.js.map +1 -1
  182. package/dist/widgets/widget-base.d.ts +2 -1
  183. package/dist/widgets/widget-base.d.ts.map +1 -1
  184. package/package.json +38 -6
  185. package/dist/renderables/json.d.ts.map +0 -1
  186. package/dist/renderables/json.js.map +0 -1
  187. package/dist/renderables/pretty.d.ts +0 -29
  188. package/dist/renderables/pretty.d.ts.map +0 -1
  189. package/dist/renderables/pretty.js +0 -141
  190. package/dist/renderables/pretty.js.map +0 -1
  191. package/dist/themes/paletteResolver.d.ts +0 -35
  192. package/dist/themes/paletteResolver.d.ts.map +0 -1
  193. package/dist/themes/paletteResolver.js +0 -88
  194. package/dist/themes/paletteResolver.js.map +0 -1
  195. package/dist/widgets/host-stream.d.ts.map +0 -1
  196. package/dist/widgets/host-stream.js.map +0 -1
  197. package/dist/widgets/terminal-host.d.ts.map +0 -1
  198. package/dist/widgets/terminal-host.js +0 -258
  199. package/dist/widgets/terminal-host.js.map +0 -1
  200. /package/dist/{widgets → host}/host-stream.d.ts +0 -0
  201. /package/dist/{widgets → host}/host-stream.js +0 -0
package/dist/core/box.js CHANGED
@@ -1,534 +1,392 @@
1
1
  /**
2
2
  * Box-drawing character sets for borders and table grids.
3
+ *
4
+ * A style is declared as an 8x4 character grid — one line per row a table can
5
+ * draw, one column per position within that row:
6
+ *
7
+ * ┌─┬┐ top border
8
+ * │ ││ header content
9
+ * ├─┼┤ header separator
10
+ * │ ││ body content
11
+ * ├─┼┤ row separator
12
+ * ├─┼┤ footer separator
13
+ * │ ││ footer content
14
+ * └─┴┘ bottom border
15
+ *
16
+ * [LAW:one-source-of-truth] The grid is the shape the reference implementation
17
+ * (Python Rich's `box.py`) publishes these glyphs in, so a constant below can
18
+ * be diffed against it character for character. The eighteen named fields this
19
+ * replaced were a second, differently-shaped map of the same territory, and it
20
+ * had drifted: seven of the nineteen constants carried wrong glyphs, and the
21
+ * field named `mid` held the reference's line 3 while the reference's `mid_*`
22
+ * is line 4 — so reading the reference name-for-name swapped a separator for a
23
+ * content row. Named row fields are gone for that reason; a row is reached by
24
+ * what it is (`getRow`, `getContentChars`), never by a name that can be
25
+ * mismatched to a line.
3
26
  */
27
+ import { cellLen } from "./cells.js";
4
28
  import { Segment } from "./segment.js";
29
+ const GRID_ROWS = 8;
30
+ const GRID_COLUMNS = 4;
31
+ /**
32
+ * A grid a terminal without unicode support can already draw as written.
33
+ *
34
+ * [LAW:one-source-of-truth] Derived from the grid rather than declared per
35
+ * constant the way the reference's `ascii=True` is. A `Box` is wholly its grid,
36
+ * so the grid already answers this; a second, hand-written answer could
37
+ * disagree with it. It also reaches boxes no constant can speak for —
38
+ * `safeSubstitute` builds a fresh `Box` from an edited grid, and a flag carried
39
+ * on the shipped constants would say nothing about that one.
40
+ */
41
+ const ASCII_GRID = /^[\x00-\x7F]*$/;
42
+ /** Corners that a legacy Windows terminal cannot draw, and their square kin. */
43
+ const SAFE_SUBSTITUTIONS = {
44
+ "╭": "┌",
45
+ "╮": "┐",
46
+ "╰": "└",
47
+ "╯": "┘",
48
+ };
49
+ const edgeOf = (row) => ({
50
+ left: row[0],
51
+ horizontal: row[1],
52
+ cross: row[2],
53
+ right: row[3],
54
+ });
55
+ const contentOf = (row) => ({
56
+ left: row[0],
57
+ vertical: row[2],
58
+ right: row[3],
59
+ });
5
60
  // [LAW:one-type-per-behavior] Box is a single type for all border styles — instances differ by data
6
61
  export class Box {
7
- topLeft;
8
62
  top;
9
- topDivider;
10
- topRight;
11
- headLeft;
12
- headVertical;
13
- headRight;
14
- midLeft;
15
- mid;
16
- midVertical;
17
- midRight;
18
- bottomLeft;
19
63
  bottom;
20
- bottomDivider;
21
- bottomRight;
22
- left;
23
- right;
24
- vertical;
25
- constructor(chars) {
26
- this.topLeft = chars.topLeft;
27
- this.top = chars.top;
28
- this.topDivider = chars.topDivider;
29
- this.topRight = chars.topRight;
30
- this.headLeft = chars.headLeft;
31
- this.headVertical = chars.headVertical;
32
- this.headRight = chars.headRight;
33
- this.midLeft = chars.midLeft;
34
- this.mid = chars.mid;
35
- this.midVertical = chars.midVertical;
36
- this.midRight = chars.midRight;
37
- this.bottomLeft = chars.bottomLeft;
38
- this.bottom = chars.bottom;
39
- this.bottomDivider = chars.bottomDivider;
40
- this.bottomRight = chars.bottomRight;
41
- this.left = chars.left;
42
- this.right = chars.right;
43
- this.vertical = chars.vertical;
64
+ grid;
65
+ ascii;
66
+ headContent;
67
+ headSeparator;
68
+ bodyContent;
69
+ rowSeparator;
70
+ footSeparator;
71
+ footContent;
72
+ /**
73
+ * [LAW:parse-dont-validate] The one crossing between a grid string and box
74
+ * glyphs. A `Box` cannot exist without eight rows of four characters, so no
75
+ * consumer below ever re-checks the shape of the data it reads.
76
+ */
77
+ constructor(grid) {
78
+ const lines = grid.split("\n");
79
+ // A row is four characters because `getEdge` indexes the four positions,
80
+ // and four cells because that is what the terminal draws — a single astral
81
+ // glyph satisfies the first and breaks every frame the box appears in.
82
+ // [LAW:single-enforcer] `cellLen` is the cell-width authority.
83
+ const malformed = lines.length !== GRID_ROWS
84
+ || lines.some((line) => Array.from(line).length !== GRID_COLUMNS)
85
+ || lines.some((line) => cellLen(line) !== GRID_COLUMNS);
86
+ if (malformed) {
87
+ throw new Error(`A box grid is ${GRID_ROWS} lines of ${GRID_COLUMNS} single-cell `
88
+ + `characters; got ${lines.length} line(s) measuring `
89
+ + lines.map((line) => `${Array.from(line).length}/${cellLen(line)}`).join(", ")
90
+ + " characters/cells");
91
+ }
92
+ const rows = lines.map((line) => Array.from(line));
93
+ this.grid = grid;
94
+ this.ascii = ASCII_GRID.test(grid);
95
+ this.top = edgeOf(rows[0]);
96
+ this.headContent = contentOf(rows[1]);
97
+ this.headSeparator = edgeOf(rows[2]);
98
+ this.bodyContent = contentOf(rows[3]);
99
+ this.rowSeparator = edgeOf(rows[4]);
100
+ this.footSeparator = edgeOf(rows[5]);
101
+ this.footContent = contentOf(rows[6]);
102
+ this.bottom = edgeOf(rows[7]);
44
103
  }
45
104
  /**
46
105
  * Renders the top border row for given column widths.
47
106
  */
48
107
  getTop(widths, style, edge = true) {
49
- const segments = [];
50
- if (edge)
51
- segments.push(new Segment(this.topLeft, style));
52
- for (let i = 0; i < widths.length; i++) {
53
- if (i > 0)
54
- segments.push(new Segment(this.topDivider, style));
55
- segments.push(new Segment(this.top.repeat(widths[i]), style));
56
- }
57
- if (edge)
58
- segments.push(new Segment(this.topRight, style));
59
- segments.push(Segment.line());
60
- return segments;
108
+ return this.getEdge(widths, this.top, style, edge);
61
109
  }
62
110
  /**
63
- * Renders a separator row.
111
+ * Renders the separator drawn *above* a row at `level` — the head separator
112
+ * under the header, the row separator between body rows, the foot separator
113
+ * above the footer.
64
114
  */
65
115
  getRow(widths, level, style, edge = true) {
66
- const [left, horizontal, cross, right] = this.getRowChars(level);
67
- const segments = [];
68
- if (edge)
69
- segments.push(new Segment(left, style));
70
- for (let i = 0; i < widths.length; i++) {
71
- if (i > 0)
72
- segments.push(new Segment(cross, style));
73
- segments.push(new Segment(horizontal.repeat(widths[i]), style));
116
+ return this.getEdge(widths, this.getRowChars(level), style, edge);
117
+ }
118
+ /**
119
+ * The verticals that frame a content row at `level` — the counterpart to
120
+ * `getRow`, which draws the separator between two such rows.
121
+ */
122
+ getContentChars(level) {
123
+ switch (level) {
124
+ case "head":
125
+ return this.headContent;
126
+ // `mid` is a spacer between body rows, so it is framed as one.
127
+ case "row":
128
+ case "mid":
129
+ return this.bodyContent;
130
+ case "foot":
131
+ return this.footContent;
74
132
  }
75
- if (edge)
76
- segments.push(new Segment(right, style));
77
- segments.push(Segment.line());
78
- return segments;
79
133
  }
80
134
  /**
81
135
  * Renders the bottom border row.
82
136
  */
83
137
  getBottom(widths, style, edge = true) {
84
- const segments = [];
85
- if (edge)
86
- segments.push(new Segment(this.bottomLeft, style));
87
- for (let i = 0; i < widths.length; i++) {
88
- if (i > 0)
89
- segments.push(new Segment(this.bottomDivider, style));
90
- segments.push(new Segment(this.bottom.repeat(widths[i]), style));
91
- }
92
- if (edge)
93
- segments.push(new Segment(this.bottomRight, style));
94
- segments.push(Segment.line());
95
- return segments;
138
+ return this.getEdge(widths, this.bottom, style, edge);
96
139
  }
97
140
  /**
98
- * Returns a new Box with characters substituted for ASCII or safe alternatives.
99
- * asciiOnly: all characters become ASCII (+, -, |)
100
- * safe: problematic characters (e.g. rounded corners) replaced with square equivalents
141
+ * The box to draw with when the platform cannot render this one as written.
142
+ *
143
+ * `asciiOnly` gives up a box that spends non-ASCII glyphs for `ASCII`, and
144
+ * leaves the four already-ASCII styles as they are — a caller that chose
145
+ * MARKDOWN or ASCII_DOUBLE_HEAD asked for that frame and it is already
146
+ * drawable, so answering with `ASCII` would trade a frame the terminal
147
+ * supports for a different one it equally supports. `safe` squares off the
148
+ * rounded corners a legacy Windows terminal draws as blanks.
101
149
  */
102
150
  substitute(options = {}) {
103
- if (options.asciiOnly)
151
+ if (options.asciiOnly && !this.ascii)
104
152
  return ASCII;
105
153
  if (options.safe)
106
154
  return this.safeSubstitute();
107
155
  return this;
108
156
  }
109
157
  safeSubstitute() {
110
- // Replace rounded corners and other characters that may not render
111
- // on Windows legacy terminal with safe square equivalents
112
- const replacements = {
113
- "╭": "┌",
114
- "╮": "┐",
115
- "╰": "└",
116
- "╯": "┘",
117
- };
118
- const replace = (ch) => replacements[ch] ?? ch;
119
- return new Box({
120
- topLeft: replace(this.topLeft),
121
- top: replace(this.top),
122
- topDivider: replace(this.topDivider),
123
- topRight: replace(this.topRight),
124
- headLeft: replace(this.headLeft),
125
- headVertical: replace(this.headVertical),
126
- headRight: replace(this.headRight),
127
- midLeft: replace(this.midLeft),
128
- mid: replace(this.mid),
129
- midVertical: replace(this.midVertical),
130
- midRight: replace(this.midRight),
131
- bottomLeft: replace(this.bottomLeft),
132
- bottom: replace(this.bottom),
133
- bottomDivider: replace(this.bottomDivider),
134
- bottomRight: replace(this.bottomRight),
135
- left: replace(this.left),
136
- right: replace(this.right),
137
- vertical: replace(this.vertical),
138
- });
158
+ return new Box(Array.from(this.grid, (char) => SAFE_SUBSTITUTIONS[char] ?? char).join(""));
159
+ }
160
+ /**
161
+ * The nearest box that spends no special glyphs on a header — what a table
162
+ * with `showHeader: false` draws with. A box whose head row already matches
163
+ * its body is its own answer, so this is the identity for fourteen of the
164
+ * nineteen shipped styles.
165
+ *
166
+ * It stands beside `substitute` rather than joining it because the two ask
167
+ * unrelated questions: `substitute` asks what the *platform* can draw, this
168
+ * asks what the *table* contains. Nothing correlates them, so a caller that
169
+ * wants both wants both, and a shared options bag would only multiply the
170
+ * combinations either one has to reason about. [LAW:no-mode-explosion]
171
+ *
172
+ * [LAW:types-are-the-program] The relation is keyed on the grid, not on
173
+ * object identity as the reference's dict is. A `Box` is wholly determined by
174
+ * its grid — that is what the constructor takes and all eight rows derive
175
+ * from — so two boxes with one grid must answer this alike. Identity keying
176
+ * would say otherwise the moment a box arrived by any route but the shipped
177
+ * constant, and `safeSubstitute` above builds exactly such a box: a fresh
178
+ * instance carrying an unchanged grid.
179
+ */
180
+ plainHeaded() {
181
+ // `private` is scoped to the class, so the pairs below can be read by grid
182
+ // without exposing one.
183
+ return PLAIN_HEADED_SUBSTITUTIONS.find(([headed]) => headed.grid === this.grid)?.[1]
184
+ ?? this;
185
+ }
186
+ /**
187
+ * [LAW:dataflow-not-control-flow] Every full-width rule the box can draw is
188
+ * this one loop; which rule it is arrives as four characters, not a branch.
189
+ */
190
+ getEdge(widths, chars, style, edge) {
191
+ const segments = [];
192
+ if (edge)
193
+ segments.push(new Segment(chars.left, style));
194
+ for (let i = 0; i < widths.length; i++) {
195
+ if (i > 0)
196
+ segments.push(new Segment(chars.cross, style));
197
+ segments.push(new Segment(chars.horizontal.repeat(widths[i]), style));
198
+ }
199
+ if (edge)
200
+ segments.push(new Segment(chars.right, style));
201
+ segments.push(Segment.line());
202
+ return segments;
139
203
  }
140
204
  getRowChars(level) {
141
205
  switch (level) {
142
206
  case "head":
143
- return [this.headLeft, this.mid, this.headVertical, this.headRight];
207
+ return this.headSeparator;
144
208
  case "row":
145
- return [this.midLeft, this.mid, this.midVertical, this.midRight];
146
- case "mid":
147
- return [this.midLeft, this.mid, this.midVertical, this.midRight];
209
+ return this.rowSeparator;
148
210
  case "foot":
149
- return [this.midLeft, this.mid, this.midVertical, this.midRight];
211
+ return this.footSeparator;
212
+ // The reference's spacer row, not a rule: blank fill between the body
213
+ // row's verticals. Nothing draws it yet — rich-table-jx1 has the details.
214
+ case "mid":
215
+ return {
216
+ left: this.bodyContent.left,
217
+ horizontal: " ",
218
+ cross: this.bodyContent.vertical,
219
+ right: this.bodyContent.right,
220
+ };
150
221
  }
151
222
  }
152
223
  }
153
224
  // --- Pre-built box styles ---
154
- export const ASCII = new Box({
155
- topLeft: "+",
156
- top: "-",
157
- topDivider: "+",
158
- topRight: "+",
159
- headLeft: "|",
160
- headVertical: "|",
161
- headRight: "|",
162
- midLeft: "|",
163
- mid: "-",
164
- midVertical: "+",
165
- midRight: "|",
166
- bottomLeft: "+",
167
- bottom: "-",
168
- bottomDivider: "+",
169
- bottomRight: "+",
170
- left: "|",
171
- right: "|",
172
- vertical: "|",
173
- });
174
- export const ASCII2 = new Box({
175
- topLeft: "+",
176
- top: "-",
177
- topDivider: "+",
178
- topRight: "+",
179
- headLeft: "|",
180
- headVertical: "|",
181
- headRight: "|",
182
- midLeft: "+",
183
- mid: "-",
184
- midVertical: "+",
185
- midRight: "+",
186
- bottomLeft: "+",
187
- bottom: "-",
188
- bottomDivider: "+",
189
- bottomRight: "+",
190
- left: "|",
191
- right: "|",
192
- vertical: "|",
193
- });
194
- export const ASCII_DOUBLE_HEAD = new Box({
195
- topLeft: "+",
196
- top: "-",
197
- topDivider: "+",
198
- topRight: "+",
199
- headLeft: "|",
200
- headVertical: "|",
201
- headRight: "|",
202
- midLeft: "+",
203
- mid: "=",
204
- midVertical: "+",
205
- midRight: "+",
206
- bottomLeft: "+",
207
- bottom: "-",
208
- bottomDivider: "+",
209
- bottomRight: "+",
210
- left: "|",
211
- right: "|",
212
- vertical: "|",
213
- });
214
- export const SQUARE = new Box({
215
- topLeft: "┌",
216
- top: "─",
217
- topDivider: "┬",
218
- topRight: "┐",
219
- headLeft: "│",
220
- headVertical: "│",
221
- headRight: "│",
222
- midLeft: "├",
223
- mid: "─",
224
- midVertical: "┼",
225
- midRight: "┤",
226
- bottomLeft: "└",
227
- bottom: "─",
228
- bottomDivider: "┴",
229
- bottomRight: "┘",
230
- left: "│",
231
- right: "│",
232
- vertical: "│",
233
- });
234
- export const SQUARE_DOUBLE_HEAD = new Box({
235
- topLeft: "┌",
236
- top: "─",
237
- topDivider: "┬",
238
- topRight: "┐",
239
- headLeft: "│",
240
- headVertical: "│",
241
- headRight: "│",
242
- midLeft: "╞",
243
- mid: "═",
244
- midVertical: "╪",
245
- midRight: "╡",
246
- bottomLeft: "└",
247
- bottom: "─",
248
- bottomDivider: "┴",
249
- bottomRight: "┘",
250
- left: "│",
251
- right: "│",
252
- vertical: "│",
253
- });
254
- export const MINIMAL = new Box({
255
- topLeft: " ",
256
- top: " ",
257
- topDivider: " ",
258
- topRight: " ",
259
- headLeft: " ",
260
- headVertical: " ",
261
- headRight: " ",
262
- midLeft: " ",
263
- mid: "─",
264
- midVertical: "─",
265
- midRight: " ",
266
- bottomLeft: " ",
267
- bottom: " ",
268
- bottomDivider: " ",
269
- bottomRight: " ",
270
- left: " ",
271
- right: " ",
272
- vertical: " ",
273
- });
274
- export const MINIMAL_HEAVY_HEAD = new Box({
275
- topLeft: " ",
276
- top: " ",
277
- topDivider: " ",
278
- topRight: " ",
279
- headLeft: " ",
280
- headVertical: " ",
281
- headRight: " ",
282
- midLeft: " ",
283
- mid: "━",
284
- midVertical: "━",
285
- midRight: " ",
286
- bottomLeft: " ",
287
- bottom: " ",
288
- bottomDivider: " ",
289
- bottomRight: " ",
290
- left: " ",
291
- right: " ",
292
- vertical: " ",
293
- });
294
- export const MINIMAL_DOUBLE_HEAD = new Box({
295
- topLeft: " ",
296
- top: " ",
297
- topDivider: " ",
298
- topRight: " ",
299
- headLeft: " ",
300
- headVertical: " ",
301
- headRight: " ",
302
- midLeft: " ",
303
- mid: "═",
304
- midVertical: "═",
305
- midRight: " ",
306
- bottomLeft: " ",
307
- bottom: " ",
308
- bottomDivider: " ",
309
- bottomRight: " ",
310
- left: " ",
311
- right: " ",
312
- vertical: " ",
313
- });
314
- export const SIMPLE = new Box({
315
- topLeft: " ",
316
- top: " ",
317
- topDivider: " ",
318
- topRight: " ",
319
- headLeft: " ",
320
- headVertical: " ",
321
- headRight: " ",
322
- midLeft: " ",
323
- mid: "─",
324
- midVertical: " ",
325
- midRight: " ",
326
- bottomLeft: " ",
327
- bottom: "─",
328
- bottomDivider: " ",
329
- bottomRight: " ",
330
- left: " ",
331
- right: " ",
332
- vertical: " ",
333
- });
334
- export const SIMPLE_HEAD = new Box({
335
- topLeft: " ",
336
- top: " ",
337
- topDivider: " ",
338
- topRight: " ",
339
- headLeft: " ",
340
- headVertical: " ",
341
- headRight: " ",
342
- midLeft: " ",
343
- mid: "─",
344
- midVertical: " ",
345
- midRight: " ",
346
- bottomLeft: " ",
347
- bottom: " ",
348
- bottomDivider: " ",
349
- bottomRight: " ",
350
- left: " ",
351
- right: " ",
352
- vertical: " ",
353
- });
354
- export const SIMPLE_HEAVY = new Box({
355
- topLeft: " ",
356
- top: " ",
357
- topDivider: " ",
358
- topRight: " ",
359
- headLeft: " ",
360
- headVertical: " ",
361
- headRight: " ",
362
- midLeft: " ",
363
- mid: "━",
364
- midVertical: " ",
365
- midRight: " ",
366
- bottomLeft: " ",
367
- bottom: "━",
368
- bottomDivider: " ",
369
- bottomRight: " ",
370
- left: " ",
371
- right: " ",
372
- vertical: " ",
373
- });
374
- export const HORIZONTALS = new Box({
375
- topLeft: " ",
376
- top: "─",
377
- topDivider: "─",
378
- topRight: " ",
379
- headLeft: " ",
380
- headVertical: " ",
381
- headRight: " ",
382
- midLeft: " ",
383
- mid: "─",
384
- midVertical: "─",
385
- midRight: " ",
386
- bottomLeft: " ",
387
- bottom: "─",
388
- bottomDivider: "─",
389
- bottomRight: " ",
390
- left: " ",
391
- right: " ",
392
- vertical: " ",
393
- });
394
- export const ROUNDED = new Box({
395
- topLeft: "╭",
396
- top: "─",
397
- topDivider: "┬",
398
- topRight: "╮",
399
- headLeft: "│",
400
- headVertical: "│",
401
- headRight: "│",
402
- midLeft: "├",
403
- mid: "─",
404
- midVertical: "┼",
405
- midRight: "┤",
406
- bottomLeft: "╰",
407
- bottom: "─",
408
- bottomDivider: "┴",
409
- bottomRight: "╯",
410
- left: "│",
411
- right: "│",
412
- vertical: "│",
413
- });
414
- export const HEAVY = new Box({
415
- topLeft: "┏",
416
- top: "━",
417
- topDivider: "┳",
418
- topRight: "┓",
419
- headLeft: "┃",
420
- headVertical: "┃",
421
- headRight: "┃",
422
- midLeft: "┣",
423
- mid: "━",
424
- midVertical: "╋",
425
- midRight: "┫",
426
- bottomLeft: "┗",
427
- bottom: "━",
428
- bottomDivider: "┻",
429
- bottomRight: "┛",
430
- left: "┃",
431
- right: "┃",
432
- vertical: "┃",
433
- });
434
- export const HEAVY_EDGE = new Box({
435
- topLeft: "┏",
436
- top: "━",
437
- topDivider: "┯",
438
- topRight: "┓",
439
- headLeft: "┃",
440
- headVertical: "│",
441
- headRight: "┃",
442
- midLeft: "┠",
443
- mid: "─",
444
- midVertical: "┼",
445
- midRight: "┨",
446
- bottomLeft: "┗",
447
- bottom: "━",
448
- bottomDivider: "┷",
449
- bottomRight: "┛",
450
- left: "┃",
451
- right: "┃",
452
- vertical: "│",
453
- });
454
- export const HEAVY_HEAD = new Box({
455
- topLeft: "┏",
456
- top: "━",
457
- topDivider: "┳",
458
- topRight: "┓",
459
- headLeft: "┃",
460
- headVertical: "┃",
461
- headRight: "┃",
462
- midLeft: "┡",
463
- mid: "━",
464
- midVertical: "╇",
465
- midRight: "┩",
466
- bottomLeft: "└",
467
- bottom: "─",
468
- bottomDivider: "┴",
469
- bottomRight: "┘",
470
- left: "│",
471
- right: "│",
472
- vertical: "│",
473
- });
474
- export const DOUBLE = new Box({
475
- topLeft: "╔",
476
- top: "═",
477
- topDivider: "╦",
478
- topRight: "╗",
479
- headLeft: "║",
480
- headVertical: "║",
481
- headRight: "║",
482
- midLeft: "╠",
483
- mid: "═",
484
- midVertical: "╬",
485
- midRight: "╣",
486
- bottomLeft: "╚",
487
- bottom: "═",
488
- bottomDivider: "╩",
489
- bottomRight: "╝",
490
- left: "║",
491
- right: "║",
492
- vertical: "║",
493
- });
494
- export const DOUBLE_EDGE = new Box({
495
- topLeft: "╔",
496
- top: "═",
497
- topDivider: "╤",
498
- topRight: "╗",
499
- headLeft: "║",
500
- headVertical: "│",
501
- headRight: "║",
502
- midLeft: "╟",
503
- mid: "─",
504
- midVertical: "┼",
505
- midRight: "╢",
506
- bottomLeft: "╚",
507
- bottom: "═",
508
- bottomDivider: "╧",
509
- bottomRight: "╝",
510
- left: "║",
511
- right: "║",
512
- vertical: "│",
513
- });
514
- export const MARKDOWN = new Box({
515
- topLeft: " ",
516
- top: " ",
517
- topDivider: " ",
518
- topRight: " ",
519
- headLeft: "|",
520
- headVertical: "|",
521
- headRight: "|",
522
- midLeft: "|",
523
- mid: "-",
524
- midVertical: "|",
525
- midRight: "|",
526
- bottomLeft: " ",
527
- bottom: " ",
528
- bottomDivider: " ",
529
- bottomRight: " ",
530
- left: "|",
531
- right: "|",
532
- vertical: "|",
533
- });
225
+ // Transcribed from Python Rich's `rich/box.py` and verified grid-for-grid
226
+ // against it; see this module's header for the shape and why it is this shape.
227
+ export const ASCII = new Box("+--+\n" +
228
+ "| ||\n" +
229
+ "|-+|\n" +
230
+ "| ||\n" +
231
+ "|-+|\n" +
232
+ "|-+|\n" +
233
+ "| ||\n" +
234
+ "+--+");
235
+ export const ASCII2 = new Box("+-++\n" +
236
+ "| ||\n" +
237
+ "+-++\n" +
238
+ "| ||\n" +
239
+ "+-++\n" +
240
+ "+-++\n" +
241
+ "| ||\n" +
242
+ "+-++");
243
+ export const ASCII_DOUBLE_HEAD = new Box("+-++\n" +
244
+ "| ||\n" +
245
+ "+=++\n" +
246
+ "| ||\n" +
247
+ "+-++\n" +
248
+ "+-++\n" +
249
+ "| ||\n" +
250
+ "+-++");
251
+ export const SQUARE = new Box("┌─┬┐\n" +
252
+ "│ ││\n" +
253
+ "├─┼┤\n" +
254
+ "│ ││\n" +
255
+ "├─┼┤\n" +
256
+ "├─┼┤\n" +
257
+ "│ ││\n" +
258
+ "└─┴┘");
259
+ export const SQUARE_DOUBLE_HEAD = new Box("┌─┬┐\n" +
260
+ "│ ││\n" +
261
+ "╞═╪╡\n" +
262
+ "│ ││\n" +
263
+ "├─┼┤\n" +
264
+ "├─┼┤\n" +
265
+ "│ ││\n" +
266
+ "└─┴┘");
267
+ export const MINIMAL = new Box(" ╷ \n" +
268
+ " │ \n" +
269
+ "╶─┼╴\n" +
270
+ " │ \n" +
271
+ "╶─┼╴\n" +
272
+ "╶─┼╴\n" +
273
+ " │ \n" +
274
+ " ╵ ");
275
+ export const MINIMAL_HEAVY_HEAD = new Box(" ╷ \n" +
276
+ " │ \n" +
277
+ "╺━┿╸\n" +
278
+ " │ \n" +
279
+ "╶─┼╴\n" +
280
+ "╶─┼╴\n" +
281
+ " │ \n" +
282
+ " ╵ ");
283
+ export const MINIMAL_DOUBLE_HEAD = new Box(" ╷ \n" +
284
+ " │ \n" +
285
+ " ═╪ \n" +
286
+ " │ \n" +
287
+ " ─┼ \n" +
288
+ " ─┼ \n" +
289
+ " │ \n" +
290
+ " ╵ ");
291
+ export const SIMPLE = new Box(" \n" +
292
+ " \n" +
293
+ " ── \n" +
294
+ " \n" +
295
+ " \n" +
296
+ " ── \n" +
297
+ " \n" +
298
+ " ");
299
+ export const SIMPLE_HEAD = new Box(" \n" +
300
+ " \n" +
301
+ " ── \n" +
302
+ " \n" +
303
+ " \n" +
304
+ " \n" +
305
+ " \n" +
306
+ " ");
307
+ export const SIMPLE_HEAVY = new Box(" \n" +
308
+ " \n" +
309
+ " ━━ \n" +
310
+ " \n" +
311
+ " \n" +
312
+ " ━━ \n" +
313
+ " \n" +
314
+ " ");
315
+ export const HORIZONTALS = new Box(" ── \n" +
316
+ " \n" +
317
+ " ── \n" +
318
+ " \n" +
319
+ " ── \n" +
320
+ " ── \n" +
321
+ " \n" +
322
+ " ── ");
323
+ export const ROUNDED = new Box("╭─┬╮\n" +
324
+ "│ ││\n" +
325
+ "├─┼┤\n" +
326
+ "│ ││\n" +
327
+ "├─┼┤\n" +
328
+ "├─┼┤\n" +
329
+ "│ ││\n" +
330
+ "╰─┴╯");
331
+ export const HEAVY = new Box("┏━┳┓\n" +
332
+ "┃ ┃┃\n" +
333
+ "┣━╋┫\n" +
334
+ "┃ ┃┃\n" +
335
+ "┣━╋┫\n" +
336
+ "┣━╋┫\n" +
337
+ "┃ ┃┃\n" +
338
+ "┗━┻┛");
339
+ export const HEAVY_EDGE = new Box("┏━┯┓\n" +
340
+ "┃ │┃\n" +
341
+ "┠─┼┨\n" +
342
+ "┃ │┃\n" +
343
+ "┠─┼┨\n" +
344
+ "┠─┼┨\n" +
345
+ "┃ │┃\n" +
346
+ "┗━┷┛");
347
+ export const HEAVY_HEAD = new Box("┏━┳┓\n" +
348
+ "┃ ┃┃\n" +
349
+ "┡━╇┩\n" +
350
+ "│ ││\n" +
351
+ "├─┼┤\n" +
352
+ "├─┼┤\n" +
353
+ "│ ││\n" +
354
+ "└─┴┘");
355
+ export const DOUBLE = new Box("╔═╦╗\n" +
356
+ "║ ║║\n" +
357
+ "╠═╬╣\n" +
358
+ "║ ║║\n" +
359
+ "╠═╬╣\n" +
360
+ "╠═╬╣\n" +
361
+ "║ ║║\n" +
362
+ "╚═╩╝");
363
+ export const DOUBLE_EDGE = new Box("╔═╤╗\n" +
364
+ "║ │║\n" +
365
+ "╟─┼╢\n" +
366
+ "║ │║\n" +
367
+ "╟─┼╢\n" +
368
+ "╟─┼╢\n" +
369
+ "║ │║\n" +
370
+ "╚═╧╝");
371
+ export const MARKDOWN = new Box(" \n" +
372
+ "| ||\n" +
373
+ "|-||\n" +
374
+ "| ||\n" +
375
+ "|-||\n" +
376
+ "|-||\n" +
377
+ "| ||\n" +
378
+ " ");
379
+ /**
380
+ * Boxes whose header glyphs differ from their body's, paired with the kin that
381
+ * draws the same frame without them. Transcribed from the reference's
382
+ * `PLAIN_HEADED_SUBSTITUTIONS`; the fourteen styles absent here already draw a
383
+ * plain head, and `plainHeaded` returns them unchanged.
384
+ */
385
+ const PLAIN_HEADED_SUBSTITUTIONS = [
386
+ [HEAVY_HEAD, SQUARE],
387
+ [SQUARE_DOUBLE_HEAD, SQUARE],
388
+ [MINIMAL_HEAVY_HEAD, MINIMAL],
389
+ [MINIMAL_DOUBLE_HEAD, MINIMAL],
390
+ [ASCII_DOUBLE_HEAD, ASCII2],
391
+ ];
534
392
  //# sourceMappingURL=box.js.map