@linxiraos/pi-tui 1.4.11 → 1.4.13

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 (265) hide show
  1. package/CHANGELOG.md +30 -233
  2. package/README.md +4 -1
  3. package/THIRD-PARTY-NOTICES.txt +4 -5
  4. package/dist/types/apps/shell-visualizer.d.ts +24 -0
  5. package/dist/types/autocomplete.d.ts +20 -0
  6. package/dist/types/chat/cache-invalidation-marker.d.ts +15 -7
  7. package/dist/types/chat/chat-transcript-builder.d.ts +5 -3
  8. package/dist/types/chat/display-preferences.d.ts +2 -0
  9. package/dist/types/chat/extension-types.d.ts +72 -1
  10. package/dist/types/chat/image-loading.d.ts +2 -2
  11. package/dist/types/chat/messages.d.ts +2 -3
  12. package/dist/types/chat/read-tool-group.d.ts +15 -2
  13. package/dist/types/chat/skill-message.d.ts +1 -0
  14. package/dist/types/chat/spotlight.d.ts +203 -0
  15. package/dist/types/chat/tool-execution.d.ts +26 -5
  16. package/dist/types/chat/transcript-actions.d.ts +11 -0
  17. package/dist/types/chat/transcript-browser.d.ts +9 -0
  18. package/dist/types/chat/transcript-presentation.d.ts +164 -0
  19. package/dist/types/chat/ttsr-notification.d.ts +2 -0
  20. package/dist/types/chrome/message-frame.d.ts +2 -0
  21. package/dist/types/chrome/transcript-container.d.ts +27 -6
  22. package/dist/types/components/loader.d.ts +0 -2
  23. package/dist/types/components/markdown.d.ts +11 -1
  24. package/dist/types/components/settings-list.d.ts +12 -2
  25. package/dist/types/frame-rate.d.ts +18 -0
  26. package/dist/types/hotkeys-markdown.d.ts +2 -0
  27. package/dist/types/index.d.ts +3 -0
  28. package/dist/types/keybinding-matchers.d.ts +4 -1
  29. package/dist/types/kitty-graphics.d.ts +1 -1
  30. package/dist/types/motion-effects.d.ts +10 -0
  31. package/dist/types/native/encode.d.ts +2 -0
  32. package/dist/types/native/measure.d.ts +10 -0
  33. package/dist/types/native/overlay.d.ts +1 -1
  34. package/dist/types/native/quiet.d.ts +5 -0
  35. package/dist/types/native/reconcile.d.ts +6 -1
  36. package/dist/types/native/spans.d.ts +6 -0
  37. package/dist/types/native/state.d.ts +4 -0
  38. package/dist/types/overlays/agent-hub.d.ts +6 -0
  39. package/dist/types/overlays/link-browser.d.ts +55 -0
  40. package/dist/types/overlays/running-subagent-badge.d.ts +1 -4
  41. package/dist/types/overlays/spotlight-sheet.d.ts +36 -0
  42. package/dist/types/prompt/composer-attachments.d.ts +5 -2
  43. package/dist/types/prompt/composer-cache.d.ts +7 -2
  44. package/dist/types/prompt/composer.d.ts +6 -11
  45. package/dist/types/prompt/custom-editor.d.ts +8 -2
  46. package/dist/types/prompt/gradient-highlight.d.ts +2 -2
  47. package/dist/types/prompt/magic-keywords.d.ts +2 -0
  48. package/dist/types/prompt/model-mention-autocomplete.d.ts +9 -7
  49. package/dist/types/prompt/model-mention-syntax.d.ts +6 -0
  50. package/dist/types/prompt/prompt-action-autocomplete.d.ts +2 -1
  51. package/dist/types/prompt/welcome.d.ts +19 -0
  52. package/dist/types/render/extension-links.d.ts +0 -6
  53. package/dist/types/render/index.d.ts +1 -0
  54. package/dist/types/render/link-hints.d.ts +78 -0
  55. package/dist/types/render/render-utils.d.ts +0 -2
  56. package/dist/types/setup/scenes/types.d.ts +8 -0
  57. package/dist/types/setup/scenes/updates.d.ts +6 -0
  58. package/dist/types/setup/wizard.d.ts +7 -2
  59. package/dist/types/spinner-clock.d.ts +34 -0
  60. package/dist/types/status-line/component.d.ts +8 -4
  61. package/dist/types/status-line/host.d.ts +62 -0
  62. package/dist/types/status-line/index.d.ts +1 -0
  63. package/dist/types/status-line/prompt-cache.d.ts +14 -0
  64. package/dist/types/status-line/schema.d.ts +1 -1
  65. package/dist/types/status-line/startup.d.ts +6 -0
  66. package/dist/types/status-line/types.d.ts +8 -21
  67. package/dist/types/theme/schema.d.ts +28 -1
  68. package/dist/types/theme/symbols.d.ts +1 -1
  69. package/dist/types/theme/theme-class.d.ts +12 -2
  70. package/dist/types/theme/theme.d.ts +1 -1
  71. package/dist/types/theme/tui-adapters.d.ts +7 -0
  72. package/dist/types/thinking.d.ts +12 -0
  73. package/dist/types/tools/ask.d.ts +1 -1
  74. package/dist/types/tools/bash.d.ts +21 -0
  75. package/dist/types/tools/find.d.ts +9 -1
  76. package/dist/types/tools/grep.d.ts +2 -1
  77. package/dist/types/tools/grouped-file-output.d.ts +17 -0
  78. package/dist/types/tools/job-widget.d.ts +2 -2
  79. package/dist/types/tools/lsp.d.ts +4 -2
  80. package/dist/types/tools/native-view.d.ts +4 -0
  81. package/dist/types/tools/renderer.d.ts +9 -1
  82. package/dist/types/tools/shell-trace.d.ts +10 -0
  83. package/dist/types/tools/shell-viz-render.d.ts +6 -0
  84. package/dist/types/tools/shell-viz.d.ts +16 -0
  85. package/dist/types/tools/wait.d.ts +2 -2
  86. package/dist/types/tools/web-search-types.d.ts +1 -0
  87. package/dist/types/tools/write.d.ts +2 -0
  88. package/dist/types/tui.d.ts +15 -1
  89. package/package.json +15 -11
  90. package/src/apps/shell-visualizer.d.ts +24 -0
  91. package/src/apps/shell-visualizer.ts +167 -0
  92. package/src/autocomplete.d.ts +20 -0
  93. package/src/autocomplete.ts +14 -0
  94. package/src/chat/assistant-message.ts +11 -6
  95. package/src/chat/cache-invalidation-marker.d.ts +15 -7
  96. package/src/chat/cache-invalidation-marker.ts +18 -9
  97. package/src/chat/chat-transcript-builder.d.ts +5 -3
  98. package/src/chat/chat-transcript-builder.ts +16 -12
  99. package/src/chat/display-preferences.d.ts +2 -0
  100. package/src/chat/display-preferences.ts +3 -0
  101. package/src/chat/extension-types.d.ts +72 -1
  102. package/src/chat/extension-types.ts +74 -1
  103. package/src/chat/image-loading.d.ts +2 -2
  104. package/src/chat/image-loading.ts +2 -2
  105. package/src/chat/messages.d.ts +2 -3
  106. package/src/chat/messages.ts +3 -8
  107. package/src/chat/read-tool-group.d.ts +15 -2
  108. package/src/chat/read-tool-group.ts +201 -41
  109. package/src/chat/skill-message.d.ts +1 -0
  110. package/src/chat/skill-message.ts +4 -0
  111. package/src/chat/spotlight.d.ts +203 -0
  112. package/src/chat/spotlight.ts +460 -0
  113. package/src/chat/tool-execution.d.ts +26 -5
  114. package/src/chat/tool-execution.ts +360 -38
  115. package/src/chat/transcript-actions.d.ts +11 -0
  116. package/src/chat/transcript-actions.ts +13 -1
  117. package/src/chat/transcript-browser.d.ts +9 -0
  118. package/src/chat/transcript-browser.ts +18 -0
  119. package/src/chat/transcript-presentation.d.ts +164 -0
  120. package/src/chat/transcript-presentation.ts +642 -0
  121. package/src/chat/ttsr-notification.d.ts +25 -0
  122. package/src/chat/ttsr-notification.ts +5 -0
  123. package/src/chrome/message-frame.d.ts +2 -0
  124. package/src/chrome/message-frame.ts +7 -0
  125. package/src/chrome/message-notice.d.ts +58 -0
  126. package/src/chrome/transcript-container.d.ts +27 -6
  127. package/src/chrome/transcript-container.ts +317 -66
  128. package/src/components/editor.ts +25 -1
  129. package/src/components/loader.d.ts +0 -2
  130. package/src/components/loader.ts +30 -18
  131. package/src/components/markdown.d.ts +11 -1
  132. package/src/components/markdown.ts +41 -16
  133. package/src/components/settings-list.d.ts +12 -2
  134. package/src/components/settings-list.ts +29 -13
  135. package/src/frame-rate.d.ts +18 -0
  136. package/src/frame-rate.ts +36 -0
  137. package/src/hotkeys-markdown.ts +9 -2
  138. package/src/index.d.ts +3 -0
  139. package/src/index.ts +3 -0
  140. package/src/keybinding-matchers.d.ts +4 -1
  141. package/src/keybinding-matchers.ts +13 -12
  142. package/src/kitty-graphics.d.ts +1 -1
  143. package/src/kitty-graphics.ts +3 -2
  144. package/src/motion-effects.d.ts +10 -0
  145. package/src/motion-effects.ts +27 -0
  146. package/src/native/backend.ts +66 -7
  147. package/src/native/encode.d.ts +2 -0
  148. package/src/native/encode.ts +2 -0
  149. package/src/native/measure.d.ts +10 -0
  150. package/src/native/measure.ts +185 -0
  151. package/src/native/overlay.d.ts +1 -1
  152. package/src/native/overlay.ts +1 -1
  153. package/src/native/quiet.d.ts +5 -0
  154. package/src/native/quiet.ts +105 -0
  155. package/src/native/reconcile.d.ts +6 -1
  156. package/src/native/reconcile.ts +16 -10
  157. package/src/native/spans.d.ts +6 -0
  158. package/src/native/spans.ts +40 -0
  159. package/src/native/state.d.ts +4 -0
  160. package/src/native/state.ts +18 -0
  161. package/src/overlays/agent-hub.ts +15 -2
  162. package/src/overlays/ask-dialog.ts +1 -0
  163. package/src/overlays/btw-history-panel.ts +73 -6
  164. package/src/overlays/link-browser.ts +295 -0
  165. package/src/overlays/running-subagent-badge.ts +2 -9
  166. package/src/overlays/settings-defs.ts +1 -1
  167. package/src/overlays/settings-selector.ts +17 -3
  168. package/src/overlays/spotlight-sheet.ts +478 -0
  169. package/src/overlays/usage-dashboard.ts +6 -5
  170. package/src/prompt/composer-attachments.d.ts +5 -2
  171. package/src/prompt/composer-attachments.ts +6 -6
  172. package/src/prompt/composer-cache.ts +17 -16
  173. package/src/prompt/composer.ts +30 -123
  174. package/src/prompt/custom-editor.ts +17 -13
  175. package/src/prompt/gradient-highlight.d.ts +2 -2
  176. package/src/prompt/gradient-highlight.ts +5 -4
  177. package/src/prompt/magic-keywords.d.ts +2 -0
  178. package/src/prompt/magic-keywords.ts +4 -1
  179. package/src/prompt/model-mention-autocomplete.ts +73 -20
  180. package/src/prompt/model-mention-syntax.d.ts +6 -0
  181. package/src/prompt/model-mention-syntax.ts +9 -0
  182. package/src/prompt/prompt-action-autocomplete.ts +49 -33
  183. package/src/prompt/tips.txt +1 -0
  184. package/src/prompt/welcome.ts +104 -2
  185. package/src/render/extension-links.d.ts +0 -6
  186. package/src/render/extension-links.ts +0 -20
  187. package/src/render/index.d.ts +1 -0
  188. package/src/render/index.ts +1 -0
  189. package/src/render/link-hints.d.ts +78 -0
  190. package/src/render/link-hints.ts +299 -0
  191. package/src/render/render-utils.d.ts +0 -2
  192. package/src/render/render-utils.ts +0 -5
  193. package/src/setup/scenes/glyph.ts +1 -1
  194. package/src/setup/scenes/types.ts +8 -0
  195. package/src/setup/scenes/updates.ts +116 -0
  196. package/src/setup/wizard.ts +19 -8
  197. package/src/spinner-clock.d.ts +34 -0
  198. package/src/spinner-clock.ts +79 -0
  199. package/src/status-line/component.ts +145 -53
  200. package/src/status-line/host.ts +51 -0
  201. package/src/status-line/index.ts +1 -0
  202. package/src/status-line/presets.ts +3 -1
  203. package/src/status-line/prompt-cache.ts +154 -0
  204. package/src/status-line/schema.ts +1 -1
  205. package/src/status-line/segments.ts +33 -22
  206. package/src/status-line/startup.ts +22 -4
  207. package/src/status-line/types.ts +8 -22
  208. package/src/stdin-buffer.ts +89 -46
  209. package/src/terminal-capabilities.ts +3 -3
  210. package/src/terminal.ts +1 -8
  211. package/src/theme/loader.ts +3 -2
  212. package/src/theme/schema.d.ts +28 -1
  213. package/src/theme/schema.ts +30 -1
  214. package/src/theme/symbols.d.ts +1 -1
  215. package/src/theme/symbols.ts +15 -3
  216. package/src/theme/theme-class.d.ts +12 -2
  217. package/src/theme/theme-class.ts +23 -0
  218. package/src/theme/theme-schema.json +1 -1
  219. package/src/theme/theme.d.ts +1 -1
  220. package/src/theme/theme.ts +3 -7
  221. package/src/theme/tui-adapters.d.ts +7 -0
  222. package/src/theme/tui-adapters.ts +33 -1
  223. package/src/thinking.d.ts +12 -0
  224. package/src/thinking.ts +31 -0
  225. package/src/tools/ask.d.ts +1 -1
  226. package/src/tools/ask.ts +99 -38
  227. package/src/tools/ast-edit.ts +51 -32
  228. package/src/tools/ast-grep.ts +31 -19
  229. package/src/tools/bash.d.ts +21 -0
  230. package/src/tools/bash.ts +166 -24
  231. package/src/tools/find.d.ts +9 -1
  232. package/src/tools/find.ts +23 -2
  233. package/src/tools/grep.d.ts +2 -1
  234. package/src/tools/grep.ts +52 -36
  235. package/src/tools/grouped-file-output.d.ts +17 -0
  236. package/src/tools/grouped-file-output.ts +20 -2
  237. package/src/tools/job-widget.d.ts +2 -2
  238. package/src/tools/job-widget.ts +2 -2
  239. package/src/tools/lsp.d.ts +4 -2
  240. package/src/tools/lsp.ts +537 -642
  241. package/src/tools/native-view.d.ts +4 -0
  242. package/src/tools/native-view.ts +8 -2
  243. package/src/tools/renderer.d.ts +9 -1
  244. package/src/tools/renderer.ts +9 -1
  245. package/src/tools/shell-trace.d.ts +10 -0
  246. package/src/tools/shell-trace.ts +80 -0
  247. package/src/tools/shell-viz-render.d.ts +6 -0
  248. package/src/tools/shell-viz-render.ts +156 -0
  249. package/src/tools/shell-viz.d.ts +16 -0
  250. package/src/tools/shell-viz.ts +181 -0
  251. package/src/tools/streaming-output.ts +18 -8
  252. package/src/tools/wait.d.ts +2 -2
  253. package/src/tools/wait.ts +39 -34
  254. package/src/tools/web-search-types.d.ts +1 -0
  255. package/src/tools/web-search-types.ts +1 -0
  256. package/src/tools/write.d.ts +2 -0
  257. package/src/tools/write.ts +2 -0
  258. package/src/tui.d.ts +15 -1
  259. package/src/tui.ts +63 -6
  260. package/src/windows-input-mode.ts +7 -1
  261. package/dist/types/chat/collab-prompt-message.d.ts +0 -14
  262. package/dist/types/chrome/collab-qrcode.d.ts +0 -35
  263. package/src/chat/collab-prompt-message.d.ts +0 -14
  264. package/src/chat/collab-prompt-message.ts +0 -46
  265. package/src/chrome/collab-qrcode.ts +0 -99
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Decorative motion with no knob of its own — the status-line blink and brand fade, the editor's
3
+ * magic-keyword sweep, native `fx` spans — behind one switch the host's `tui.motion` preset drives.
4
+ */
5
+
6
+ let enabled = true;
7
+ const listeners = new Set<() => void>();
8
+
9
+ /** Whether decorative motion may run. */
10
+ export function motionEffectsEnabled(): boolean {
11
+ return enabled;
12
+ }
13
+
14
+ /** Enable or disable decorative motion. Timer-driven effects stop at their next frame. */
15
+ export function setMotionEffects(next: boolean): void {
16
+ if (next === enabled) return;
17
+ enabled = next;
18
+ for (const listener of listeners) listener();
19
+ }
20
+
21
+ /** Observe switch flips, for output nothing would otherwise re-describe; returns the unsubscribe. */
22
+ export function onMotionEffectsChange(listener: () => void): () => void {
23
+ listeners.add(listener);
24
+ return () => {
25
+ listeners.delete(listener);
26
+ };
27
+ }
@@ -38,6 +38,8 @@ import {
38
38
  type TspNode,
39
39
  type TspOp,
40
40
  } from "@linxiraos/pi-wire";
41
+ import { onMotionEffectsChange } from "../motion-effects";
42
+ import { onSpinnerIntervalChange } from "../spinner-clock";
41
43
  import type { Terminal } from "../terminal";
42
44
  import { getCurrentThemeName, isLightTheme, setNativeSymbolPreset } from "../theme/theme";
43
45
  import type { Component, OverlayOptions, RenderScheduler, RenderTimer } from "../tui";
@@ -45,10 +47,15 @@ import { TspDocument } from "./apply";
45
47
  import { getNativeBlob, type NativeBlob } from "./blobs";
46
48
  import { node } from "./describe";
47
49
  import { encodeTspJson, encodeTspMessage, type TspHello, TspReader, splitTspMessage } from "./encode";
50
+ import { estimateRows } from "./measure";
48
51
  import type { DescribeContext, NativeChild, NativeNode, NativeSurface, NativeUiEvent } from "./node";
49
52
  import { NARROW_SHEET_COLS } from "./overlay";
53
+ import { resetQuietMotion } from "./quiet";
50
54
  import { nativeComponentId, Reconciler } from "./reconcile";
51
- import { setNativeButtons, setNativeRendering } from "./state";
55
+ import { setNativeButtons, setNativePacing, setNativeRendering } from "./state";
56
+
57
+ /** Share of the viewport's rows a centered sheet's content must reach to fill a narrow pane. */
58
+ const SHEET_FILL_FRACTION = 0.5;
52
59
 
53
60
  /** A visible TUI overlay, bottom to top. */
54
61
  export interface NativeOverlay {
@@ -200,9 +207,9 @@ function sameSet(a: ReadonlySet<string>, b: ReadonlySet<string>): boolean {
200
207
  * once the real `hello` lists them, so the optimistic start never emits a node
201
208
  * an older terminal cannot draw (`media`: files Tern loads by path; `json`:
202
209
  * raw JSON values Tern draws as its own tree; `button`: omp's buttons, which
203
- * older builds get as role-styled rows).
210
+ * older builds get as role-styled rows; `shell`: the bash tool's live trace).
204
211
  */
205
- const UNASSUMED_KINDS: Partial<Record<TspKind, true>> = { media: true, json: true, button: true };
212
+ const UNASSUMED_KINDS: Partial<Record<TspKind, true>> = { media: true, json: true, button: true, shell: true };
206
213
 
207
214
  /**
208
215
  * The reply a v1 terminal is assumed to give before its real `hello` arrives
@@ -307,6 +314,8 @@ export class NativeBackend {
307
314
  #sawResize = false;
308
315
  #live = false;
309
316
  #overlayNodes = new Map<Component, { key: string; node: NativeNode }>();
317
+ /** Centered sheets measured tall enough to fill a narrow pane; they keep filling until closed. */
318
+ #fillingSheets = new Set<Component>();
310
319
  /** Pending delivery owns bytes until sent or confirmed held; settled descriptions may already be released. */
311
320
  #blobs = new Map<string, NativeBlob | "sent">();
312
321
  /** `blobs` queries sent, oldest first: the terminal answers each once, in order. */
@@ -315,6 +324,7 @@ export class NativeBackend {
315
324
  #askHeld = true;
316
325
  /** Bumped when the connection resets or stops, so blob cache writes finishing later are dropped. */
317
326
  #blobEpoch = 0;
327
+ #unbindMotion: (() => void) | undefined;
318
328
 
319
329
  constructor(host: NativeHost, hello: TspHello, options: NativeBackendOptions = {}) {
320
330
  this.#host = host;
@@ -355,11 +365,28 @@ export class NativeBackend {
355
365
  if (this.#live) return;
356
366
  this.#live = true;
357
367
  this.#useNerdSymbols(true);
368
+ this.#watchMotion();
358
369
  this.#open(this.#inline);
359
370
  setNativeRendering(true);
360
371
  this.render();
361
372
  }
362
373
 
374
+ /** The terminal clocks spinners and span effects itself, so a motion change re-describes every component. */
375
+ #watchMotion(): void {
376
+ this.#unbindMotion?.();
377
+ const changed = () => {
378
+ resetQuietMotion();
379
+ this.#host.invalidate();
380
+ this.#host.requestRender();
381
+ };
382
+ const unbindSpinner = onSpinnerIntervalChange(changed);
383
+ const unbindEffects = onMotionEffectsChange(changed);
384
+ this.#unbindMotion = () => {
385
+ unbindSpinner();
386
+ unbindEffects();
387
+ };
388
+ }
389
+
363
390
  /**
364
391
  * Tern's font carries every Nerd Font glyph, and it never answers the Glyph
365
392
  * Protocol, so icons come from the nerd preset (process-local, not the
@@ -382,6 +409,9 @@ export class NativeBackend {
382
409
  this.#inline.doc?.close();
383
410
  setNativeRendering(false);
384
411
  setNativeButtons(false);
412
+ setNativePacing(false);
413
+ this.#unbindMotion?.();
414
+ this.#unbindMotion = undefined;
385
415
  this.#useNerdSymbols(false);
386
416
  this.#clearStallTimer();
387
417
  // Replies no longer reach the backend: forget the queries outright.
@@ -401,6 +431,7 @@ export class NativeBackend {
401
431
  this.#live = true;
402
432
  this.#useNerdSymbols(true);
403
433
  this.#resetBlobs();
434
+ this.#watchMotion();
404
435
  const surface = this.#inline;
405
436
  surface.reconciler.detachLive();
406
437
  surface.unacked = [];
@@ -508,6 +539,7 @@ export class NativeBackend {
508
539
  if (this.#stats) {
509
540
  logger.debug("TSP frame", { sf: surface.id, ops: ops.length, rows: surface.reconciler.fallbackCount });
510
541
  }
542
+ this.#measureSheets(surface, overlays);
511
543
  if (ops.length === 0) return;
512
544
  this.#uploadBlobs(ops);
513
545
  this.#sendFrame(surface, ops);
@@ -543,6 +575,7 @@ export class NativeBackend {
543
575
  this.#cx = new NativeContext(hello, hello.cols ?? this.#cx.cols);
544
576
  // A changed vocabulary re-describes every component (`confirm`).
545
577
  setNativeButtons(this.#cx.supports("button"));
578
+ setNativePacing(this.#cx.feature("pace"));
546
579
  this.#sawResize = false;
547
580
  }
548
581
 
@@ -884,9 +917,7 @@ export class NativeBackend {
884
917
  const own = overlay.component.nativeOverlay;
885
918
  const anchor = own?.anchor ?? overlayAnchor(overlay.options);
886
919
  let size = own?.size ?? overlaySize(overlay.options, this.#cx.cols);
887
- // A centered sheet in a narrow pane fills it instead of floating with margins: `lg`, and a component's own `md`
888
- // sheet (an undeclared `md` is a generic dialog sized from its options).
889
- if (anchor === "center" && this.#cx.cols < NARROW_SHEET_COLS && (size === "lg" || own?.size === "md")) {
920
+ if (anchor === "center" && this.#cx.cols < NARROW_SHEET_COLS && this.#fillingSheets.has(overlay.component)) {
890
921
  size = "full";
891
922
  }
892
923
  const modal = overlay.focused || overlay.options?.fullscreen === true;
@@ -905,9 +936,37 @@ export class NativeBackend {
905
936
  return wrapper;
906
937
  }
907
938
 
939
+ /**
940
+ * A narrow pane has no room for a floating sheet with margins, but a sheet
941
+ * stretched over content a few lines tall is mostly empty. The terminal lays
942
+ * the content out, so estimate its rows from what was just described: a
943
+ * centered sheet whose content reaches {@link SHEET_FILL_FRACTION} of the
944
+ * viewport fills the pane from the next frame on, and keeps filling while it
945
+ * stays open so a filter or a reload never makes it jump between sizes.
946
+ */
947
+ #measureSheets(surface: Surface, overlays: readonly NativeOverlay[]): void {
948
+ const cols = this.#cx.cols;
949
+ if (cols >= NARROW_SHEET_COLS) return;
950
+ const limit = Math.max(1, Math.ceil(this.#host.terminal.rows * SHEET_FILL_FRACTION));
951
+ let grew = false;
952
+ for (const { component, options } of overlays) {
953
+ if (this.#fillingSheets.has(component) || component.nativeSheet?.(this.#cx)) continue;
954
+ if ((component.nativeOverlay?.anchor ?? overlayAnchor(options)) !== "center") continue;
955
+ const rows = estimateRows(component, cols, limit, child => surface.reconciler.described(child));
956
+ if (rows < limit) continue;
957
+ this.#fillingSheets.add(component);
958
+ grew = true;
959
+ }
960
+ if (grew) this.#host.requestRender();
961
+ }
962
+
908
963
  #pruneOverlayNodes(overlays: readonly NativeOverlay[]): void {
909
964
  if (this.#overlayNodes.size <= overlays.length) return;
910
965
  const live = new Set(overlays.map(overlay => overlay.component));
911
- for (const component of this.#overlayNodes.keys()) if (!live.has(component)) this.#overlayNodes.delete(component);
966
+ for (const component of this.#overlayNodes.keys()) {
967
+ if (live.has(component)) continue;
968
+ this.#overlayNodes.delete(component);
969
+ this.#fillingSheets.delete(component);
970
+ }
912
971
  }
913
972
  }
@@ -1,6 +1,8 @@
1
1
  import { type TspEvent, type TspReply, type TspVerb } from "@linxiraos/pi-wire";
2
2
  /** Every TSP message starts with this. */
3
3
  export declare const TSP_PREFIX = "\u001B_tsp;";
4
+ /** TSP input framing through ConPTY, whose input parser discards APC. */
5
+ export declare const TSP_OSC_PREFIX = "\u001B]877;tsp;";
4
6
  /** The terminal's hello reply. */
5
7
  export type TspHello = Extract<TspReply, {
6
8
  r: "hello";
@@ -24,6 +24,8 @@ const APC = "\x1b_";
24
24
  const ST = "\x1b\\";
25
25
  /** Every TSP message starts with this. */
26
26
  export const TSP_PREFIX = `${APC}${TSP_APC_ID};`;
27
+ /** TSP input framing through ConPTY, whose input parser discards APC. */
28
+ export const TSP_OSC_PREFIX = `\x1b]877;${TSP_APC_ID};`;
27
29
 
28
30
  /** The terminal's hello reply. */
29
31
  export type TspHello = Extract<TspReply, { r: "hello" }>;
@@ -0,0 +1,10 @@
1
+ import type { Component } from "../tui";
2
+ import type { NativeChild, NativeNode } from "./node";
3
+ /** The last description of a component, or undefined when unknown. */
4
+ export type DescribedOf = (component: Component) => NativeNode | undefined;
5
+ /**
6
+ * Estimated rows of `root` at `cols` cells wide, stopping once `limit` is
7
+ * reached (the result never exceeds it). Component children are measured
8
+ * through `described`.
9
+ */
10
+ export declare function estimateRows(root: NativeChild, cols: number, limit: number, described: DescribedOf): number;
@@ -0,0 +1,185 @@
1
+ /**
2
+ * A rough lower bound on how many terminal rows a described subtree takes,
3
+ * for layout decisions the program must make before the terminal lays the
4
+ * content out (whether a sheet fills a narrow pane). Counts cell lines at the
5
+ * surface width; the terminal's own fonts and padding differ, so callers
6
+ * compare against a fraction of the viewport, not an exact fit.
7
+ */
8
+ import type { TspExtent, TspText, TspTreeNode } from "@linxiraos/pi-wire";
9
+ import type { Component } from "../tui";
10
+ import type { NativeChild, NativeNode } from "./node";
11
+
12
+ /** The last description of a component, or undefined when unknown. */
13
+ export type DescribedOf = (component: Component) => NativeNode | undefined;
14
+
15
+ /** Leaf images, media and charts: a fixed guess, since their height is the terminal's choice. */
16
+ const GRAPHIC_ROWS = 8;
17
+ /** Nesting deeper than this is not measured (cyclic or runaway descriptions). */
18
+ const MAX_DEPTH = 64;
19
+
20
+ /**
21
+ * Estimated rows of `root` at `cols` cells wide, stopping once `limit` is
22
+ * reached (the result never exceeds it). Component children are measured
23
+ * through `described`.
24
+ */
25
+ export function estimateRows(root: NativeChild, cols: number, limit: number, described: DescribedOf): number {
26
+ return new RowEstimator(Math.max(1, cols), described).measure(root, limit, 0);
27
+ }
28
+
29
+ class RowEstimator {
30
+ constructor(
31
+ readonly cols: number,
32
+ readonly described: DescribedOf,
33
+ ) {}
34
+
35
+ measure(child: NativeChild, cap: number, depth: number): number {
36
+ if (cap <= 0 || depth > MAX_DEPTH) return 0;
37
+ const node = isNode(child) ? child : this.described(child);
38
+ if (!node) return 0;
39
+ if (node.k === "chart") return Math.min(cap, GRAPHIC_ROWS);
40
+ const p = node.p;
41
+ if (p?.hidden) return 0;
42
+ const max = linesExtent(p?.max?.h);
43
+ const own = this.#kindRows(node, max === undefined ? cap : Math.min(cap, max), depth);
44
+ return Math.min(cap, Math.max(own, linesExtent(p?.min?.h) ?? 0));
45
+ }
46
+
47
+ #sum(children: readonly NativeChild[] | undefined, cap: number, depth: number): number {
48
+ let rows = 0;
49
+ for (const child of children ?? []) {
50
+ if (rows >= cap) break;
51
+ rows += this.measure(child, cap - rows, depth + 1);
52
+ }
53
+ return rows;
54
+ }
55
+
56
+ #tallest(children: readonly NativeChild[] | undefined, cap: number, depth: number): number {
57
+ let rows = 0;
58
+ for (const child of children ?? []) rows = Math.max(rows, this.measure(child, cap, depth + 1));
59
+ return rows;
60
+ }
61
+
62
+ /** Rows of `text`, one per line, or wrapped at the surface width. */
63
+ #textRows(text: string | undefined, wrap: boolean, cap: number): number {
64
+ if (!text) return 0;
65
+ let rows = 0;
66
+ let start = 0;
67
+ while (rows < cap) {
68
+ const end = text.indexOf("\n", start);
69
+ const line = end === -1 ? text.slice(start) : text.slice(start, end);
70
+ rows += wrap ? Math.max(1, Math.ceil(Bun.stringWidth(line) / this.cols)) : 1;
71
+ if (end === -1) break;
72
+ start = end + 1;
73
+ }
74
+ return Math.min(rows, cap);
75
+ }
76
+
77
+ #kindRows(node: NativeNode, cap: number, depth: number): number {
78
+ switch (node.k) {
79
+ // Scrollers of their own: they take whatever height they get.
80
+ case "picker":
81
+ case "prefs":
82
+ return cap;
83
+ case "row":
84
+ return this.#tallest(node.c, cap, depth);
85
+ case "tabs":
86
+ // One page shows at a time: the tab strip, then the tallest page.
87
+ return 1 + this.#tallest(node.c, cap - 1, depth);
88
+ case "card":
89
+ case "section": {
90
+ const head = node.p?.head === undefined ? 0 : 1;
91
+ const body = this.#sum(node.c, cap - head, depth);
92
+ if (!node.p?.collapsed) return head + body;
93
+ const preview = node.k === "card" && typeof node.p.preview === "object" ? node.p.preview.lines : 0;
94
+ return head + Math.min(preview, body);
95
+ }
96
+ case "text": {
97
+ const p = node.p;
98
+ const text = p?.text ?? p?.spans?.map(run => run.t).join("");
99
+ return this.#textRows(
100
+ text,
101
+ p?.wrap !== "none" && p?.truncate === undefined,
102
+ Math.min(cap, p?.lines ?? cap),
103
+ );
104
+ }
105
+ case "md":
106
+ case "editor":
107
+ case "input":
108
+ return this.#textRows(node.p?.text, true, cap);
109
+ case "code":
110
+ case "diff":
111
+ return this.#textRows(node.p?.text, false, cap);
112
+ case "ansi": {
113
+ if (node.p?.follow) return cap;
114
+ const preview = typeof node.p?.preview === "object" ? node.p.preview.lines : cap;
115
+ return this.#textRows(node.p?.text, false, Math.min(cap, preview));
116
+ }
117
+ case "rows":
118
+ return Math.min(cap, node.p?.lines.length ?? 0);
119
+ case "kv":
120
+ return Math.min(cap, node.p?.items.length ?? 0);
121
+ case "table":
122
+ return Math.min(cap, 1 + (node.p?.rows.length ?? 0));
123
+ case "tree":
124
+ return treeRows(node.p?.nodes, cap);
125
+ case "json":
126
+ return Math.min(cap, jsonRows(node.p?.value, cap));
127
+ case "checklist": {
128
+ let rows = 0;
129
+ for (const phase of node.p?.phases ?? []) rows += 1 + (phase.collapsed ? 0 : phase.items.length);
130
+ return Math.min(cap, rows);
131
+ }
132
+ case "list": {
133
+ const max = node.p?.max;
134
+ return this.#sum(node.c, Math.min(cap, typeof max === "number" ? max : (max?.lines ?? cap)), depth);
135
+ }
136
+ case "item":
137
+ return (hasText(node.p?.detail) ? 2 : 1) + this.#sum(node.c, cap, depth);
138
+ case "image":
139
+ case "media":
140
+ return Math.min(cap, GRAPHIC_ROWS);
141
+ case "tool":
142
+ case "agent":
143
+ return 1 + this.#sum(node.c, cap - 1, depth);
144
+ default:
145
+ // Containers stack their children; leaves (badges, keys, buttons, meters) take a row.
146
+ return node.c && node.c.length > 0 ? this.#sum(node.c, cap, depth) : 1;
147
+ }
148
+ }
149
+ }
150
+
151
+ function isNode(child: NativeChild): child is NativeNode {
152
+ return typeof (child as Partial<NativeNode>).k === "string";
153
+ }
154
+
155
+ function hasText(text: TspText | undefined): boolean {
156
+ return typeof text === "string" ? text.length > 0 : text !== undefined && text.some(run => run.t.length > 0);
157
+ }
158
+
159
+ /** A `Nlines` extent as a row count; fractions and widths say nothing about rows. */
160
+ function linesExtent(extent: TspExtent | undefined): number | undefined {
161
+ if (typeof extent !== "string" || !extent.endsWith("lines")) return undefined;
162
+ const lines = Number.parseFloat(extent);
163
+ return Number.isFinite(lines) ? lines : undefined;
164
+ }
165
+
166
+ function treeRows(nodes: readonly TspTreeNode[] | undefined, cap: number): number {
167
+ let rows = 0;
168
+ for (const node of nodes ?? []) {
169
+ if (rows >= cap) break;
170
+ rows += 1;
171
+ if (node.open && node.children) rows += treeRows(node.children, cap - rows);
172
+ }
173
+ return Math.min(rows, cap);
174
+ }
175
+
176
+ /** Rows of `value` pretty-printed one entry per line. */
177
+ function jsonRows(value: unknown, cap: number): number {
178
+ if (value === null || typeof value !== "object") return 1;
179
+ let rows = 2;
180
+ for (const entry of Array.isArray(value) ? value : Object.values(value)) {
181
+ if (rows >= cap) break;
182
+ rows += jsonRows(entry, cap - rows);
183
+ }
184
+ return rows;
185
+ }
@@ -10,7 +10,7 @@ import type { TspProps, TspSpan, TspText } from "@linxiraos/pi-wire";
10
10
  import { type KeyName } from "../key-hint-format";
11
11
  import { type Keybinding } from "../keybindings";
12
12
  import type { NativeChild, NativeNode } from "./node";
13
- /** Below this many columns a centered sheet fills the pane instead of floating with margins. */
13
+ /** Below this many columns a centered sheet with tall content fills the pane instead of floating with margins. */
14
14
  export declare const NARROW_SHEET_COLS = 100;
15
15
  /** One footer hint: the keys that trigger it and what it does. */
16
16
  export interface NativeHint {
@@ -13,7 +13,7 @@ import { card, kbd, keyNames, list, node, row, span, text } from "./describe";
13
13
  import type { NativeChild, NativeNode } from "./node";
14
14
  import { nativeButtons } from "./state";
15
15
 
16
- /** Below this many columns a centered sheet fills the pane instead of floating with margins. */
16
+ /** Below this many columns a centered sheet with tall content fills the pane instead of floating with margins. */
17
17
  export const NARROW_SHEET_COLS = 100;
18
18
 
19
19
  /** One footer hint: the keys that trigger it and what it does. */
@@ -0,0 +1,5 @@
1
+ import type { NativeNode } from "./node";
2
+ /** Forget cached translations; the backend calls this when a motion switch flips, then re-describes. */
3
+ export declare function resetQuietMotion(): void;
4
+ /** `node` as described, or with its terminal-clocked animations stilled per the motion switches. */
5
+ export declare function quietMotion(node: NativeNode): NativeNode;
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Describe-time gate for the animations a TSP terminal clocks itself. The protocol has no "static
3
+ * spinner" or "no effects" knob, so `tui.motion` is honoured on the way to the wire: with static
4
+ * spinners a `spinner` node becomes its frame-0 glyph (label and common props kept), and with
5
+ * decorative motion off every `fx` is dropped. Untouched subtrees keep their identity (the reconciler
6
+ * memoizes on it); translations are cached per described node until a switch changes.
7
+ */
8
+ import type { TspSpan, TspSpinnerProps, TspText } from "@linxiraos/pi-wire";
9
+ import { motionEffectsEnabled } from "../motion-effects";
10
+ import { spinnerAnimated } from "../spinner-clock";
11
+ import type { NativeChild, NativeNode } from "./node";
12
+
13
+ let cache = new WeakMap<NativeNode, NativeNode>();
14
+
15
+ /** Forget cached translations; the backend calls this when a motion switch flips, then re-describes. */
16
+ export function resetQuietMotion(): void {
17
+ cache = new WeakMap();
18
+ }
19
+
20
+ /** `node` as described, or with its terminal-clocked animations stilled per the motion switches. */
21
+ export function quietMotion(node: NativeNode): NativeNode {
22
+ const stillSpinners = !spinnerAnimated();
23
+ const noEffects = !motionEffectsEnabled();
24
+ if (!stillSpinners && !noEffects) return node;
25
+ const hit = cache.get(node);
26
+ if (hit) return hit;
27
+ const out = quiet(node, stillSpinners, noEffects);
28
+ cache.set(node, out);
29
+ return out;
30
+ }
31
+
32
+ function quiet(node: NativeNode, stillSpinners: boolean, noEffects: boolean): NativeNode {
33
+ const props = node.p as Readonly<Record<string, unknown>> | undefined;
34
+ const quietProps = noEffects && props ? (withoutEffects(props) as Readonly<Record<string, unknown>>) : props;
35
+ const children = node.c ? quietChildren(node.c, stillSpinners, noEffects) : undefined;
36
+ if (stillSpinners && node.k === "spinner") return stillSpinner(node, quietProps);
37
+ if (quietProps === props && children === node.c) return node;
38
+ return { ...node, p: quietProps, c: children } as NativeNode;
39
+ }
40
+
41
+ function quietChildren(
42
+ children: readonly NativeChild[],
43
+ stillSpinners: boolean,
44
+ noEffects: boolean,
45
+ ): readonly NativeChild[] {
46
+ let out: NativeChild[] | undefined;
47
+ for (let i = 0; i < children.length; i++) {
48
+ const child = children[i]!;
49
+ // Components are described (and stilled) on their own when the reconciler resolves them.
50
+ if (typeof (child as { render?: unknown }).render === "function") continue;
51
+ const next = quiet(child as NativeNode, stillSpinners, noEffects);
52
+ if (next !== child) (out ??= children.slice())[i] = next;
53
+ }
54
+ return out ?? children;
55
+ }
56
+
57
+ /**
58
+ * A `spinner` as the static text it would show at frame 0: glyph, then its label, under its common
59
+ * props. Starburst's first facet matches the ANSI thinking pulse's frame 0; every other style shows
60
+ * the braille frame 0 the ANSI spinners pin to.
61
+ */
62
+ function stillSpinner(node: NativeNode, props: Readonly<Record<string, unknown>> | undefined): NativeNode {
63
+ const { style, label, ...common } = (props ?? {}) as TspSpinnerProps & { label?: TspText };
64
+ const spans: TspSpan[] = [{ t: style === "starburst" ? "✻" : "⠋" }];
65
+ if (typeof label === "string") {
66
+ if (label.length > 0) spans.push({ t: ` ${label}` });
67
+ } else if (label && label.length > 0) {
68
+ spans.push({ t: " " }, ...label);
69
+ }
70
+ return { ...node, k: "text", p: { ...common, spans }, c: undefined } as unknown as NativeNode;
71
+ }
72
+
73
+ /**
74
+ * `value` with `fx` removed from every plain object carrying one — spans in any `TspText`, editor
75
+ * decorations, whatever a future prop nests — walking arrays and plain objects alike. Copy-on-write:
76
+ * the same reference comes back when nothing below it had an effect.
77
+ */
78
+ function withoutEffects(value: unknown): unknown {
79
+ if (Array.isArray(value)) {
80
+ let out: unknown[] | undefined;
81
+ for (let i = 0; i < value.length; i++) {
82
+ const next = withoutEffects(value[i]);
83
+ if (next !== value[i]) (out ??= value.slice())[i] = next;
84
+ }
85
+ return out ?? value;
86
+ }
87
+ if (!isPlainObject(value)) return value;
88
+ let out: Record<string, unknown> | undefined;
89
+ for (const key in value) {
90
+ if (key === "fx") {
91
+ out ??= { ...value };
92
+ delete out.fx;
93
+ continue;
94
+ }
95
+ const next = withoutEffects(value[key]);
96
+ if (next !== value[key]) (out ??= { ...value })[key] = next;
97
+ }
98
+ return out ?? value;
99
+ }
100
+
101
+ function isPlainObject(value: unknown): value is Record<string, unknown> {
102
+ if (typeof value !== "object" || value === null) return false;
103
+ const proto = Object.getPrototypeOf(value);
104
+ return proto === Object.prototype || proto === null;
105
+ }
@@ -1,6 +1,6 @@
1
1
  import { type TspOp } from "@linxiraos/pi-wire";
2
2
  import { type Component } from "../tui";
3
- import type { DescribeContext, NativeChild } from "./node";
3
+ import type { DescribeContext, NativeChild, NativeNode } from "./node";
4
4
  /** The regions a frame fills. */
5
5
  export interface NativeRegions {
6
6
  readonly main: readonly NativeChild[];
@@ -41,6 +41,11 @@ export declare class Reconciler {
41
41
  itemKey(id: string): string;
42
42
  /** Wire id of the first `editor`/`input` `component` describes (for `focus`), or null. */
43
43
  focusTarget(component: Component): string | null;
44
+ /**
45
+ * The last description of `component` on this surface (a settled one only
46
+ * while still referenced elsewhere), or undefined when it isn't mounted.
47
+ */
48
+ described(component: Component): NativeNode | undefined;
44
49
  /** Stop referencing ids the terminal dropped (`gone`). */
45
50
  forget(ids: readonly string[]): void;
46
51
  }
@@ -29,10 +29,11 @@
29
29
  */
30
30
  import * as logger from "@linxiraos/pi-utils/logger";
31
31
  import { TSP_TEXT_KINDS, type TspKind, type TspNode, type TspOp, type TspScrollBy } from "@linxiraos/pi-wire";
32
- import { type Component, Container, CURSOR_MARKER } from "../tui";
32
+ import { type Component, CURSOR_MARKER, ownDescription } from "../tui";
33
33
  import { getNativeBlob } from "./blobs";
34
34
  import { normalizeIconProps } from "./icons";
35
35
  import type { DescribeContext, NativeChild, NativeNode, NativeRevealAt } from "./node";
36
+ import { quietMotion } from "./quiet";
36
37
  import { isNativeSettled } from "./settle";
37
38
 
38
39
  /** The regions a frame fills. */
@@ -377,6 +378,18 @@ export class Reconciler {
377
378
  return state ? this.#findEditor(state, 0) : null;
378
379
  }
379
380
 
381
+ /**
382
+ * The last description of `component` on this surface (a settled one only
383
+ * while still referenced elsewhere), or undefined when it isn't mounted.
384
+ */
385
+ described(component: Component): NativeNode | undefined {
386
+ const state = this.#states.get(component);
387
+ if (!state) return undefined;
388
+ const node = state.node ?? (state.weak?.deref() as NativeNode | readonly string[] | undefined);
389
+ // A settled `rows` fallback is held by its lines; its node is kept beside them.
390
+ return Array.isArray(node) ? (state.rowsNode ?? undefined) : (node as NativeNode | undefined);
391
+ }
392
+
380
393
  /** Stop referencing ids the terminal dropped (`gone`). */
381
394
  forget(ids: readonly string[]): void {
382
395
  for (const id of ids) this.#gone.add(id);
@@ -927,15 +940,8 @@ export class Reconciler {
927
940
  /** The component's description, or a `rows` node rendered at `cx.cols`. */
928
941
  #resolve(state: CompState): NativeNode {
929
942
  const comp = state.comp;
930
- const describe = comp.describe;
931
- // A Container subclass that paints its own rows but inherits the plain
932
- // column description would lose its rendering: fall back to rows.
933
- // (Read lazily: this module and tui.ts import each other.)
934
- const inherited = describe === Container.prototype.describe && comp.render !== Container.prototype.render;
935
- if (describe && !inherited) {
936
- const node = describe.call(comp, this.#cx!);
937
- if (node) return node;
938
- }
943
+ const node = ownDescription(comp, this.#cx!);
944
+ if (node) return quietMotion(node);
939
945
  this.#rows++;
940
946
  const cols = Math.max(1, this.#cx!.cols);
941
947
  const lines = comp.render(cols);
@@ -17,5 +17,11 @@ export declare function styleSpans(content: string, style?: (text: string) => st
17
17
  export declare function compactText(spans: readonly TspSpan[]): TspText;
18
18
  /** Pre-rendered ANSI rows as one unwrapped text block (rows already carry their line breaks). */
19
19
  export declare function rowsText(lines: readonly string[]): NativeNode;
20
+ /**
21
+ * Styled text as one ANSI terminal line: the reverse of {@link styledSpans}. Each span takes the
22
+ * last theme colour (or semantic colour token) in `s`, bold for `strong` and italic for `em`; text
23
+ * is sanitized like {@link plainText} and line breaks become spaces.
24
+ */
25
+ export declare function spansLine(content: TspText): string;
20
26
  /** Theme background token of the first SGR background in ANSI-styled text. */
21
27
  export declare function styledBackground(styled: string): ThemeBg | undefined;
@@ -293,6 +293,46 @@ export function rowsText(lines: readonly string[]): NativeNode {
293
293
  return text(compactText(styledSpans(lines.join("\n"))), { wrap: "none" });
294
294
  }
295
295
 
296
+ /** Semantic span tokens drawn with the theme colour that stands for them in the terminal. */
297
+ const SEMANTIC_FG: Readonly<Record<string, ThemeColor>> = {
298
+ info: "accent",
299
+ link: "mdLink",
300
+ code: "mdCode",
301
+ mono: "mdCode",
302
+ path: "accent",
303
+ num: "accent",
304
+ ins: "toolDiffAdded",
305
+ del: "toolDiffRemoved",
306
+ };
307
+
308
+ /**
309
+ * Styled text as one ANSI terminal line: the reverse of {@link styledSpans}. Each span takes the
310
+ * last theme colour (or semantic colour token) in `s`, bold for `strong` and italic for `em`; text
311
+ * is sanitized like {@link plainText} and line breaks become spaces.
312
+ */
313
+ export function spansLine(content: TspText): string {
314
+ if (typeof content === "string") return plainLine(content);
315
+ let out = "";
316
+ for (const part of content) {
317
+ let value = clean(part.t).replace(/[\r\n]+/g, " ");
318
+ if (!value) continue;
319
+ let color: ThemeColor | undefined;
320
+ let bold = false;
321
+ let italic = false;
322
+ for (const token of part.s?.split(" ") ?? []) {
323
+ if (token === "strong") bold = true;
324
+ else if (token === "em") italic = true;
325
+ else if (isValidThemeColor(token)) color = token;
326
+ else if (SEMANTIC_FG[token] !== undefined) color = SEMANTIC_FG[token];
327
+ }
328
+ if (color !== undefined) value = theme.fg(color, value);
329
+ if (bold) value = theme.bold(value);
330
+ if (italic) value = theme.italic(value);
331
+ out += value;
332
+ }
333
+ return out;
334
+ }
335
+
296
336
  /** Theme background token of the first SGR background in ANSI-styled text. */
297
337
  export function styledBackground(styled: string): ThemeBg | undefined {
298
338
  const reverse = activeReverse();