@pi-kaush/pi-content-layout 0.1.3 → 0.1.5
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 +9 -6
- package/README.md +19 -13
- package/package.json +1 -1
- package/src/index.ts +0 -54
- package/src/render.ts +40 -60
package/CHANGELOG.md
CHANGED
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
-
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
- Render active input with the theme's `userMessageText` foreground, restoring
|
|
6
|
+
that base color after embedded ANSI resets while preserving inline identifier
|
|
7
|
+
highlighting.
|
|
8
|
+
- Move user-run `!` bash block styling to `@pi-kaush/pi-tool-call-markers`,
|
|
9
|
+
which now owns every execution row (tools, grouping, subagents, thinking
|
|
10
|
+
labels, and bash blocks). This package narrows to the transcript surface:
|
|
11
|
+
message insets, system-text and status-rule alignment, the editor surface,
|
|
12
|
+
and the submitted-prompt shell for user messages. One spacing contract with
|
|
13
|
+
markers remains: bash blocks align at this package's message inset.
|
|
11
14
|
|
|
12
15
|
- 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.
|
|
13
16
|
- Paint the active editor surface and submitted message body with a fixed
|
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
|
|
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
5
|
```text
|
|
6
6
|
Assistant output
|
|
@@ -15,18 +15,23 @@ 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
|
|
25
18
|
```
|
|
26
19
|
|
|
27
20
|
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.
|
|
28
21
|
|
|
29
|
-
|
|
22
|
+
## Scope boundary
|
|
23
|
+
|
|
24
|
+
This package owns the transcript **surface**: the message inset, system-text
|
|
25
|
+
and status-rule alignment, the editor surface, and the submitted-prompt
|
|
26
|
+
shell for user messages. It deliberately never renders tool execution rows
|
|
27
|
+
today: collapsed tool calls, grouping, subagent plans, thinking labels, and
|
|
28
|
+
user-run `!` bash blocks all live in `@pi-kaush/pi-tool-call-markers` (which
|
|
29
|
+
also owns the rail shell those blocks use).
|
|
30
|
+
|
|
31
|
+
The one cross-package contract is spacing: `!` blocks align with message
|
|
32
|
+
text at this package's message inset, so `pi-tool-call-markers` mirrors
|
|
33
|
+
`contentInset` for its bash blocks (see its `src/bash-block.ts`). Change
|
|
34
|
+
indentation in both packages together.
|
|
30
35
|
|
|
31
36
|
## Install
|
|
32
37
|
|
|
@@ -43,9 +48,10 @@ The package is not published while its version is `0.0.0`; use the repository pa
|
|
|
43
48
|
The active editor surface and submitted message body paint with a fixed
|
|
44
49
|
near-black `#071312` background (`PROMPT_SURFACE_BG`) so both user-input
|
|
45
50
|
surfaces stay identical; the theme's `selectedBg` token continues to serve
|
|
46
|
-
selections and dialogs.
|
|
47
|
-
|
|
48
|
-
|
|
51
|
+
selections and dialogs. Active input uses the theme's `userMessageText`
|
|
52
|
+
foreground and restores it after embedded ANSI resets without overriding
|
|
53
|
+
inline identifier colors. The extension also consumes `accent` for the
|
|
54
|
+
submitted-prompt rail and `muted` for editor scroll hints.
|
|
49
55
|
|
|
50
56
|
Themes control colors, while this extension controls width and component
|
|
51
57
|
shape; a theme cannot provide the layout itself.
|
|
@@ -59,7 +65,7 @@ Pi does not currently expose public renderers for native user and assistant mess
|
|
|
59
65
|
For the complete visual system, combine this package with:
|
|
60
66
|
|
|
61
67
|
- `@pi-kaush/pi-footer-minimal` for matching footer inset and footer working state; and
|
|
62
|
-
- `@pi-kaush/pi-tool-call-markers` for unboxed tool rows, subagent plans, and
|
|
68
|
+
- `@pi-kaush/pi-tool-call-markers` for unboxed tool rows, subagent plans, thinking markers, and user-run `!` bash blocks.
|
|
63
69
|
|
|
64
70
|
## License
|
|
65
71
|
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AssistantMessageComponent,
|
|
3
|
-
BashExecutionComponent,
|
|
4
3
|
CustomEditor,
|
|
5
4
|
type ExtensionAPI,
|
|
6
5
|
type KeybindingsManager,
|
|
@@ -21,9 +20,7 @@ import {
|
|
|
21
20
|
import {
|
|
22
21
|
contentInset,
|
|
23
22
|
insetLines,
|
|
24
|
-
PROMPT_RAIL,
|
|
25
23
|
renderActiveEditor,
|
|
26
|
-
renderBashBlockLines,
|
|
27
24
|
renderSubmittedUserLines,
|
|
28
25
|
} from "./render.ts";
|
|
29
26
|
|
|
@@ -37,9 +34,6 @@ const SYSTEM_CONTAINER_RENDER_PATCH = Symbol.for(
|
|
|
37
34
|
const STATUS_LOADER_RENDER_PATCH = Symbol.for(
|
|
38
35
|
"kg.pi.contentLayout.statusLoaderRender.v1",
|
|
39
36
|
);
|
|
40
|
-
const BASH_EXECUTION_RENDER_PATCH = Symbol.for(
|
|
41
|
-
"kg.pi.contentLayout.bashExecutionRender.v1",
|
|
42
|
-
);
|
|
43
37
|
|
|
44
38
|
type EditorFactory = (
|
|
45
39
|
tui: TUI,
|
|
@@ -69,10 +63,6 @@ type LoaderRow = RenderRow & {
|
|
|
69
63
|
paddingX?: unknown;
|
|
70
64
|
};
|
|
71
65
|
|
|
72
|
-
type BashExecutionRow = RenderRow & {
|
|
73
|
-
status?: unknown;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
66
|
type RenderPatchState = {
|
|
77
67
|
originalRender: (this: RenderRow, width: number) => string[];
|
|
78
68
|
patchedRender: (this: RenderRow, width: number) => string[];
|
|
@@ -345,35 +335,6 @@ function systemContainerDecorator(
|
|
|
345
335
|
}
|
|
346
336
|
}
|
|
347
337
|
|
|
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
|
-
|
|
377
338
|
function userDecorator(
|
|
378
339
|
original: RenderPatchState["originalRender"],
|
|
379
340
|
row: RenderRow,
|
|
@@ -426,7 +387,6 @@ export default function contentLayout(pi: ExtensionAPI): void {
|
|
|
426
387
|
let userPatch: RenderPatchState | undefined;
|
|
427
388
|
let systemContainerPatch: RenderPatchState | undefined;
|
|
428
389
|
let statusLoaderPatch: RenderPatchState | undefined;
|
|
429
|
-
let bashExecutionPatch: RenderPatchState | undefined;
|
|
430
390
|
let editorRegistration:
|
|
431
391
|
| {
|
|
432
392
|
factory: EditorFactory;
|
|
@@ -476,13 +436,6 @@ export default function contentLayout(pi: ExtensionAPI): void {
|
|
|
476
436
|
getTheme,
|
|
477
437
|
statusLoaderDecorator,
|
|
478
438
|
);
|
|
479
|
-
bashExecutionPatch = installRenderPatch(
|
|
480
|
-
BashExecutionComponent.prototype as unknown as PatchableRenderPrototype,
|
|
481
|
-
BASH_EXECUTION_RENDER_PATCH,
|
|
482
|
-
owner,
|
|
483
|
-
getTheme,
|
|
484
|
-
bashExecutionDecorator,
|
|
485
|
-
);
|
|
486
439
|
|
|
487
440
|
const previous = ctx.ui.getEditorComponent() as EditorFactory | undefined;
|
|
488
441
|
const factory: EditorFactory = (tui, editorTheme, keybindings) => {
|
|
@@ -531,17 +484,10 @@ export default function contentLayout(pi: ExtensionAPI): void {
|
|
|
531
484
|
owner,
|
|
532
485
|
statusLoaderPatch,
|
|
533
486
|
);
|
|
534
|
-
uninstallRenderPatch(
|
|
535
|
-
BashExecutionComponent.prototype as unknown as PatchableRenderPrototype,
|
|
536
|
-
BASH_EXECUTION_RENDER_PATCH,
|
|
537
|
-
owner,
|
|
538
|
-
bashExecutionPatch,
|
|
539
|
-
);
|
|
540
487
|
assistantPatch = undefined;
|
|
541
488
|
userPatch = undefined;
|
|
542
489
|
systemContainerPatch = undefined;
|
|
543
490
|
statusLoaderPatch = undefined;
|
|
544
|
-
bashExecutionPatch = undefined;
|
|
545
491
|
activeTheme = undefined;
|
|
546
492
|
});
|
|
547
493
|
}
|
package/src/render.ts
CHANGED
|
@@ -88,6 +88,41 @@ function reapplyBackgroundAfterReset(
|
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
function leavesForegroundReset(rawParameters: string): boolean {
|
|
92
|
+
const parameters =
|
|
93
|
+
rawParameters === "" ? [0] : rawParameters.split(";").map(Number);
|
|
94
|
+
let foregroundIsDefault = false;
|
|
95
|
+
for (let index = 0; index < parameters.length; index++) {
|
|
96
|
+
const parameter = parameters[index];
|
|
97
|
+
if (parameter === 38) {
|
|
98
|
+
foregroundIsDefault = false;
|
|
99
|
+
const mode = parameters[index + 1];
|
|
100
|
+
if (mode === 5) index += 2;
|
|
101
|
+
if (mode === 2) index += 4;
|
|
102
|
+
} else if (parameter === 0 || parameter === 39) {
|
|
103
|
+
foregroundIsDefault = true;
|
|
104
|
+
} else if (
|
|
105
|
+
parameter !== undefined &&
|
|
106
|
+
((parameter >= 30 && parameter <= 37) ||
|
|
107
|
+
(parameter >= 90 && parameter <= 97))
|
|
108
|
+
) {
|
|
109
|
+
foregroundIsDefault = false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return foregroundIsDefault;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function paintForeground(text: string, foregroundAnsi: string): string {
|
|
116
|
+
const content = text.replace(
|
|
117
|
+
SGR_PATTERN,
|
|
118
|
+
(sequence, rawParameters: string) =>
|
|
119
|
+
leavesForegroundReset(rawParameters)
|
|
120
|
+
? `${sequence}${foregroundAnsi}`
|
|
121
|
+
: sequence,
|
|
122
|
+
);
|
|
123
|
+
return `${foregroundAnsi}${content}\x1b[39m`;
|
|
124
|
+
}
|
|
125
|
+
|
|
91
126
|
export function paintBackground(
|
|
92
127
|
line: string,
|
|
93
128
|
width: number,
|
|
@@ -113,7 +148,11 @@ function activeBlockLine(
|
|
|
113
148
|
theme: Theme,
|
|
114
149
|
): string {
|
|
115
150
|
const hint = isBoundary ? scrollHint(line) : undefined;
|
|
116
|
-
const body = hint
|
|
151
|
+
const body = hint
|
|
152
|
+
? theme.fg("muted", ` ${hint}`)
|
|
153
|
+
: isBoundary
|
|
154
|
+
? ""
|
|
155
|
+
: paintForeground(line, theme.getFgAnsi("userMessageText"));
|
|
117
156
|
const innerWidth = Math.max(0, width - ACTIVE_SIDE_PADDING * 2);
|
|
118
157
|
const padding = " ".repeat(ACTIVE_SIDE_PADDING);
|
|
119
158
|
return paintBackground(
|
|
@@ -219,62 +258,3 @@ export function renderSubmittedUserLines(
|
|
|
219
258
|
return `${controls}${margin}${rail}${body}${margin}`;
|
|
220
259
|
});
|
|
221
260
|
}
|
|
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
|
-
}
|