@xynogen/pix-display 0.1.9 → 0.1.11

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/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ <!-- markdownlint-disable MD013 -->
2
+
1
3
  # pix-display
2
4
 
3
5
  Pi core extension — paste chips, thinking blocks, and polished code snippets.
@@ -12,7 +14,7 @@ Three features, always on when installed:
12
14
 
13
15
  **Code snippets.** Renders every fenced code block in assistant responses inside a themed, language-labeled frame—including Python, TypeScript, JSON, YAML, Rust, Go, SQL, shell, and arbitrary custom language tags. Untagged fences use a `code` label. Pi's native syntax highlighting remains intact for recognized languages, while long lines are safely clipped to the terminal width.
14
16
 
15
- The features are registered at session start. TUI-only display changes are no-ops in JSON/RPC/print modes.
17
+ The features are registered at session start. TUI-only display changes are no-ops in JSON/RPC/print modes. In-process non-TUI child sessions (such as background subagents) do not clear the parent TUI's renderer state.
16
18
 
17
19
  ## Install
18
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xynogen/pix-display",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "Pi core extension \u2014 paste chips, thinking blocks, and framed code rendering",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -13,6 +13,7 @@ const OSC_RE = /\x1b\][^\x07]*(?:\x07|\x1b\\)/g;
13
13
  const PATCHED = Symbol.for("@xynogen/pix-display:code-block-renderer");
14
14
 
15
15
  type CodeFrameTheme = Pick<Theme, "bg" | "bold" | "fg" | "getBgAnsi">;
16
+ type RenderMode = "tui" | "rpc" | "json" | "print";
16
17
 
17
18
  type PatchablePrototype = {
18
19
  [PATCHED]?: boolean;
@@ -21,6 +22,20 @@ type PatchablePrototype = {
21
22
 
22
23
  let activeTheme: CodeFrameTheme | undefined;
23
24
 
25
+ /**
26
+ * Preserve the main TUI theme when an in-process non-TUI child session starts.
27
+ * Subagents share this module and the patched prototype with the parent; letting
28
+ * their print/RPC session clear the theme silently disables code frames in the
29
+ * still-running parent transcript.
30
+ */
31
+ export function themeAfterSessionStart(
32
+ current: CodeFrameTheme | undefined,
33
+ mode: RenderMode,
34
+ theme: CodeFrameTheme,
35
+ ): CodeFrameTheme | undefined {
36
+ return mode === "tui" ? theme : current;
37
+ }
38
+
24
39
  function plainText(line: string): string {
25
40
  return line.replace(OSC_RE, "").replace(ANSI_RE, "");
26
41
  }
@@ -66,19 +81,19 @@ function fenceLabel(line: string): string | undefined {
66
81
  return info.split(/\s+/, 1)[0] || DEFAULT_LABEL;
67
82
  }
68
83
 
69
- function topBorder(width: number, language: string, theme: CodeFrameTheme): string {
70
- const available = Math.max(1, width - 6);
84
+ function topRule(width: number, language: string, theme: CodeFrameTheme): string {
85
+ const available = Math.max(1, width - 4);
71
86
  const displayLanguage = truncateToWidth(language, available, "…");
72
87
  const label = theme.bold(theme.fg("accent", ` ${displayLanguage} `));
73
- const ruleWidth = Math.max(0, width - visibleWidth(label) - 3);
88
+ const ruleWidth = Math.max(0, width - visibleWidth(label) - 2);
74
89
  return paintFrame(
75
90
  theme,
76
- `${theme.fg("borderMuted", "╭─")}${label}${theme.fg("borderMuted", `${"─".repeat(ruleWidth)}╮`)}`,
91
+ `${theme.fg("borderMuted", "──")}${label}${theme.fg("borderMuted", "─".repeat(ruleWidth))}`,
77
92
  );
78
93
  }
79
94
 
80
- function bottomBorder(width: number, theme: CodeFrameTheme): string {
81
- return paintFrame(theme, theme.fg("borderMuted", `╰${"─".repeat(Math.max(0, width - 2))}╯`));
95
+ function bottomRule(width: number, theme: CodeFrameTheme): string {
96
+ return paintFrame(theme, theme.fg("borderMuted", "─".repeat(width)));
82
97
  }
83
98
 
84
99
  function bodyLine(
@@ -111,27 +126,22 @@ export function renderCodeFences(lines: string[], width: number, theme: CodeFram
111
126
  }
112
127
  if (end >= out.length) continue;
113
128
 
114
- const pad = Math.min(leadingSpaces(out[start] ?? ""), Math.floor((width - 12) / 2));
115
- const frameWidth = Math.max(12, width - pad * 2);
129
+ const frameWidth = width;
116
130
  const body = out.slice(start + 1, end);
117
131
  const bodyIndents = body
118
132
  .map((line) => plainText(line))
119
133
  .filter((line) => line.trim().length > 0)
120
134
  .map((line) => leadingSpaces(line));
121
135
  const bodyIndent = bodyIndents.length > 0 ? Math.min(...bodyIndents) : 0;
122
- const left = " ".repeat(pad);
123
- const right = " ".repeat(Math.max(0, width - pad - frameWidth));
124
136
  const framed: string[] = [];
125
137
 
126
- framed.push(
127
- `${oscSequences(out[start] ?? "")}${left}${topBorder(frameWidth, language, theme)}${right}`,
128
- );
138
+ framed.push(`${oscSequences(out[start] ?? "")}${topRule(frameWidth, language, theme)}`);
129
139
  for (let index = start + 1; index < end; index++) {
130
140
  framed.push(
131
141
  `${oscSequences(out[index] ?? "")}${bodyLine(out[index] ?? "", width, bodyIndent, theme)}`,
132
142
  );
133
143
  }
134
- framed.push(`${oscSequences(out[end] ?? "")}${left}${bottomBorder(frameWidth, theme)}${right}`);
144
+ framed.push(`${oscSequences(out[end] ?? "")}${bottomRule(frameWidth, theme)}`);
135
145
 
136
146
  out.splice(start, end - start + 1, ...framed);
137
147
  start += framed.length - 1;
@@ -154,6 +164,6 @@ function patchAssistantRenderer(): void {
154
164
  export default function codeBlocksExtension(pi: ExtensionAPI): void {
155
165
  patchAssistantRenderer();
156
166
  pi.on("session_start", (_event, ctx) => {
157
- activeTheme = ctx.mode === "tui" ? ctx.ui.theme : undefined;
167
+ activeTheme = themeAfterSessionStart(activeTheme, ctx.mode, ctx.ui.theme);
158
168
  });
159
169
  }