@pi-kaush/pi-content-layout 0.1.2 → 0.1.3

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/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ - Restyle user-run bash blocks (`!` commands) with the submitted-prompt rail
6
+ shell: Pi's green top/bottom rules are replaced by the dark surface with a
7
+ left rail, command first and output below. The rail stays `bashMode` green
8
+ while running and on success, turns `error` red on a non-zero exit and
9
+ `warning` yellow when cancelled, and stays dim for `!!` commands excluded
10
+ from context.
11
+
5
12
  - Pad submitted message text two columns right of the accent rail (one extra leading space inside the body) for more breathing room in the chat log.
6
13
  - Paint the active editor surface and submitted message body with a fixed
7
14
  `#071312` background (`PROMPT_SURFACE_BG`) instead of the theme's `selectedBg`
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # pi-content-layout
2
2
 
3
- A small Pi extension that insets the main conversation, renders the active editor as a full-width dark surface, and gives submitted prompts a compact rail shell.
3
+ A small Pi extension that insets the main conversation, renders the active editor as a full-width dark surface, and gives submitted prompts and user-run bash blocks a compact rail shell.
4
4
 
5
5
  ```text
6
6
  Assistant output
@@ -15,10 +15,19 @@ Submitted prompt
15
15
  ▎ darker background
16
16
  ▎ prompt text darker background
17
17
  ▎ darker background
18
+
19
+ User bash (`!` command, failed)
20
+ ▎ darker background, red rail
21
+ ▎ $ ls ~/matrxi darker background
22
+ ▎ ls: /Users/kg/matrxi: No such file or directory
23
+ ▎ (exit 1) darker background
24
+ ▎ darker background
18
25
  ```
19
26
 
20
27
  Assistant and submitted-message content keep the two-column outer inset. The active prompt intentionally ignores that inset: its darker background fills the terminal width, with no rail, one extra layout column on each side of Pi's configured editor padding, and one background-colored row above and below the content. Real scroll indicators replace the corresponding padding row when needed. The submitted prompt remains unchanged: it keeps Pi's message padding and the thin rail outside its darker body. Autocomplete stays outside the active surface.
21
28
 
29
+ User-run bash blocks (`!` commands) trade Pi's green top/bottom rules for the same rail shell as the submitted prompt, command first and output below. The rail keeps the usual green while running and on success, turns red on a non-zero exit, yellow when cancelled, and stays dim for `!!` commands excluded from context.
30
+
22
31
  ## Install
23
32
 
24
33
  ```json
@@ -34,8 +43,9 @@ The package is not published while its version is `0.0.0`; use the repository pa
34
43
  The active editor surface and submitted message body paint with a fixed
35
44
  near-black `#071312` background (`PROMPT_SURFACE_BG`) so both user-input
36
45
  surfaces stay identical; the theme's `selectedBg` token continues to serve
37
- selections and dialogs. The extension consumes two theme tokens: `accent`
38
- for the submitted-prompt rail and `muted` for the editor scroll hints.
46
+ selections and dialogs. The extension consumes theme tokens for its rails and hints: `accent`
47
+ for the submitted-prompt rail, `muted` for the editor scroll hints, and
48
+ `bashMode` / `error` / `warning` / `dim` for the user-bash rail.
39
49
 
40
50
  Themes control colors, while this extension controls width and component
41
51
  shape; a theme cannot provide the layout itself.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-kaush/pi-content-layout",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Inset Pi's conversation surface and style active and submitted prompts as matching blocks.",
5
5
  "license": "MIT",
6
6
  "author": "Kaushik Gopal",
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  AssistantMessageComponent,
3
+ BashExecutionComponent,
3
4
  CustomEditor,
4
5
  type ExtensionAPI,
5
6
  type KeybindingsManager,
@@ -11,6 +12,7 @@ import {
11
12
  type EditorTheme,
12
13
  Loader,
13
14
  type TUI,
15
+ visibleWidth,
14
16
  } from "@earendil-works/pi-tui";
15
17
  import {
16
18
  chatContainerHooks,
@@ -19,7 +21,9 @@ import {
19
21
  import {
20
22
  contentInset,
21
23
  insetLines,
24
+ PROMPT_RAIL,
22
25
  renderActiveEditor,
26
+ renderBashBlockLines,
23
27
  renderSubmittedUserLines,
24
28
  } from "./render.ts";
25
29
 
@@ -33,6 +37,9 @@ const SYSTEM_CONTAINER_RENDER_PATCH = Symbol.for(
33
37
  const STATUS_LOADER_RENDER_PATCH = Symbol.for(
34
38
  "kg.pi.contentLayout.statusLoaderRender.v1",
35
39
  );
40
+ const BASH_EXECUTION_RENDER_PATCH = Symbol.for(
41
+ "kg.pi.contentLayout.bashExecutionRender.v1",
42
+ );
36
43
 
37
44
  type EditorFactory = (
38
45
  tui: TUI,
@@ -62,6 +69,10 @@ type LoaderRow = RenderRow & {
62
69
  paddingX?: unknown;
63
70
  };
64
71
 
72
+ type BashExecutionRow = RenderRow & {
73
+ status?: unknown;
74
+ };
75
+
65
76
  type RenderPatchState = {
66
77
  originalRender: (this: RenderRow, width: number) => string[];
67
78
  patchedRender: (this: RenderRow, width: number) => string[];
@@ -334,6 +345,35 @@ function systemContainerDecorator(
334
345
  }
335
346
  }
336
347
 
348
+ // User-run bash blocks (`!` commands) take the submitted-prompt shell: the
349
+ // native green rules are replaced by the rail and dark surface, with the rail
350
+ // recolored from the command's outcome (green normally, red on a non-zero
351
+ // exit, yellow when cancelled).
352
+ function bashExecutionDecorator(
353
+ original: RenderPatchState["originalRender"],
354
+ row: RenderRow,
355
+ width: number,
356
+ theme: Theme,
357
+ memo: RenderMemo,
358
+ ): string[] {
359
+ const inset = contentInset(width);
360
+ const bodyWidth = width - inset * 2 - visibleWidth(PROMPT_RAIL);
361
+ if (inset === 0 || bodyWidth < 8) return original.call(row, width);
362
+ const lines = original.call(row, Math.max(1, bodyWidth));
363
+ const cached = memo.hit(lines);
364
+ if (cached) return cached;
365
+ const status = (row as BashExecutionRow).status;
366
+ const decorated = renderBashBlockLines(
367
+ lines,
368
+ width,
369
+ theme,
370
+ typeof status === "string" ? status : undefined,
371
+ inset,
372
+ );
373
+ memo.store(lines, decorated);
374
+ return decorated;
375
+ }
376
+
337
377
  function userDecorator(
338
378
  original: RenderPatchState["originalRender"],
339
379
  row: RenderRow,
@@ -386,6 +426,7 @@ export default function contentLayout(pi: ExtensionAPI): void {
386
426
  let userPatch: RenderPatchState | undefined;
387
427
  let systemContainerPatch: RenderPatchState | undefined;
388
428
  let statusLoaderPatch: RenderPatchState | undefined;
429
+ let bashExecutionPatch: RenderPatchState | undefined;
389
430
  let editorRegistration:
390
431
  | {
391
432
  factory: EditorFactory;
@@ -435,6 +476,13 @@ export default function contentLayout(pi: ExtensionAPI): void {
435
476
  getTheme,
436
477
  statusLoaderDecorator,
437
478
  );
479
+ bashExecutionPatch = installRenderPatch(
480
+ BashExecutionComponent.prototype as unknown as PatchableRenderPrototype,
481
+ BASH_EXECUTION_RENDER_PATCH,
482
+ owner,
483
+ getTheme,
484
+ bashExecutionDecorator,
485
+ );
438
486
 
439
487
  const previous = ctx.ui.getEditorComponent() as EditorFactory | undefined;
440
488
  const factory: EditorFactory = (tui, editorTheme, keybindings) => {
@@ -483,10 +531,17 @@ export default function contentLayout(pi: ExtensionAPI): void {
483
531
  owner,
484
532
  statusLoaderPatch,
485
533
  );
534
+ uninstallRenderPatch(
535
+ BashExecutionComponent.prototype as unknown as PatchableRenderPrototype,
536
+ BASH_EXECUTION_RENDER_PATCH,
537
+ owner,
538
+ bashExecutionPatch,
539
+ );
486
540
  assistantPatch = undefined;
487
541
  userPatch = undefined;
488
542
  systemContainerPatch = undefined;
489
543
  statusLoaderPatch = undefined;
544
+ bashExecutionPatch = undefined;
490
545
  activeTheme = undefined;
491
546
  });
492
547
  }
package/src/render.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Theme } from "@earendil-works/pi-coding-agent";
1
+ import type { Theme, ThemeColor } from "@earendil-works/pi-coding-agent";
2
2
  import type { EditorComponent } from "@earendil-works/pi-tui";
3
3
  import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
4
4
 
@@ -196,6 +196,7 @@ export function renderSubmittedUserLines(
196
196
  width: number,
197
197
  theme: Theme,
198
198
  inset = contentInset(width),
199
+ railColor: ThemeColor = "accent",
199
200
  ): string[] {
200
201
  const blockWidth = width - inset * 2;
201
202
  if (inset === 0 || blockWidth <= visibleWidth(PROMPT_RAIL)) {
@@ -207,7 +208,7 @@ export function renderSubmittedUserLines(
207
208
  return lines.map((line) => {
208
209
  const { controls, content } = splitLeadingSemanticControls(line);
209
210
  const recolored = replaceBackground(content, PROMPT_SURFACE_BG);
210
- const rail = theme.fg("accent", PROMPT_RAIL);
211
+ const rail = theme.fg(railColor, PROMPT_RAIL);
211
212
  // One extra leading space inside the body, so submitted text sits two
212
213
  // columns right of the rail instead of one.
213
214
  const body = paintBackground(
@@ -218,3 +219,62 @@ export function renderSubmittedUserLines(
218
219
  return `${controls}${margin}${rail}${body}${margin}`;
219
220
  });
220
221
  }
222
+
223
+ const RULE_LINE_RE = /^─+$/;
224
+
225
+ function isRuleLine(line: string | undefined): line is string {
226
+ return line !== undefined && RULE_LINE_RE.test(stripDisplayAnsi(line).trim());
227
+ }
228
+
229
+ // `!!` commands draw their rules dim instead of bashMode green, but the
230
+ // component does not store that flag, so sniff the top rule's color to keep
231
+ // the rail consistent with the framing it replaces.
232
+ function sniffsDimRule(rule: string, theme: Theme): boolean {
233
+ const prefixOf = (colored: string) => colored.slice(0, colored.indexOf("─"));
234
+ const dimPrefix = prefixOf(theme.fg("dim", "─"));
235
+ return (
236
+ dimPrefix.length > 0 &&
237
+ dimPrefix !== prefixOf(theme.fg("bashMode", "─")) &&
238
+ rule.startsWith(dimPrefix)
239
+ );
240
+ }
241
+
242
+ // Rail tone for a user bash block: failures read red and cancellations
243
+ // yellow, matching the block's status text; anything else keeps the green
244
+ // the rules used (dim for `!!` commands).
245
+ export function bashBlockRailColor(
246
+ status: string | undefined,
247
+ topRule: string | undefined,
248
+ theme: Theme,
249
+ ): ThemeColor {
250
+ if (status === "error") return "error";
251
+ if (status === "cancelled") return "warning";
252
+ if (topRule !== undefined && sniffsDimRule(topRule, theme)) return "dim";
253
+ return "bashMode";
254
+ }
255
+
256
+ // Reshapes BashExecutionComponent output into the submitted-prompt shell: the
257
+ // leading spacer stays outside the block, the top/bottom rules are dropped,
258
+ // and the remaining lines get one blank padded row at each end plus the rail
259
+ // and dark surface.
260
+ export function renderBashBlockLines(
261
+ lines: string[],
262
+ width: number,
263
+ theme: Theme,
264
+ status: string | undefined,
265
+ inset = contentInset(width),
266
+ ): string[] {
267
+ const [spacer, ...rest] = lines;
268
+ const topRule = isRuleLine(rest[0]) ? rest[0] : undefined;
269
+ const inner = topRule !== undefined ? rest.slice(1) : rest.slice();
270
+ if (isRuleLine(inner[inner.length - 1])) inner.pop();
271
+ const railColor = bashBlockRailColor(status, topRule, theme);
272
+ const block = renderSubmittedUserLines(
273
+ ["", ...inner, ""],
274
+ width,
275
+ theme,
276
+ inset,
277
+ railColor,
278
+ );
279
+ return [fitLine(spacer ?? "", width), ...block];
280
+ }