@sagmans/dsh-tui 0.6.0 → 0.7.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 (250) hide show
  1. package/.agents/skills/dsh-tui-dogfood/SKILL.md +83 -0
  2. package/.agents/skills/dsh-tui-dogfood/references/home-state.md +78 -0
  3. package/.agents/skills/dsh-tui-dogfood/scripts/clone-links.mjs +133 -0
  4. package/.agents/skills/dsh-tui-dogfood/scripts/run-plugin-from-worktree.sh +417 -0
  5. package/.agents/skills/dsh-tui-update-models/SKILL.md +121 -0
  6. package/.agents/skills/dsh-tui-update-models/references/model-wiring.md +162 -0
  7. package/.agents/skills/dsh-tui-update-models/scripts/dump-model-catalog.mjs +178 -0
  8. package/README.md +99 -5
  9. package/lib/agent/present.d.ts.map +1 -1
  10. package/lib/agent/present.js +2 -1
  11. package/lib/agent/present.js.map +1 -1
  12. package/lib/cards/composition.d.ts +68 -0
  13. package/lib/cards/composition.d.ts.map +1 -0
  14. package/lib/cards/composition.js +117 -0
  15. package/lib/cards/composition.js.map +1 -0
  16. package/lib/cards/presenter.d.ts +23 -0
  17. package/lib/cards/presenter.d.ts.map +1 -0
  18. package/lib/cards/presenter.js +394 -0
  19. package/lib/cards/presenter.js.map +1 -0
  20. package/lib/cards/preview.d.ts +42 -0
  21. package/lib/cards/preview.d.ts.map +1 -0
  22. package/lib/cards/preview.js +51 -0
  23. package/lib/cards/preview.js.map +1 -0
  24. package/lib/cards.d.ts +12 -120
  25. package/lib/cards.d.ts.map +1 -1
  26. package/lib/cards.js +4 -556
  27. package/lib/cards.js.map +1 -1
  28. package/lib/compat/section.d.ts +29 -0
  29. package/lib/compat/section.d.ts.map +1 -0
  30. package/lib/compat/section.js +82 -0
  31. package/lib/compat/section.js.map +1 -0
  32. package/lib/config.d.ts +27 -2
  33. package/lib/config.d.ts.map +1 -1
  34. package/lib/config.js +61 -1
  35. package/lib/config.js.map +1 -1
  36. package/lib/contracts.d.ts +28 -0
  37. package/lib/contracts.d.ts.map +1 -1
  38. package/lib/fold-cursor.d.ts +8 -0
  39. package/lib/fold-cursor.d.ts.map +1 -1
  40. package/lib/fold-cursor.js +18 -0
  41. package/lib/fold-cursor.js.map +1 -1
  42. package/lib/gates/question-card.d.ts +77 -0
  43. package/lib/gates/question-card.d.ts.map +1 -0
  44. package/lib/gates/question-card.js +113 -0
  45. package/lib/gates/question-card.js.map +1 -0
  46. package/lib/gates/questions.d.ts +127 -0
  47. package/lib/gates/questions.d.ts.map +1 -0
  48. package/lib/gates/questions.js +418 -0
  49. package/lib/gates/questions.js.map +1 -0
  50. package/lib/gates.d.ts +1 -113
  51. package/lib/gates.d.ts.map +1 -1
  52. package/lib/gates.js +1 -484
  53. package/lib/gates.js.map +1 -1
  54. package/lib/index.d.ts +1 -0
  55. package/lib/index.d.ts.map +1 -1
  56. package/lib/index.js +343 -2602
  57. package/lib/index.js.map +1 -1
  58. package/lib/input/action-catalog.d.ts +74 -0
  59. package/lib/input/action-catalog.d.ts.map +1 -0
  60. package/lib/input/action-catalog.js +137 -0
  61. package/lib/input/action-catalog.js.map +1 -0
  62. package/lib/input/actions.d.ts +5 -81
  63. package/lib/input/actions.d.ts.map +1 -1
  64. package/lib/input/actions.js +4 -625
  65. package/lib/input/actions.js.map +1 -1
  66. package/lib/input/completion.d.ts +1 -1
  67. package/lib/input/completion.d.ts.map +1 -1
  68. package/lib/input/completion.js +2 -1
  69. package/lib/input/completion.js.map +1 -1
  70. package/lib/input/file-index.d.ts +40 -0
  71. package/lib/input/file-index.d.ts.map +1 -0
  72. package/lib/input/file-index.js +141 -0
  73. package/lib/input/file-index.js.map +1 -0
  74. package/lib/input/file-search.d.ts +1 -38
  75. package/lib/input/file-search.d.ts.map +1 -1
  76. package/lib/input/file-search.js +1 -487
  77. package/lib/input/file-search.js.map +1 -1
  78. package/lib/input/key-press.d.ts +57 -0
  79. package/lib/input/key-press.d.ts.map +1 -0
  80. package/lib/input/key-press.js +218 -0
  81. package/lib/input/key-press.js.map +1 -0
  82. package/lib/input/keymap-conflicts.d.ts +59 -0
  83. package/lib/input/keymap-conflicts.d.ts.map +1 -0
  84. package/lib/input/keymap-conflicts.js +292 -0
  85. package/lib/input/keymap-conflicts.js.map +1 -0
  86. package/lib/input/keymap-settings.js +1 -1
  87. package/lib/input/keymap-settings.js.map +1 -1
  88. package/lib/input/keymap.d.ts.map +1 -1
  89. package/lib/input/keymap.js +3 -1
  90. package/lib/input/keymap.js.map +1 -1
  91. package/lib/input/workspace-files.d.ts +10 -0
  92. package/lib/input/workspace-files.d.ts.map +1 -0
  93. package/lib/input/workspace-files.js +359 -0
  94. package/lib/input/workspace-files.js.map +1 -0
  95. package/lib/install-skills.d.ts +20 -0
  96. package/lib/install-skills.d.ts.map +1 -0
  97. package/lib/install-skills.js +198 -0
  98. package/lib/install-skills.js.map +1 -0
  99. package/lib/keys-command.d.ts +2 -1
  100. package/lib/keys-command.d.ts.map +1 -1
  101. package/lib/keys-command.js +2 -1
  102. package/lib/keys-command.js.map +1 -1
  103. package/lib/model-list.d.ts +37 -0
  104. package/lib/model-list.d.ts.map +1 -0
  105. package/lib/model-list.js +60 -0
  106. package/lib/model-list.js.map +1 -0
  107. package/lib/startup.d.ts +8 -0
  108. package/lib/startup.d.ts.map +1 -1
  109. package/lib/startup.js +120 -24
  110. package/lib/startup.js.map +1 -1
  111. package/lib/subagents.d.ts +7 -3
  112. package/lib/subagents.d.ts.map +1 -1
  113. package/lib/subagents.js +28 -4
  114. package/lib/subagents.js.map +1 -1
  115. package/lib/surface/appearance-preferences.d.ts +26 -0
  116. package/lib/surface/appearance-preferences.d.ts.map +1 -0
  117. package/lib/surface/appearance-preferences.js +139 -0
  118. package/lib/surface/appearance-preferences.js.map +1 -0
  119. package/lib/surface/appearance.d.ts +87 -0
  120. package/lib/surface/appearance.d.ts.map +1 -0
  121. package/lib/surface/appearance.js +353 -0
  122. package/lib/surface/appearance.js.map +1 -0
  123. package/lib/surface/background-work.d.ts +49 -0
  124. package/lib/surface/background-work.d.ts.map +1 -0
  125. package/lib/surface/background-work.js +146 -0
  126. package/lib/surface/background-work.js.map +1 -0
  127. package/lib/surface/commands.d.ts +80 -0
  128. package/lib/surface/commands.d.ts.map +1 -0
  129. package/lib/surface/commands.js +364 -0
  130. package/lib/surface/commands.js.map +1 -0
  131. package/lib/surface/modal-input.d.ts +58 -0
  132. package/lib/surface/modal-input.d.ts.map +1 -0
  133. package/lib/surface/modal-input.js +237 -0
  134. package/lib/surface/modal-input.js.map +1 -0
  135. package/lib/surface/model-choice.d.ts +54 -0
  136. package/lib/surface/model-choice.d.ts.map +1 -0
  137. package/lib/surface/model-choice.js +325 -0
  138. package/lib/surface/model-choice.js.map +1 -0
  139. package/lib/surface/preset-choice.d.ts +78 -0
  140. package/lib/surface/preset-choice.d.ts.map +1 -0
  141. package/lib/surface/preset-choice.js +163 -0
  142. package/lib/surface/preset-choice.js.map +1 -0
  143. package/lib/surface/prompt-input.d.ts +97 -0
  144. package/lib/surface/prompt-input.d.ts.map +1 -0
  145. package/lib/surface/prompt-input.js +215 -0
  146. package/lib/surface/prompt-input.js.map +1 -0
  147. package/lib/surface/prompt-memory.d.ts +76 -0
  148. package/lib/surface/prompt-memory.d.ts.map +1 -0
  149. package/lib/surface/prompt-memory.js +167 -0
  150. package/lib/surface/prompt-memory.js.map +1 -0
  151. package/lib/surface/session-lifecycle.d.ts +120 -0
  152. package/lib/surface/session-lifecycle.d.ts.map +1 -0
  153. package/lib/surface/session-lifecycle.js +321 -0
  154. package/lib/surface/session-lifecycle.js.map +1 -0
  155. package/lib/surface/session-picker.d.ts +39 -0
  156. package/lib/surface/session-picker.d.ts.map +1 -0
  157. package/lib/surface/session-picker.js +107 -0
  158. package/lib/surface/session-picker.js.map +1 -0
  159. package/lib/surface/session-view.d.ts +86 -0
  160. package/lib/surface/session-view.d.ts.map +1 -0
  161. package/lib/surface/session-view.js +215 -0
  162. package/lib/surface/session-view.js.map +1 -0
  163. package/lib/surface/staged-turns.d.ts +81 -0
  164. package/lib/surface/staged-turns.d.ts.map +1 -0
  165. package/lib/surface/staged-turns.js +206 -0
  166. package/lib/surface/staged-turns.js.map +1 -0
  167. package/lib/surface/terminal-lifecycle.d.ts +76 -0
  168. package/lib/surface/terminal-lifecycle.d.ts.map +1 -0
  169. package/lib/surface/terminal-lifecycle.js +222 -0
  170. package/lib/surface/terminal-lifecycle.js.map +1 -0
  171. package/lib/terminal-text/scan.d.ts +44 -0
  172. package/lib/terminal-text/scan.d.ts.map +1 -0
  173. package/lib/terminal-text/scan.js +195 -0
  174. package/lib/terminal-text/scan.js.map +1 -0
  175. package/lib/terminal-text/sgr.d.ts +32 -0
  176. package/lib/terminal-text/sgr.d.ts.map +1 -0
  177. package/lib/terminal-text/sgr.js +203 -0
  178. package/lib/terminal-text/sgr.js.map +1 -0
  179. package/lib/terminal-text.d.ts +1 -1
  180. package/lib/terminal-text.d.ts.map +1 -1
  181. package/lib/terminal-text.js +2 -379
  182. package/lib/terminal-text.js.map +1 -1
  183. package/lib/theme-command.js +2 -1
  184. package/lib/theme-command.js.map +1 -1
  185. package/lib/theme-defaults.d.ts +64 -0
  186. package/lib/theme-defaults.d.ts.map +1 -0
  187. package/lib/theme-defaults.js +248 -0
  188. package/lib/theme-defaults.js.map +1 -0
  189. package/lib/theme-resolver.d.ts +36 -0
  190. package/lib/theme-resolver.d.ts.map +1 -0
  191. package/lib/theme-resolver.js +112 -0
  192. package/lib/theme-resolver.js.map +1 -0
  193. package/lib/theme-schema.d.ts.map +1 -1
  194. package/lib/theme-schema.js +3 -2
  195. package/lib/theme-schema.js.map +1 -1
  196. package/lib/theme-settings.d.ts +5 -7
  197. package/lib/theme-settings.d.ts.map +1 -1
  198. package/lib/theme-settings.js +27 -19
  199. package/lib/theme-settings.js.map +1 -1
  200. package/lib/theme-tokens.d.ts +0 -89
  201. package/lib/theme-tokens.d.ts.map +1 -1
  202. package/lib/theme-tokens.js +0 -356
  203. package/lib/theme-tokens.js.map +1 -1
  204. package/lib/theme.d.ts +1 -1
  205. package/lib/theme.d.ts.map +1 -1
  206. package/lib/theme.js +2 -1
  207. package/lib/theme.js.map +1 -1
  208. package/lib/tool-display.d.ts.map +1 -1
  209. package/lib/tool-display.js +2 -1
  210. package/lib/tool-display.js.map +1 -1
  211. package/lib/transcript/message-content.d.ts +21 -0
  212. package/lib/transcript/message-content.d.ts.map +1 -0
  213. package/lib/transcript/message-content.js +61 -0
  214. package/lib/transcript/message-content.js.map +1 -0
  215. package/lib/transcript/tool-calls.d.ts +106 -0
  216. package/lib/transcript/tool-calls.d.ts.map +1 -0
  217. package/lib/transcript/tool-calls.js +254 -0
  218. package/lib/transcript/tool-calls.js.map +1 -0
  219. package/lib/transcript.d.ts +14 -55
  220. package/lib/transcript.d.ts.map +1 -1
  221. package/lib/transcript.js +31 -253
  222. package/lib/transcript.js.map +1 -1
  223. package/lib/ui/dock.d.ts +14 -2
  224. package/lib/ui/dock.d.ts.map +1 -1
  225. package/lib/ui/dock.js +52 -10
  226. package/lib/ui/dock.js.map +1 -1
  227. package/lib/ui/editor.d.ts.map +1 -1
  228. package/lib/ui/editor.js +2 -1
  229. package/lib/ui/editor.js.map +1 -1
  230. package/lib/ui/keymap-picker.d.ts +2 -1
  231. package/lib/ui/keymap-picker.d.ts.map +1 -1
  232. package/lib/ui/keymap-picker.js +1 -0
  233. package/lib/ui/keymap-picker.js.map +1 -1
  234. package/lib/ui/view/gate-card.d.ts +21 -0
  235. package/lib/ui/view/gate-card.d.ts.map +1 -0
  236. package/lib/ui/view/gate-card.js +104 -0
  237. package/lib/ui/view/gate-card.js.map +1 -0
  238. package/lib/ui/view/tool-card.d.ts +138 -0
  239. package/lib/ui/view/tool-card.d.ts.map +1 -0
  240. package/lib/ui/view/tool-card.js +413 -0
  241. package/lib/ui/view/tool-card.js.map +1 -0
  242. package/lib/ui/view/transcript-message.d.ts +62 -0
  243. package/lib/ui/view/transcript-message.d.ts.map +1 -0
  244. package/lib/ui/view/transcript-message.js +158 -0
  245. package/lib/ui/view/transcript-message.js.map +1 -0
  246. package/lib/ui/view.d.ts +80 -220
  247. package/lib/ui/view.d.ts.map +1 -1
  248. package/lib/ui/view.js +81 -675
  249. package/lib/ui/view.js.map +1 -1
  250. package/package.json +3 -1
@@ -0,0 +1,203 @@
1
+ /**
2
+ * The style state a renderer models: which attributes are on, which colour each
3
+ * names, and the sequences that move one state to the next.
4
+ *
5
+ * Apart from the grammar that reads those sequences and the renderer that emits
6
+ * rows, because which attributes and colours a terminal may set is a policy
7
+ * this surface owns, not a property of either.
8
+ */
9
+ import { sgrBackgroundPrefix, sgrPrefix } from "../theme-capability.js";
10
+ import { ESC, RESET, parseSgrParams } from "./scan.js";
11
+ export const CSI = `${ESC}[`;
12
+ /** The attributes a run may carry, in the order they are emitted. */
13
+ const ATTRIBUTES = ['bold', 'dim', 'italic', 'underline', 'inverse', 'strike'];
14
+ const ATTRIBUTE_ON = {
15
+ bold: `${CSI}1m`,
16
+ dim: `${CSI}2m`,
17
+ italic: `${CSI}3m`,
18
+ underline: `${CSI}4m`,
19
+ inverse: `${CSI}7m`,
20
+ strike: `${CSI}9m`,
21
+ };
22
+ const ATTRIBUTE_OFF = {
23
+ bold: `${CSI}22m`,
24
+ dim: `${CSI}22m`,
25
+ italic: `${CSI}23m`,
26
+ underline: `${CSI}24m`,
27
+ inverse: `${CSI}27m`,
28
+ strike: `${CSI}29m`,
29
+ };
30
+ const SGR_ATTRIBUTE_ON = { 1: 'bold', 2: 'dim', 3: 'italic', 4: 'underline', 7: 'inverse', 9: 'strike' };
31
+ const SGR_ATTRIBUTE_OFF = {
32
+ 21: ['bold', 'dim'],
33
+ 22: ['bold', 'dim'],
34
+ 23: ['italic'],
35
+ 24: ['underline'],
36
+ 27: ['inverse'],
37
+ 29: ['strike'],
38
+ };
39
+ const FIRST_FG_SLOT = 30;
40
+ const LAST_FG_SLOT = 37;
41
+ const FIRST_BRIGHT_FG_SLOT = 90;
42
+ const LAST_BRIGHT_FG_SLOT = 97;
43
+ const FIRST_BG_SLOT = 40;
44
+ const LAST_BG_SLOT = 47;
45
+ const FIRST_BRIGHT_BG_SLOT = 100;
46
+ const LAST_BRIGHT_BG_SLOT = 107;
47
+ const FG_DEFAULT = 39;
48
+ const BG_DEFAULT = 49;
49
+ const EXTENDED_FG = 38;
50
+ const EXTENDED_BG = 48;
51
+ const EXTENDED_INDEXED = 5;
52
+ const EXTENDED_RGB = 2;
53
+ const RGB_COMPONENTS = 3;
54
+ const HEX_PREFIX = '#';
55
+ const HEX_PAD = 2;
56
+ const COLOUR_MAX = 0xff;
57
+ const BRIGHT_OFFSET = 8;
58
+ const GROUND_FG = `${CSI}${FG_DEFAULT}m`;
59
+ const GROUND_BG = `${CSI}${BG_DEFAULT}m`;
60
+ export const GROUND = { attributes: 0 };
61
+ function withAttributes(style, on, off) {
62
+ let attributes = style.attributes;
63
+ if (off !== undefined)
64
+ for (const attribute of off)
65
+ attributes &= ~(1 << ATTRIBUTES.indexOf(attribute));
66
+ if (on !== undefined)
67
+ attributes |= 1 << ATTRIBUTES.indexOf(on);
68
+ return attributes === style.attributes ? style : { ...style, attributes };
69
+ }
70
+ function hasAttribute(style, attribute) {
71
+ return (style.attributes & (1 << ATTRIBUTES.indexOf(attribute))) !== 0;
72
+ }
73
+ /**
74
+ * Build the encoder for one colour budget.
75
+ *
76
+ * The element's own colour is the ground state rather than a reset, because a
77
+ * tool that ends a coloured run must not clear the colour the card drew it in;
78
+ * a full reset is never emitted, so nothing outside the run is disturbed.
79
+ */
80
+ export function encoder(color, base) {
81
+ if (color === 'none')
82
+ return { between: () => '' };
83
+ const groundCodes = (style) => {
84
+ let out = '';
85
+ for (const attribute of ATTRIBUTES)
86
+ if (hasAttribute(style, attribute))
87
+ out += ATTRIBUTE_OFF[attribute];
88
+ if (style.fg !== undefined)
89
+ out += GROUND_FG + base;
90
+ if (style.bg !== undefined)
91
+ out += GROUND_BG + base;
92
+ return out;
93
+ };
94
+ return {
95
+ between(previous, next) {
96
+ if (previous === next)
97
+ return '';
98
+ let out = '';
99
+ for (const attribute of ATTRIBUTES) {
100
+ if (hasAttribute(previous, attribute) && !hasAttribute(next, attribute))
101
+ out += ATTRIBUTE_OFF[attribute];
102
+ }
103
+ for (const attribute of ATTRIBUTES) {
104
+ if (!hasAttribute(previous, attribute) && hasAttribute(next, attribute))
105
+ out += ATTRIBUTE_ON[attribute];
106
+ }
107
+ if (next.fg !== previous.fg)
108
+ out += next.fg ?? GROUND_FG + base;
109
+ if (next.bg !== previous.bg)
110
+ out += next.bg ?? GROUND_BG + base;
111
+ return out;
112
+ },
113
+ };
114
+ }
115
+ function colourFor(params, at, color) {
116
+ const kind = params[at + 1];
117
+ if (kind === EXTENDED_INDEXED) {
118
+ const index = params[at + 2];
119
+ if (index === undefined)
120
+ return { next: params.length };
121
+ const code = params[at] === EXTENDED_FG ? sgrPrefix(index, color) : sgrBackgroundPrefix(index, color);
122
+ return { code: code === '' ? undefined : code, next: at + 3 };
123
+ }
124
+ if (kind === EXTENDED_RGB) {
125
+ const r = params[at + 2];
126
+ const g = params[at + 3];
127
+ const b = params[at + 4];
128
+ const spec = r === undefined || g === undefined || b === undefined ? undefined : rgbSpec(r, g, b);
129
+ if (spec === undefined)
130
+ return { next: at + 2 + RGB_COMPONENTS };
131
+ const code = params[at] === EXTENDED_FG ? sgrPrefix(spec, color) : sgrBackgroundPrefix(spec, color);
132
+ return { code: code === '' ? undefined : code, next: at + 2 + RGB_COMPONENTS };
133
+ }
134
+ return { next: at + 1 };
135
+ }
136
+ /** Apply an SGR sequence to the state a cell is written with. */
137
+ export function applySgr(style, params, color) {
138
+ let next = style;
139
+ let at = 0;
140
+ while (at < params.length) {
141
+ const param = params[at] ?? RESET;
142
+ if (param === RESET) {
143
+ next = GROUND;
144
+ at += 1;
145
+ continue;
146
+ }
147
+ const on = SGR_ATTRIBUTE_ON[param];
148
+ if (on !== undefined) {
149
+ next = withAttributes(next, on, undefined);
150
+ at += 1;
151
+ continue;
152
+ }
153
+ const off = SGR_ATTRIBUTE_OFF[param];
154
+ if (off !== undefined) {
155
+ next = withAttributes(next, undefined, off);
156
+ at += 1;
157
+ continue;
158
+ }
159
+ if (param === EXTENDED_FG || param === EXTENDED_BG) {
160
+ const extended = colourFor(params, at, color);
161
+ if (extended.next <= at)
162
+ break;
163
+ next = extended.code === undefined
164
+ ? { ...next, ...(param === EXTENDED_FG ? { fg: undefined } : { bg: undefined }) }
165
+ : { ...next, ...(param === EXTENDED_FG ? { fg: extended.code } : { bg: extended.code }) };
166
+ at = extended.next;
167
+ continue;
168
+ }
169
+ if (param >= FIRST_FG_SLOT && param <= LAST_FG_SLOT) {
170
+ next = { ...next, fg: slotColour(param - FIRST_FG_SLOT, color, 'fg') };
171
+ }
172
+ else if (param >= FIRST_BRIGHT_FG_SLOT && param <= LAST_BRIGHT_FG_SLOT) {
173
+ next = { ...next, fg: slotColour(param - FIRST_BRIGHT_FG_SLOT + BRIGHT_OFFSET, color, 'fg') };
174
+ }
175
+ else if (param === FG_DEFAULT) {
176
+ next = { ...next, fg: undefined };
177
+ }
178
+ else if (param >= FIRST_BG_SLOT && param <= LAST_BG_SLOT) {
179
+ next = { ...next, bg: slotColour(param - FIRST_BG_SLOT, color, 'bg') };
180
+ }
181
+ else if (param >= FIRST_BRIGHT_BG_SLOT && param <= LAST_BRIGHT_BG_SLOT) {
182
+ next = { ...next, bg: slotColour(param - FIRST_BRIGHT_BG_SLOT + BRIGHT_OFFSET, color, 'bg') };
183
+ }
184
+ else if (param === BG_DEFAULT) {
185
+ next = { ...next, bg: undefined };
186
+ }
187
+ at += 1;
188
+ }
189
+ return next;
190
+ }
191
+ /** The hex spec the colour helpers take, or nothing when a tool sent a component a colour cannot hold. */
192
+ function rgbSpec(r, g, b) {
193
+ for (const value of [r, g, b]) {
194
+ if (!Number.isInteger(value) || value < 0 || value > COLOUR_MAX)
195
+ return undefined;
196
+ }
197
+ return HEX_PREFIX + [r, g, b].map(value => value.toString(16).padStart(HEX_PAD, '0')).join('');
198
+ }
199
+ function slotColour(slot, color, layer) {
200
+ const code = layer === 'fg' ? sgrPrefix(slot, color) : sgrBackgroundPrefix(slot, color);
201
+ return code === '' ? undefined : code;
202
+ }
203
+ //# sourceMappingURL=sgr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sgr.js","sourceRoot":"","sources":["../../src/terminal-text/sgr.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAmB,MAAM,wBAAwB,CAAA;AACxF,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,cAAc,EAAc,MAAM,WAAW,CAAA;AAElE,MAAM,CAAC,MAAM,GAAG,GAAG,GAAG,GAAG,GAAG,CAAA;AAE5B,qEAAqE;AACrE,MAAM,UAAU,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,CAAU,CAAA;AAIvF,MAAM,YAAY,GAAwC;IACxD,IAAI,EAAE,GAAG,GAAG,IAAI;IAChB,GAAG,EAAE,GAAG,GAAG,IAAI;IACf,MAAM,EAAE,GAAG,GAAG,IAAI;IAClB,SAAS,EAAE,GAAG,GAAG,IAAI;IACrB,OAAO,EAAE,GAAG,GAAG,IAAI;IACnB,MAAM,EAAE,GAAG,GAAG,IAAI;CACnB,CAAA;AAED,MAAM,aAAa,GAAwC;IACzD,IAAI,EAAE,GAAG,GAAG,KAAK;IACjB,GAAG,EAAE,GAAG,GAAG,KAAK;IAChB,MAAM,EAAE,GAAG,GAAG,KAAK;IACnB,SAAS,EAAE,GAAG,GAAG,KAAK;IACtB,OAAO,EAAE,GAAG,GAAG,KAAK;IACpB,MAAM,EAAE,GAAG,GAAG,KAAK;CACpB,CAAA;AAED,MAAM,gBAAgB,GAAoD,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,SA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
  * sequence that is not SGR must be gone before any width is measured.
23
23
  */
24
- import { type ColourMode } from './theme-capability.ts';
24
+ import type { ColourMode } from './theme-capability.ts';
25
25
  /** Columns between tab stops: the POSIX default, and what every terminal still uses. */
26
26
  export declare const TAB_STOP = 8;
27
27
  /** Whether a tab is drawn on its stop, or kept for a buffer that will hold it. */
@@ -1 +1 @@
1
- {"version":3,"file":"terminal-text.d.ts","sourceRoot":"","sources":["../src/terminal-text.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,EAAkC,KAAK,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAEvF,wFAAwF;AACxF,eAAO,MAAM,QAAQ,IAAI,CAAA;AAEzB,kFAAkF;AAClF,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,MAAM,CAAA;AAEzC,MAAM,WAAW,iBAAiB;IAChC,yFAAyF;IACzF,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACpC,QAAQ,CAAC,GAAG,CAAC,EAAE,SAAS,GAAG,SAAS,CAAA;CACrC;AAED,MAAM,WAAW,iBAAiB;IAChC,6EAA6E;IAC7E,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAA;IAC1B,yFAAyF;IACzF,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAClC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACrC;AAuRD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB,GAAG,MAAM,CAkCvF;AAsJD;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,MAAM,CA2ElF;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAwBvE"}
1
+ {"version":3,"file":"terminal-text.d.ts","sourceRoot":"","sources":["../src/terminal-text.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAIvD,wFAAwF;AACxF,eAAO,MAAM,QAAQ,IAAI,CAAA;AAEzB,kFAAkF;AAClF,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,MAAM,CAAA;AAEzC,MAAM,WAAW,iBAAiB;IAChC,yFAAyF;IACzF,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACpC,QAAQ,CAAC,GAAG,CAAC,EAAE,SAAS,GAAG,SAAS,CAAA;CACrC;AAED,MAAM,WAAW,iBAAiB;IAChC,6EAA6E;IAC7E,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAA;IAC1B,yFAAyF;IACzF,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAClC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACrC;AA8BD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB,GAAG,MAAM,CAkCvF;AASD;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,MAAM,CA2ElF;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAwBvE"}
@@ -22,245 +22,11 @@
22
22
  * sequence that is not SGR must be gone before any width is measured.
23
23
  */
24
24
  import { visibleWidth } from '@earendil-works/pi-tui';
25
- import { sgrBackgroundPrefix, sgrPrefix } from "./theme-capability.js";
25
+ import { NEEDS_READING, scan, spellControls } from "./terminal-text/scan.js";
26
+ import { GROUND, applySgr, encoder } from "./terminal-text/sgr.js";
26
27
  /** Columns between tab stops: the POSIX default, and what every terminal still uses. */
27
28
  export const TAB_STOP = 8;
28
- const ESC = '\u001b';
29
- const CSI = `${ESC}[`;
30
- const REPLACEMENT = '\uFFFD';
31
- const C0_PREFIX = '\\x';
32
- const UNICODE_PREFIX = '\\u';
33
- const HEX2 = 2;
34
- const HEX4 = 4;
35
- const LAST_C0 = 0x1f;
36
- const TAB = 0x09;
37
- const LINE_FEED = 0x0a;
38
- const CARRIAGE_RETURN = 0x0d;
39
- const BACKSPACE = 0x08;
40
- const DELETE = 0x7f;
41
- const FIRST_C1 = 0x80;
42
- const LAST_C1 = 0x9f;
43
- const FIRST_SURROGATE = 0xd800;
44
- const LAST_SURROGATE = 0xdfff;
45
- /** The bytes a text fragment cannot be drawn with: they are either sequences to read or marks to spell. */
46
- const NEEDS_READING = /[\u0000-\u0009\u000B-\u001F\u007F-\u009F\u061C\u200E\u200F\u2028\u2029\u202A-\u202E\u2066-\u2069\uD800-\uDFFF]/u;
47
- /** Directional overrides and isolates, which reorder a row without drawing anything. */
48
- const BIDI_CONTROLS = new Set([0x202a, 0x202b, 0x202c, 0x202d, 0x202e, 0x2066, 0x2067, 0x2068, 0x2069]);
49
- const LINE_SEPARATOR = 0x2028;
50
- const PARAGRAPH_SEPARATOR = 0x2029;
51
- const ARABIC_LETTER_MARK = 0x061c;
52
- const LEFT_TO_RIGHT_MARK = 0x200e;
53
- const RIGHT_TO_LEFT_MARK = 0x200f;
54
29
  const GRAPHEMES = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
55
- /** The SGR final byte, and the parameter bytes a sequence may carry before it. */
56
- const SGR_FINAL = 'm';
57
- const CSI_PARAMETER_LAST = 0x3f;
58
- const CSI_INTERMEDIATE_FIRST = 0x20;
59
- const CSI_INTERMEDIATE_LAST = 0x2f;
60
- const CSI_FINAL_FIRST = 0x40;
61
- const CSI_FINAL_LAST = 0x7e;
62
- const ESCAPE_FINAL_FIRST = 0x30;
63
- const OSC_INTRODUCER = ']';
64
- const STRING_INTRODUCERS = new Set(['P', 'X', '^', '_']);
65
- const STRING_END = '\u0007';
66
- /** The attributes a run may carry, in the order they are emitted. */
67
- const ATTRIBUTES = ['bold', 'dim', 'italic', 'underline', 'inverse', 'strike'];
68
- const ATTRIBUTE_ON = {
69
- bold: `${CSI}1m`,
70
- dim: `${CSI}2m`,
71
- italic: `${CSI}3m`,
72
- underline: `${CSI}4m`,
73
- inverse: `${CSI}7m`,
74
- strike: `${CSI}9m`,
75
- };
76
- const ATTRIBUTE_OFF = {
77
- bold: `${CSI}22m`,
78
- dim: `${CSI}22m`,
79
- italic: `${CSI}23m`,
80
- underline: `${CSI}24m`,
81
- inverse: `${CSI}27m`,
82
- strike: `${CSI}29m`,
83
- };
84
- const SGR_ATTRIBUTE_ON = { 1: 'bold', 2: 'dim', 3: 'italic', 4: 'underline', 7: 'inverse', 9: 'strike' };
85
- const SGR_ATTRIBUTE_OFF = {
86
- 21: ['bold', 'dim'],
87
- 22: ['bold', 'dim'],
88
- 23: ['italic'],
89
- 24: ['underline'],
90
- 27: ['inverse'],
91
- 29: ['strike'],
92
- };
93
- const FIRST_FG_SLOT = 30;
94
- const LAST_FG_SLOT = 37;
95
- const FIRST_BRIGHT_FG_SLOT = 90;
96
- const LAST_BRIGHT_FG_SLOT = 97;
97
- const FIRST_BG_SLOT = 40;
98
- const LAST_BG_SLOT = 47;
99
- const FIRST_BRIGHT_BG_SLOT = 100;
100
- const LAST_BRIGHT_BG_SLOT = 107;
101
- const FG_DEFAULT = 39;
102
- const BG_DEFAULT = 49;
103
- const EXTENDED_FG = 38;
104
- const EXTENDED_BG = 48;
105
- const EXTENDED_INDEXED = 5;
106
- const EXTENDED_RGB = 2;
107
- const RGB_COMPONENTS = 3;
108
- const HEX_PREFIX = '#';
109
- const HEX_PAD = 2;
110
- const COLOUR_MAX = 0xff;
111
- const BRIGHT_OFFSET = 8;
112
- const RESET = 0;
113
- const GROUND_FG = `${CSI}${FG_DEFAULT}m`;
114
- const GROUND_BG = `${CSI}${BG_DEFAULT}m`;
115
- function escapeCode(prefix, code, digits) {
116
- return prefix + code.toString(16).toUpperCase().padStart(digits, '0');
117
- }
118
- /** Whether a code point is a mark this module spells instead of drawing. */
119
- function isSpelledControl(code) {
120
- if (code <= LAST_C0 || code === DELETE)
121
- return true;
122
- if (code >= FIRST_C1 && code <= LAST_C1)
123
- return true;
124
- return BIDI_CONTROLS.has(code) || code === LINE_SEPARATOR || code === PARAGRAPH_SEPARATOR || code === ARABIC_LETTER_MARK || code === LEFT_TO_RIGHT_MARK || code === RIGHT_TO_LEFT_MARK;
125
- }
126
- function spelled(code) {
127
- if (code <= 0xff)
128
- return escapeCode(C0_PREFIX, code, HEX2);
129
- return escapeCode(UNICODE_PREFIX, code, HEX4);
130
- }
131
- /** Every character of a sequence that is a control, spelled; the rest of it is printable. */
132
- function spellControls(raw) {
133
- let out = '';
134
- for (const character of raw) {
135
- const code = character.codePointAt(0) ?? 0;
136
- out += isSpelledControl(code) ? spelled(code) : character;
137
- }
138
- return out;
139
- }
140
- function isCsiFinal(code) {
141
- return code >= CSI_FINAL_FIRST && code <= CSI_FINAL_LAST;
142
- }
143
- /**
144
- * Read one escape sequence at `at`.
145
- *
146
- * A string sequence (OSC, DCS, and their siblings) runs to BEL or ST; when its
147
- * terminator never arrives the sequence is reported incomplete rather than
148
- * swallowed to the end of the row, because the renderer and the editor want
149
- * different answers for a truncated sequence and only the scanner knows where
150
- * it stopped.
151
- */
152
- function readEscape(raw, at) {
153
- const introducer = raw[at + 1];
154
- if (introducer === undefined)
155
- return undefined;
156
- if (introducer === '[') {
157
- let end = at + 2;
158
- while (end < raw.length) {
159
- const code = raw.charCodeAt(end);
160
- if (isCsiFinal(code)) {
161
- const source = raw.slice(at, end + 1);
162
- if (raw[end] === SGR_FINAL) {
163
- const params = parseSgrParams(source.slice(2, -1));
164
- if (params !== undefined)
165
- return { token: { kind: 'sgr', params }, raw: source };
166
- }
167
- return { token: { kind: 'consumed' }, raw: source };
168
- }
169
- if (code > CSI_PARAMETER_LAST && (code < CSI_INTERMEDIATE_FIRST || code > CSI_INTERMEDIATE_LAST)) {
170
- // A byte outside the CSI grammar ends the sequence as malformed; the
171
- // sequence is consumed so its bytes cannot be drawn as text.
172
- return { token: { kind: 'consumed' }, raw: raw.slice(at, end) };
173
- }
174
- end += 1;
175
- }
176
- return { token: { kind: 'incomplete' }, raw: raw.slice(at) };
177
- }
178
- if (introducer === OSC_INTRODUCER || STRING_INTRODUCERS.has(introducer)) {
179
- let end = at + 2;
180
- while (end < raw.length) {
181
- if (raw[end] === STRING_END)
182
- return { token: { kind: 'consumed' }, raw: raw.slice(at, end + 1) };
183
- if (raw[end] === ESC && raw[end + 1] === '\\')
184
- return { token: { kind: 'consumed' }, raw: raw.slice(at, end + 2) };
185
- end += 1;
186
- }
187
- return { token: { kind: 'incomplete' }, raw: raw.slice(at) };
188
- }
189
- const code = raw.charCodeAt(at + 1);
190
- if (code >= ESCAPE_FINAL_FIRST && code <= CSI_FINAL_LAST) {
191
- return { token: { kind: 'consumed' }, raw: raw.slice(at, at + 2) };
192
- }
193
- return undefined;
194
- }
195
- /** The parameters of an SGR sequence, or nothing when it uses a form this module does not model. */
196
- function parseSgrParams(body) {
197
- if (body === '')
198
- return [RESET];
199
- const params = [];
200
- for (const part of body.split(';')) {
201
- if (!/^[0-9]*$/.test(part))
202
- return undefined;
203
- params.push(part === '' ? RESET : Number(part));
204
- }
205
- return params;
206
- }
207
- /** Split a text fragment into the pieces a policy draws or spells. */
208
- function scan(raw) {
209
- const pieces = [];
210
- let text = '';
211
- const flush = () => {
212
- if (text === '')
213
- return;
214
- pieces.push({ token: { kind: 'text' }, raw: text });
215
- text = '';
216
- };
217
- let at = 0;
218
- while (at < raw.length) {
219
- const code = raw.codePointAt(at) ?? 0;
220
- const character = String.fromCodePoint(code);
221
- if (code === LINE_FEED) {
222
- flush();
223
- pieces.push({ token: { kind: 'lineFeed' }, raw: character });
224
- }
225
- else if (code === TAB) {
226
- flush();
227
- pieces.push({ token: { kind: 'tab' }, raw: character });
228
- }
229
- else if (code === CARRIAGE_RETURN) {
230
- flush();
231
- pieces.push({ token: { kind: 'carriageReturn' }, raw: character });
232
- }
233
- else if (code === BACKSPACE) {
234
- flush();
235
- pieces.push({ token: { kind: 'backspace' }, raw: character });
236
- }
237
- else if (code === 0x1b) {
238
- flush();
239
- const sequence = readEscape(raw, at);
240
- if (sequence === undefined) {
241
- pieces.push({ token: { kind: 'control' }, raw: character });
242
- }
243
- else {
244
- pieces.push(sequence);
245
- at += sequence.raw.length;
246
- continue;
247
- }
248
- }
249
- else if (code >= FIRST_SURROGATE && code <= LAST_SURROGATE) {
250
- text += REPLACEMENT;
251
- }
252
- else if (isSpelledControl(code)) {
253
- flush();
254
- pieces.push({ token: { kind: 'control' }, raw: character });
255
- }
256
- else {
257
- text += character;
258
- }
259
- at += character.length;
260
- }
261
- flush();
262
- return pieces;
263
- }
264
30
  /** How many characters a reader sees in this piece, which is what a row budget pays for. */
265
31
  function visibleLength(piece) {
266
32
  switch (piece.token.kind) {
@@ -330,149 +96,6 @@ export function escapeTerminalText(raw, options = {}) {
330
96
  }
331
97
  return out;
332
98
  }
333
- const GROUND = { attributes: 0 };
334
- function withAttributes(style, on, off) {
335
- let attributes = style.attributes;
336
- if (off !== undefined)
337
- for (const attribute of off)
338
- attributes &= ~(1 << ATTRIBUTES.indexOf(attribute));
339
- if (on !== undefined)
340
- attributes |= 1 << ATTRIBUTES.indexOf(on);
341
- return attributes === style.attributes ? style : { ...style, attributes };
342
- }
343
- function hasAttribute(style, attribute) {
344
- return (style.attributes & (1 << ATTRIBUTES.indexOf(attribute))) !== 0;
345
- }
346
- /**
347
- * Build the encoder for one colour budget.
348
- *
349
- * The element's own colour is the ground state rather than a reset, because a
350
- * tool that ends a coloured run must not clear the colour the card drew it in;
351
- * a full reset is never emitted, so nothing outside the run is disturbed.
352
- */
353
- function encoder(color, base) {
354
- if (color === 'none')
355
- return { between: () => '' };
356
- const groundCodes = (style) => {
357
- let out = '';
358
- for (const attribute of ATTRIBUTES)
359
- if (hasAttribute(style, attribute))
360
- out += ATTRIBUTE_OFF[attribute];
361
- if (style.fg !== undefined)
362
- out += GROUND_FG + base;
363
- if (style.bg !== undefined)
364
- out += GROUND_BG + base;
365
- return out;
366
- };
367
- return {
368
- between(previous, next) {
369
- if (previous === next)
370
- return '';
371
- let out = '';
372
- for (const attribute of ATTRIBUTES) {
373
- if (hasAttribute(previous, attribute) && !hasAttribute(next, attribute))
374
- out += ATTRIBUTE_OFF[attribute];
375
- }
376
- for (const attribute of ATTRIBUTES) {
377
- if (!hasAttribute(previous, attribute) && hasAttribute(next, attribute))
378
- out += ATTRIBUTE_ON[attribute];
379
- }
380
- if (next.fg !== previous.fg)
381
- out += next.fg ?? GROUND_FG + base;
382
- if (next.bg !== previous.bg)
383
- out += next.bg ?? GROUND_BG + base;
384
- return out;
385
- },
386
- };
387
- }
388
- function colourFor(params, at, color) {
389
- const kind = params[at + 1];
390
- if (kind === EXTENDED_INDEXED) {
391
- const index = params[at + 2];
392
- if (index === undefined)
393
- return { next: params.length };
394
- const code = params[at] === EXTENDED_FG ? sgrPrefix(index, color) : sgrBackgroundPrefix(index, color);
395
- return { code: code === '' ? undefined : code, next: at + 3 };
396
- }
397
- if (kind === EXTENDED_RGB) {
398
- const r = params[at + 2];
399
- const g = params[at + 3];
400
- const b = params[at + 4];
401
- const spec = r === undefined || g === undefined || b === undefined ? undefined : rgbSpec(r, g, b);
402
- if (spec === undefined)
403
- return { next: at + 2 + RGB_COMPONENTS };
404
- const code = params[at] === EXTENDED_FG ? sgrPrefix(spec, color) : sgrBackgroundPrefix(spec, color);
405
- return { code: code === '' ? undefined : code, next: at + 2 + RGB_COMPONENTS };
406
- }
407
- return { next: at + 1 };
408
- }
409
- /** Apply an SGR sequence to the state a cell is written with. */
410
- function applySgr(style, params, color) {
411
- let next = style;
412
- let at = 0;
413
- while (at < params.length) {
414
- const param = params[at] ?? RESET;
415
- if (param === RESET) {
416
- next = GROUND;
417
- at += 1;
418
- continue;
419
- }
420
- const on = SGR_ATTRIBUTE_ON[param];
421
- if (on !== undefined) {
422
- next = withAttributes(next, on, undefined);
423
- at += 1;
424
- continue;
425
- }
426
- const off = SGR_ATTRIBUTE_OFF[param];
427
- if (off !== undefined) {
428
- next = withAttributes(next, undefined, off);
429
- at += 1;
430
- continue;
431
- }
432
- if (param === EXTENDED_FG || param === EXTENDED_BG) {
433
- const extended = colourFor(params, at, color);
434
- if (extended.next <= at)
435
- break;
436
- next = extended.code === undefined
437
- ? { ...next, ...(param === EXTENDED_FG ? { fg: undefined } : { bg: undefined }) }
438
- : { ...next, ...(param === EXTENDED_FG ? { fg: extended.code } : { bg: extended.code }) };
439
- at = extended.next;
440
- continue;
441
- }
442
- if (param >= FIRST_FG_SLOT && param <= LAST_FG_SLOT) {
443
- next = { ...next, fg: slotColour(param - FIRST_FG_SLOT, color, 'fg') };
444
- }
445
- else if (param >= FIRST_BRIGHT_FG_SLOT && param <= LAST_BRIGHT_FG_SLOT) {
446
- next = { ...next, fg: slotColour(param - FIRST_BRIGHT_FG_SLOT + BRIGHT_OFFSET, color, 'fg') };
447
- }
448
- else if (param === FG_DEFAULT) {
449
- next = { ...next, fg: undefined };
450
- }
451
- else if (param >= FIRST_BG_SLOT && param <= LAST_BG_SLOT) {
452
- next = { ...next, bg: slotColour(param - FIRST_BG_SLOT, color, 'bg') };
453
- }
454
- else if (param >= FIRST_BRIGHT_BG_SLOT && param <= LAST_BRIGHT_BG_SLOT) {
455
- next = { ...next, bg: slotColour(param - FIRST_BRIGHT_BG_SLOT + BRIGHT_OFFSET, color, 'bg') };
456
- }
457
- else if (param === BG_DEFAULT) {
458
- next = { ...next, bg: undefined };
459
- }
460
- at += 1;
461
- }
462
- return next;
463
- }
464
- /** The hex spec the colour helpers take, or nothing when a tool sent a component a colour cannot hold. */
465
- function rgbSpec(r, g, b) {
466
- for (const value of [r, g, b]) {
467
- if (!Number.isInteger(value) || value < 0 || value > COLOUR_MAX)
468
- return undefined;
469
- }
470
- return HEX_PREFIX + [r, g, b].map(value => value.toString(16).padStart(HEX_PAD, '0')).join('');
471
- }
472
- function slotColour(slot, color, layer) {
473
- const code = layer === 'fg' ? sgrPrefix(slot, color) : sgrBackgroundPrefix(slot, color);
474
- return code === '' ? undefined : code;
475
- }
476
99
  /**
477
100
  * Draw text as the terminal that produced it would have drawn it.
478
101
  *