@pi-kaush/pi-content-layout 0.1.8 → 0.1.10

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,9 +2,9 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
- - Give the submitted-prompt box an explicit right padding column inside the
6
- surface, matching the one already on the left of the text, so wrapped
7
- content no longer sits flush against the box's right edge.
5
+ - Pad the submitted-prompt box with two columns on the right of the text so
6
+ it matches the two-column visual gap the quarter-block rail leaves on the
7
+ left; previously wrapped content sat one column off the right edge.
8
8
 
9
9
  - Reference semantic tokens for the remaining extension-colored elements:
10
10
  the intercom sender name rides `customMessageLabel`, the submitted-prompt
package/README.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
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.
4
4
 
5
+ ### Install
6
+
7
+ ```fish
8
+ pi install npm:@pi-kaush/pi-content-layout
9
+ ```
10
+
11
+ Restart Pi or run `/reload`.
12
+
5
13
  ```text
6
14
  Assistant output
7
15
  Text wraps inside the inset width.
@@ -33,6 +41,23 @@ text at this package's message inset, so `pi-tool-call-markers` mirrors
33
41
  `contentInset` for its bash blocks (see its `src/bash-block.ts`). Change
34
42
  indentation in both packages together.
35
43
 
44
+ ## Queued steering previews
45
+
46
+ Pi renders queued `Steering:` messages in the native `dim` color. This package
47
+ uses the optional `steeringMessage` foreground token when the active theme
48
+ defines it; otherwise, it preserves Pi's native `dim` color. Other queued
49
+ rows and the dequeue hint stay native.
50
+
51
+ Add the token to a theme's `colors` map to choose the preview color:
52
+
53
+ ```json
54
+ {
55
+ "colors": {
56
+ "steeringMessage": "mauve"
57
+ }
58
+ }
59
+ ```
60
+
36
61
  ## pi-intercom message surface
37
62
 
38
63
  When [`pi-intercom`](https://www.npmjs.com/package/pi-intercom) is installed,
@@ -53,7 +78,9 @@ for the restyle to take effect. Without pi-intercom installed the
53
78
  registration is inert; malformed message payloads fall back to Pi's default
54
79
  custom-message box.
55
80
 
56
- ## Install
81
+ ## Manual configuration
82
+
83
+ If you manage Pi package sources directly, add the package to `settings.json`:
57
84
 
58
85
  ```json
59
86
  {
@@ -61,8 +88,6 @@ custom-message box.
61
88
  }
62
89
  ```
63
90
 
64
- The package is not published while its version is `0.0.0`; use the repository path for local development.
65
-
66
91
  ## Theme ownership
67
92
 
68
93
  The active editor surface and submitted message body paint with a fixed
@@ -80,7 +105,7 @@ shape; a theme cannot provide the layout itself.
80
105
 
81
106
  The editor factory wraps the currently configured custom editor, or creates Pi's `CustomEditor` when none exists. It decorates `render()` only; text handling, callbacks, autocomplete, history, paste, application keybindings, image paste, and extension shortcuts remain on Pi's editor.
82
107
 
83
- Pi does not currently expose public renderers for native user and assistant messages. Their side inset and submitted prompt shell therefore use guarded prototype adapters around Pi's exported components. The adapters are idempotent, restore the original renderers on shutdown, and fall back to native rendering if the runtime shape changes.
108
+ Pi does not currently expose public renderers for native user and assistant messages or queued steering previews. Their layout and styling use guarded adapters around Pi's exported components. The adapters restore the original renderers on shutdown and fall back to native rendering when the expected component shape changes.
84
109
 
85
110
  For the complete visual system, combine this package with:
86
111
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-kaush/pi-content-layout",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
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
@@ -10,6 +10,7 @@ import {
10
10
  type EditorComponent,
11
11
  type EditorTheme,
12
12
  Loader,
13
+ TruncatedText,
13
14
  type TUI,
14
15
  visibleWidth,
15
16
  } from "@earendil-works/pi-tui";
@@ -35,6 +36,9 @@ const SYSTEM_CONTAINER_RENDER_PATCH = Symbol.for(
35
36
  const STATUS_LOADER_RENDER_PATCH = Symbol.for(
36
37
  "kg.pi.contentLayout.statusLoaderRender.v1",
37
38
  );
39
+ const STEERING_MESSAGE_RENDER_PATCH = Symbol.for(
40
+ "kg.pi.contentLayout.steeringMessageRender.v1",
41
+ );
38
42
 
39
43
  type EditorFactory = (
40
44
  tui: TUI,
@@ -310,6 +314,49 @@ function statusLoaderDecorator(
310
314
  return insetLines(lines, width, inset);
311
315
  }
312
316
 
317
+ function themeColorAnsi(theme: Theme, color: string): string | undefined {
318
+ try {
319
+ return (theme.getFgAnsi as (color: string) => string).call(theme, color);
320
+ } catch {
321
+ return undefined;
322
+ }
323
+ }
324
+
325
+ // Pi renders queued steering previews as TruncatedText rows in dim. The
326
+ // optional color token is extension-defined; absent themes keep native dim.
327
+ function steeringMessageDecorator(
328
+ original: RenderPatchState["originalRender"],
329
+ row: RenderRow,
330
+ width: number,
331
+ theme: Theme,
332
+ _memo: RenderMemo,
333
+ ): string[] {
334
+ const textRow = row as NativeTextRow;
335
+ const text = textRow.text;
336
+ const dimAnsi = themeColorAnsi(theme, "dim");
337
+ const reset = "\x1b[39m";
338
+ if (
339
+ typeof text !== "string" ||
340
+ !dimAnsi ||
341
+ !text.startsWith(dimAnsi) ||
342
+ !text.endsWith(reset) ||
343
+ !text.slice(dimAnsi.length, -reset.length).startsWith("Steering: ")
344
+ ) {
345
+ return original.call(row, width);
346
+ }
347
+
348
+ const colorAnsi = themeColorAnsi(theme, "steeringMessage") ?? dimAnsi;
349
+ const message = text.slice(dimAnsi.length, -reset.length);
350
+ // Let TruncatedText handle ANSI-aware truncation, then restore its native
351
+ // source text so the style never leaks into a later render.
352
+ textRow.text = `${colorAnsi}${message}${reset}`;
353
+ try {
354
+ return original.call(row, width);
355
+ } finally {
356
+ textRow.text = text;
357
+ }
358
+ }
359
+
313
360
  function systemContainerDecorator(
314
361
  original: RenderPatchState["originalRender"],
315
362
  row: RenderRow,
@@ -396,6 +443,7 @@ export default function contentLayout(pi: ExtensionAPI): void {
396
443
  let userPatch: RenderPatchState | undefined;
397
444
  let systemContainerPatch: RenderPatchState | undefined;
398
445
  let statusLoaderPatch: RenderPatchState | undefined;
446
+ let steeringMessagePatch: RenderPatchState | undefined;
399
447
  let editorRegistration:
400
448
  | {
401
449
  factory: EditorFactory;
@@ -446,6 +494,14 @@ export default function contentLayout(pi: ExtensionAPI): void {
446
494
  statusLoaderDecorator,
447
495
  );
448
496
 
497
+ steeringMessagePatch = installRenderPatch(
498
+ TruncatedText.prototype as unknown as PatchableRenderPrototype,
499
+ STEERING_MESSAGE_RENDER_PATCH,
500
+ owner,
501
+ getTheme,
502
+ steeringMessageDecorator,
503
+ );
504
+
449
505
  const previous = ctx.ui.getEditorComponent() as EditorFactory | undefined;
450
506
  const factory: EditorFactory = (tui, editorTheme, keybindings) => {
451
507
  const editor = previous
@@ -493,10 +549,17 @@ export default function contentLayout(pi: ExtensionAPI): void {
493
549
  owner,
494
550
  statusLoaderPatch,
495
551
  );
552
+ uninstallRenderPatch(
553
+ TruncatedText.prototype as unknown as PatchableRenderPrototype,
554
+ STEERING_MESSAGE_RENDER_PATCH,
555
+ owner,
556
+ steeringMessagePatch,
557
+ );
496
558
  assistantPatch = undefined;
497
559
  userPatch = undefined;
498
560
  systemContainerPatch = undefined;
499
561
  statusLoaderPatch = undefined;
562
+ steeringMessagePatch = undefined;
500
563
  activeTheme = undefined;
501
564
  });
502
565
  }
package/src/render.ts CHANGED
@@ -258,13 +258,14 @@ export function renderSubmittedUserLines(
258
258
  const { controls, content } = splitLeadingSemanticControls(line);
259
259
  const recolored = replaceBackground(content, surfaceBg);
260
260
  const rail = theme.fg(railColor, PROMPT_RAIL);
261
- // One column of side padding inside the box on both edges, so submitted
262
- // text sits two columns right of the rail and one column off the right
263
- // edge — matching the active editor's side padding.
264
- const padding = " ".repeat(ACTIVE_SIDE_PADDING);
265
- const innerWidth = Math.max(1, bodyWidth - ACTIVE_SIDE_PADDING * 2);
261
+ // The rail glyph (▎) fills only the left quarter of its cell, so one
262
+ // column of left padding already reads as a two-column visual gap.
263
+ // Give the right edge two columns so both sides of the text read equal.
264
+ const leftPadding = " ".repeat(ACTIVE_SIDE_PADDING);
265
+ const rightPadding = " ".repeat(ACTIVE_SIDE_PADDING + 1);
266
+ const innerWidth = Math.max(1, bodyWidth - ACTIVE_SIDE_PADDING * 2 - 1);
266
267
  const body = paintBackground(
267
- `${padding}${fitLine(recolored, innerWidth)}${padding}`,
268
+ `${leftPadding}${fitLine(recolored, innerWidth)}${rightPadding}`,
268
269
  bodyWidth,
269
270
  surfaceBg,
270
271
  );