@xynogen/pix-pretty 3.0.1 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xynogen/pix-pretty",
3
- "version": "3.0.1",
3
+ "version": "3.1.0",
4
4
  "description": "Enhanced tool output rendering with syntax highlighting, file icons, tree views, diff rendering, and FFF search",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -17,6 +17,7 @@
17
17
  "./diff-render": "./src/diff-render.ts",
18
18
  "./highlight": "./src/highlight.ts",
19
19
  "./lang": "./src/lang.ts",
20
+ "./markdown-transform": "./src/markdown-transform.ts",
20
21
  "./icons": "./src/icons.ts",
21
22
  "./icon-catalog": "./src/icon-catalog.ts",
22
23
  "./icon-persist": "./src/icon-persist.ts",
@@ -76,7 +77,7 @@
76
77
  "access": "public"
77
78
  },
78
79
  "dependencies": {
79
- "@xynogen/pix-runtime": "^0.22.0",
80
+ "@xynogen/pix-runtime": "^0.22.4",
80
81
  "chalk": "^4.1.2",
81
82
  "cli-highlight": "^2.1.11",
82
83
  "@ff-labs/fff-node": "^0.10.6",
package/src/ansi.ts CHANGED
@@ -32,6 +32,35 @@ export function hasAnsi(s: string): boolean {
32
32
  return s.includes(ESC);
33
33
  }
34
34
 
35
+ /**
36
+ * Re-open `bgOpen`/`fgOpen` after every reset inside `s`: `\x1b[0m` clears both, `49`
37
+ * clears the background, `39` the foreground. Keeps a panel color solid behind
38
+ * embedded content that ends its own styles with a full reset.
39
+ */
40
+ export function reopenAfterResets(s: string, bgOpen: string, fgOpen = ""): string {
41
+ if (!bgOpen && !fgOpen) return s;
42
+ return s.replace(ANSI_CAPTURE_RE, (seq, params: string) => {
43
+ let bgReset = false;
44
+ let fgReset = false;
45
+ const codes = params === "" ? [0] : params.split(";").map(Number);
46
+ for (let i = 0; i < codes.length; i++) {
47
+ const code = codes[i];
48
+ // 38/48 carry color arguments (`5;n` or `2;r;g;b`); a 49 there is not a reset.
49
+ if (code === 38 || code === 48) i += codes[i + 1] === 5 ? 2 : 4;
50
+ else if (code === 0) bgReset = fgReset = true;
51
+ else if (code === 49) bgReset = true;
52
+ else if (code === 39) fgReset = true;
53
+ }
54
+ return `${seq}${bgReset ? bgOpen : ""}${fgReset ? fgOpen : ""}`;
55
+ });
56
+ }
57
+
58
+ /** A `Box` background function that stays solid behind content with embedded resets. */
59
+ export function solidBackground(bg: (text: string) => string): (text: string) => string {
60
+ const bgOpen = bg("\x00").split("\x00")[0] ?? "";
61
+ return (text) => bg(reopenAfterResets(text, bgOpen));
62
+ }
63
+
35
64
  // ---------------------------------------------------------------------------
36
65
  // Low-contrast fix (same as pi-diff)
37
66
  // ---------------------------------------------------------------------------
@@ -43,9 +43,9 @@ export function commandPreview(
43
43
  let replacement: string | undefined;
44
44
  const text = new Text("", 0, 0);
45
45
  let memo:
46
- | { width: number; styled: string; replacement: string | undefined; lines: string[] }
46
+ | { width: number; styled: string; replacement: string | undefined; lines: readonly string[] }
47
47
  | undefined;
48
- const layout = (width: number): string[] => {
48
+ const layout = (width: number): readonly string[] => {
49
49
  if (replacement !== undefined) {
50
50
  text.setText(replacement);
51
51
  return replacement ? text.render(width) : [];
@@ -78,7 +78,7 @@ export function commandPreview(
78
78
  memo = undefined;
79
79
  text.invalidate();
80
80
  },
81
- render(width: number): string[] {
81
+ render(width: number): readonly string[] {
82
82
  if (
83
83
  memo?.width === width &&
84
84
  memo.styled === current.styled &&
@@ -102,7 +102,9 @@ export function collapsedCommandRow(
102
102
  let text = `${prefix}${theme.fg("dim", plain)}`;
103
103
  let replaced = false;
104
104
  const replacementText = new Text("", 0, 0);
105
- let memo: { width: number; text: string; replaced: boolean; lines: string[] } | undefined;
105
+ let memo:
106
+ | { width: number; text: string; replaced: boolean; lines: readonly string[] }
107
+ | undefined;
106
108
  return {
107
109
  setText(value: string) {
108
110
  text = value;
@@ -113,7 +115,7 @@ export function collapsedCommandRow(
113
115
  memo = undefined;
114
116
  replacementText.invalidate();
115
117
  },
116
- render(width: number): string[] {
118
+ render(width: number): readonly string[] {
117
119
  if (memo?.width === width && memo.text === text && memo.replaced === replaced)
118
120
  return memo.lines;
119
121
  if (replaced) {
package/src/confirm.ts CHANGED
@@ -26,7 +26,7 @@ interface CustomTheme {
26
26
  }
27
27
 
28
28
  interface CustomComponent {
29
- render(width: number): string[];
29
+ render(width: number): readonly string[];
30
30
  invalidate(): void;
31
31
  handleInput(data: string): void;
32
32
  focused?: boolean;
package/src/frame.ts CHANGED
@@ -6,7 +6,7 @@ import type { TextComponentCtor, TextComponentLike } from "./types.ts";
6
6
  import { terminalWidth } from "./utils.ts";
7
7
 
8
8
  type ResultComponent = {
9
- render(width: number): string[];
9
+ render(width: number): readonly string[];
10
10
  invalidate(): void;
11
11
  handleInput?(data: string): void;
12
12
  wantsKeyRelease?: boolean;
@@ -230,8 +230,8 @@ export function reuseText(
230
230
  * footer lines. Existing callers inherit this distro-wide presentation.
231
231
  */
232
232
  export function ruleFrame(
233
- bodyLines: string[],
234
- footerLines: string[] = [],
233
+ bodyLines: readonly string[],
234
+ footerLines: readonly string[] = [],
235
235
  width?: number,
236
236
  paint?: RulePaint,
237
237
  ): string[] {
@@ -265,8 +265,8 @@ export function outputBodyRows(
265
265
 
266
266
  /** Explicit solid top/bottom frame for sections that need stronger separation. */
267
267
  export function sectionFrame(
268
- bodyLines: string[],
269
- footerLines: string[] = [],
268
+ bodyLines: readonly string[],
269
+ footerLines: readonly string[] = [],
270
270
  width?: number,
271
271
  paint?: RulePaint,
272
272
  ): string[] {
@@ -112,7 +112,7 @@ interface OverlayTui {
112
112
  }
113
113
 
114
114
  interface OverlayComponent {
115
- render(width: number): string[];
115
+ render(width: number): readonly string[];
116
116
  invalidate(): void;
117
117
  handleInput(data: string): void;
118
118
  focused?: boolean;
package/src/index.ts CHANGED
@@ -15,10 +15,8 @@ import { fffState } from "./fff.ts";
15
15
  import { clearHighlightCache } from "./highlight.ts";
16
16
  import { initIconMode } from "./icon-persist.ts";
17
17
  import { installOrderedWidgets } from "./ordered-widgets.ts";
18
- import { installOverlayImages } from "./overlay-images.ts";
19
18
 
20
19
  export default function piPrettyExtension(pi: ExtensionAPI): void {
21
- installOverlayImages();
22
20
  once(pi, "pix-pretty-widgets", () => {
23
21
  let restore: (() => void) | undefined;
24
22
  pi.on("session_start", (_event, ctx) => {
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Display transform for Markdown that Pi does not pass through its transformer chain,
3
+ * such as cards drawn by entry renderers (`/btw`). pix-display registers the same
4
+ * pipeline it gives assistant replies; without it the Markdown stays as written.
5
+ * The slot lives on globalThis: Pi re-evaluates extension modules on reload.
6
+ */
7
+ export type MarkdownTransform = (markdown: string, availableWidth: number) => string;
8
+
9
+ const KEY = Symbol.for("@xynogen/pix-pretty:markdown-transform");
10
+ type Slot = { [KEY]?: MarkdownTransform };
11
+
12
+ export function setMarkdownTransform(transform: MarkdownTransform | undefined): void {
13
+ (globalThis as Slot)[KEY] = transform;
14
+ }
15
+
16
+ /** Pass as `Markdown`'s `transform` option. A throwing transform keeps the source, as Pi does. */
17
+ export function transformMarkdown(markdown: string, availableWidth: number): string {
18
+ try {
19
+ return (globalThis as Slot)[KEY]?.(markdown, availableWidth) ?? markdown;
20
+ } catch {
21
+ return markdown;
22
+ }
23
+ }
@@ -18,6 +18,7 @@ import {
18
18
  } from "@earendil-works/pi-tui";
19
19
  import { config } from "@xynogen/pix-runtime/config";
20
20
  import { prettySection, type RenderSize } from "@xynogen/pix-runtime/sections";
21
+ import { reopenAfterResets } from "./ansi.ts";
21
22
 
22
23
  export { truncateToWidth, visibleWidth, wrapTextWithAnsi };
23
24
 
@@ -174,7 +175,11 @@ export interface JoinColumnsOptions {
174
175
  * padded with blanks. Pure: no wrapping, no color; callers style the cells and
175
176
  * the optional `sep`.
176
177
  */
177
- export function joinColumns(left: string[], right: string[], opts: JoinColumnsOptions): string[] {
178
+ export function joinColumns(
179
+ left: readonly string[],
180
+ right: readonly string[],
181
+ opts: JoinColumnsOptions,
182
+ ): string[] {
178
183
  const divider = opts.sep ?? " ".repeat(Math.max(0, opts.gap ?? 2));
179
184
  const height = Math.max(left.length, right.length);
180
185
  const rows: string[] = [];
@@ -229,24 +234,12 @@ export function frameLines(opts: FrameOptions): string[] {
229
234
  // Expand before framing so a long command wraps instead of losing its tail.
230
235
  const { rows: lines } = fitModalLines(opts.lines, inner, wrap);
231
236
 
232
- // Derive the OPEN sequences so we can re-assert them after any embedded
233
- // reset. A full reset (\x1b[0m) clears both fg and bg; \x1b[49m clears bg;
234
- // \x1b[39m clears fg. Re-emitting the base opens after each keeps the modal
235
- // background solid AND gives raw text a readable foreground.
237
+ // Re-assert the base opens after any embedded reset so the modal background stays
238
+ // solid AND raw text keeps a readable foreground.
236
239
  const SENTINEL = "\x00";
237
240
  const bgOpen = bg(SENTINEL).split(SENTINEL)[0] ?? "";
238
241
  const fgOpen = fg ? (fg(SENTINEL).split(SENTINEL)[0] ?? "") : "";
239
- const reassert = (s: string): string =>
240
- bgOpen || fgOpen
241
- ? s.replace(/\x1b\[([0-9;]*)m/g, (seq, p: string) => {
242
- const parts = p.split(";");
243
- const isFull = p === "0";
244
- let tail = seq;
245
- if (isFull || parts.includes("49")) tail += bgOpen;
246
- if (isFull || parts.includes("39")) tail += fgOpen;
247
- return tail;
248
- })
249
- : s;
242
+ const reassert = (s: string): string => reopenAfterResets(s, bgOpen, fgOpen);
250
243
 
251
244
  const row = (content: string): string => {
252
245
  const pad = inner - visibleWidth(content);
package/src/progress.ts CHANGED
@@ -30,7 +30,7 @@ interface ProgressTheme {
30
30
  }
31
31
 
32
32
  interface ProgressComponent {
33
- render(width: number): string[];
33
+ render(width: number): readonly string[];
34
34
  invalidate(): void;
35
35
  handleInput(data: string): void;
36
36
  }
@@ -18,6 +18,7 @@ import {
18
18
  visibleWidth,
19
19
  } from "@earendil-works/pi-tui";
20
20
  import { getErrorMessage } from "@xynogen/pix-runtime/errors";
21
+ import { isSubTabKey, nextTab, renderSubTabBar, renderTabRule } from "@xynogen/pix-runtime/tab-bar";
21
22
  import {
22
23
  frameModal,
23
24
  MIN_MODAL_HEIGHT,
@@ -66,7 +67,7 @@ export interface ProviderPickerUI {
66
67
  keybindings: KeybindingsManager,
67
68
  done: (value: T) => void,
68
69
  ) => {
69
- render(width: number): string[];
70
+ render(width: number): readonly string[];
70
71
  invalidate(): void;
71
72
  handleInput(data: string): void;
72
73
  dispose?(): void;
@@ -90,7 +91,11 @@ function defaultExample(name: string): string {
90
91
  export function renderProviderRows(
91
92
  opts: ProviderPickerOptions,
92
93
  theme: Pick<PickerTheme, "fg">,
93
- state: { cursor: number; expanded: Set<string>; field?: { render(width: number): string[] } },
94
+ state: {
95
+ cursor: number;
96
+ expanded: Set<string>;
97
+ field?: { render(width: number): readonly string[] };
98
+ },
94
99
  width: number,
95
100
  ): { lines: string[]; nodes: Node[]; selected: { start: number; end: number } } {
96
101
  const aliases = opts.envAliases ?? {};
@@ -161,6 +166,8 @@ export interface SettingsRow {
161
166
  value: string;
162
167
  /** Theme role for the value. Default `success`. */
163
168
  tone?: "success" | "warning" | "muted";
169
+ /** Dim the label too: the row is turned off. The cursor still highlights it. */
170
+ dim?: boolean;
164
171
  /** Enter edits `value` in a text field inside the row, not in a new dialog. */
165
172
  editable?: boolean;
166
173
  /**
@@ -196,7 +203,7 @@ export function renderSettingsRows(
196
203
  rows: SettingsRow[],
197
204
  theme: Pick<PickerTheme, "fg">,
198
205
  selected: number,
199
- field?: { render(width: number): string[] },
206
+ field?: { render(width: number): readonly string[] },
200
207
  width = 80,
201
208
  list?: { choices: SettingsChoice[]; cursor: number; query: string; max?: number },
202
209
  ): { lines: string[]; rowLines: number[]; listLine?: number } {
@@ -206,14 +213,16 @@ export function renderSettingsRows(
206
213
  let listLine: number | undefined;
207
214
  let section = "";
208
215
  rows.forEach((row, index) => {
209
- if (row.section !== section) {
216
+ // An empty section (rows of one sub-tab) gets no heading.
217
+ if (row.section !== section && row.section) {
210
218
  if (section) lines.push("");
211
219
  lines.push(theme.fg("dim", ` ${row.section}`));
212
220
  section = row.section;
213
221
  }
214
222
  const active = index === selected;
215
223
  rowLines[index] = lines.length;
216
- const label = `${active ? theme.fg("accent", "→") : " "} ${theme.fg(active ? "accent" : "text", row.label.padEnd(labelWidth))} `;
224
+ const labelRole = active ? "accent" : row.dim ? "dim" : "text";
225
+ const label = `${active ? theme.fg("accent", "→") : " "} ${theme.fg(labelRole, row.label.padEnd(labelWidth))} `;
217
226
  const editing = active ? field : undefined;
218
227
  const valueWidth = Math.max(10, width - labelWidth - 4);
219
228
  lines.push(
@@ -266,10 +275,16 @@ export interface SettingsPickerOptions {
266
275
  onMount?: (redraw: () => void) => () => void;
267
276
  /** Start row. */
268
277
  selected?: number;
278
+ /**
279
+ * Show each row `section` as a sub-tab (`` ` `` switches) instead of a heading in one list.
280
+ * Off by default; one section shows no tab bar.
281
+ */
282
+ sectionTabs?: boolean;
269
283
  }
270
284
 
271
285
  /**
272
- * Show the sectioned settings overview. It stays open until esc, or until
286
+ * Show the sectioned settings overview, or one section per sub-tab with `sectionTabs`.
287
+ * It stays open until esc, or until
273
288
  * `onAction` returns `"close"`. For an `editable` row, enter opens a text field in
274
289
  * the row. Resolves with the closing action, or null on escape.
275
290
  */
@@ -279,8 +294,16 @@ export async function showSettingsPicker(
279
294
  ): Promise<SettingsAction | null> {
280
295
  const result = await ui.custom<SettingsAction | null>(
281
296
  (tui, theme, keybindings, done) => {
282
- let rows = opts.rows();
283
- let selected = Math.min(opts.selected ?? 0, Math.max(0, rows.length - 1));
297
+ let all = opts.rows();
298
+ const sectionsOf = (list: SettingsRow[]) => [...new Set(list.map((row) => row.section))];
299
+ // Start on the section of the requested row, so a reopened panel keeps its place.
300
+ let tab = opts.sectionTabs ? (all[opts.selected ?? 0]?.section ?? all[0]?.section ?? "") : "";
301
+ const visible = () => (tab ? all.filter((row) => row.section === tab) : all);
302
+ let rows = visible();
303
+ let selected = Math.max(
304
+ 0,
305
+ Math.min(rows.indexOf(all[opts.selected ?? 0] as SettingsRow), rows.length - 1),
306
+ );
284
307
  let field: Input | undefined;
285
308
  let list: { row: SettingsRow; query: string; cursor: number } | undefined;
286
309
  let busy = false;
@@ -300,7 +323,10 @@ export async function showSettingsPicker(
300
323
  error = getErrorMessage(cause);
301
324
  }
302
325
  busy = false;
303
- rows = opts.rows();
326
+ all = opts.rows();
327
+ if (tab && !sectionsOf(all).includes(tab)) tab = all[0]?.section ?? "";
328
+ rows = visible();
329
+ selected = Math.min(selected, Math.max(0, rows.length - 1));
304
330
  redraw();
305
331
  };
306
332
  const edit = (row: SettingsRow) => {
@@ -357,8 +383,9 @@ export async function showSettingsPicker(
357
383
  return {
358
384
  render(width: number) {
359
385
  const mw = modalWidth(width);
386
+ const tabs = tab ? sectionsOf(all) : [];
360
387
  const body = renderSettingsRows(
361
- rows,
388
+ tabs.length > 1 ? rows.map((row) => ({ ...row, section: "" })) : rows,
362
389
  theme,
363
390
  selected,
364
391
  field,
@@ -374,7 +401,10 @@ export async function showSettingsPicker(
374
401
  minHeight: MIN_MODAL_HEIGHT,
375
402
  title: opts.title,
376
403
  titleColor: (text) => theme.fg("accent", theme.bold(text)),
377
- header: [""],
404
+ header:
405
+ tabs.length > 1
406
+ ? [renderSubTabBar(tabs, tab, theme, mw - 4), renderTabRule(theme, mw - 4)]
407
+ : [""],
378
408
  body: body.lines,
379
409
  footer: [
380
410
  "",
@@ -384,7 +414,7 @@ export async function showSettingsPicker(
384
414
  ? "enter save · esc cancel"
385
415
  : list
386
416
  ? "type to filter · ↑↓ move · enter pick · esc cancel"
387
- : "↑↓ move · enter change · esc close",
417
+ : `↑↓ move · space/enter${all.some((row) => row.choices?.length) ? "/←→" : ""} change${tabs.length > 1 ? " · ` sub-tab" : ""} · esc close`,
388
418
  ),
389
419
  ],
390
420
  selectedBodyLine: body.listLine ?? body.rowLines[selected],
@@ -402,14 +432,28 @@ export async function showSettingsPicker(
402
432
  if (list) return listInput(data);
403
433
  if (keybindings.matches(data, "tui.select.cancel")) return close(null);
404
434
  if (busy) return;
435
+ if (tab && isSubTabKey(data)) {
436
+ tab = nextTab(sectionsOf(all), tab);
437
+ rows = visible();
438
+ selected = 0;
439
+ return redraw();
440
+ }
405
441
  const row = rows[selected];
406
- if (matchesKey(data, Key.enter)) {
442
+ // Standard /pix keys: enter or space acts on the row; ←→ step through its choices.
443
+ if (matchesKey(data, Key.enter) || matchesKey(data, Key.space)) {
407
444
  if (!row) return;
408
445
  if (row.choices?.length) openList(row);
409
446
  else if (row.editable) edit(row);
410
447
  else void run({ key: row.key });
411
448
  return redraw();
412
449
  }
450
+ if (row?.choices?.length && (matchesKey(data, Key.left) || matchesKey(data, Key.right))) {
451
+ const at = row.choices.findIndex((choice) => choice.value === row.value);
452
+ const step = matchesKey(data, Key.left) ? -1 : 1;
453
+ const next = row.choices[(at + step + row.choices.length) % row.choices.length];
454
+ if (next && next.value !== row.value) void run({ key: row.key, value: next.value });
455
+ return redraw();
456
+ }
413
457
  if (keybindings.matches(data, "tui.select.up"))
414
458
  selected = (selected - 1 + rows.length) % rows.length;
415
459
  else if (keybindings.matches(data, "tui.select.down"))
@@ -493,11 +537,11 @@ export async function showProviderPicker(
493
537
  "",
494
538
  field
495
539
  ? guide("enter", "submit") + sep + guide("esc", "cancel")
496
- : guide("\u2191\u2193", "navigate") +
540
+ : guide("↑↓", "move") +
497
541
  sep +
498
542
  guide("enter", "set default") +
499
543
  sep +
500
- guide("space", "open") +
544
+ guide("space", "expand") +
501
545
  sep +
502
546
  guide("esc", "close"),
503
547
  ],
package/src/text.ts CHANGED
@@ -132,12 +132,12 @@ export function fadeTextRow(
132
132
  *
133
133
  * Blank rows never take a fade step: the steps go to the last rows with text.
134
134
  */
135
- export function fadeRowsOf(
136
- lines: string[],
135
+ export function fadeRowsOf<T extends readonly string[]>(
136
+ lines: T,
137
137
  theme: FadeTheme,
138
138
  maxLines: number,
139
139
  fadeRows = 3,
140
- ): string[] {
140
+ ): T | string[] {
141
141
  if (lines.length <= maxLines) return lines;
142
142
  const paint = fadePaint(theme);
143
143
  // At most a third of the preview fades, so short previews stay readable.
@@ -30,7 +30,7 @@ export type TransientMessageLevel = "error" | "warning" | "info";
30
30
  type WidgetFactory = (
31
31
  tui: unknown,
32
32
  theme: TransientMessageTheme,
33
- ) => { render(width: number): string[]; invalidate(): void };
33
+ ) => { render(width: number): readonly string[]; invalidate(): void };
34
34
 
35
35
  export type TransientErrorUI = {
36
36
  setWidget(
package/src/tui.ts CHANGED
@@ -13,6 +13,7 @@ export {
13
13
  AssistantMessageComponent,
14
14
  CustomEditor,
15
15
  getMarkdownTheme,
16
+ InteractiveMode,
16
17
  Theme,
17
18
  } from "@earendil-works/pi-coding-agent";
18
19
  export type {
@@ -31,6 +32,10 @@ export {
31
32
  decodeKittyPrintable,
32
33
  Editor,
33
34
  fuzzyFilter,
35
+ getCapabilities,
36
+ getCellDimensions,
37
+ getImageDimensions,
38
+ Image,
34
39
  Input,
35
40
  isKeyRelease,
36
41
  isKeyRepeat,
package/src/utils.ts CHANGED
@@ -43,7 +43,7 @@ export function viewportText(
43
43
  }
44
44
 
45
45
  type ViewportComponent = {
46
- render(width: number): string[];
46
+ render(width: number): readonly string[];
47
47
  invalidate(): void;
48
48
  };
49
49
 
@@ -55,7 +55,7 @@ type ViewportEntry = {
55
55
  /** Raw line → line fitted to this width. */
56
56
  lines: Map<string, string>;
57
57
  /** Inner render output for the current text at this width. */
58
- rendered: string[] | undefined;
58
+ rendered: readonly string[] | undefined;
59
59
  };
60
60
 
61
61
  class ViewportText implements TextComponentLike, ViewportComponent {
@@ -84,7 +84,7 @@ class ViewportText implements TextComponentLike, ViewportComponent {
84
84
  return this.text;
85
85
  }
86
86
 
87
- render(width: number): string[] {
87
+ render(width: number): readonly string[] {
88
88
  let entry = this.widths.get(width);
89
89
  if (entry) {
90
90
  // Refresh recency: Map keeps insertion order, so re-insert moves it to the end.
@@ -1,25 +0,0 @@
1
- import { TuiMainScreen } from "@earendil-works/pi-tui";
2
-
3
- const PATCHED = Symbol.for("@xynogen/pix-pretty:overlay-images");
4
- type Compositor = {
5
- hasOverlay(): boolean;
6
- compositeOverlays(lines: string[], width: number, height: number): string[];
7
- [PATCHED]?: boolean;
8
- };
9
-
10
- /** Let the native renderer remove image placements before it draws an overlay. */
11
- export function installOverlayImages(): void {
12
- const prototype = Object.getPrototypeOf(TuiMainScreen.prototype) as Compositor;
13
- if (prototype[PATCHED]) return;
14
- const compose = prototype.compositeOverlays;
15
- // ponytail: Pi skips overlay composition on image lines; suppress transcript images until upstream supports image occlusion.
16
- prototype.compositeOverlays = function (lines, width, height) {
17
- const background = this.hasOverlay()
18
- ? lines.map((line) =>
19
- line.includes("\x1b_G") || line.includes("\x1b]1337;File=") ? "" : line,
20
- )
21
- : lines;
22
- return compose.call(this, background, width, height);
23
- };
24
- prototype[PATCHED] = true;
25
- }