pi-render-btw 0.6.0 → 0.6.1
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.
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { BtwOverlayComponent } from "./btw.ts";
|
|
3
|
+
|
|
4
|
+
const theme = {
|
|
5
|
+
bg: (_name: string, text: string) => text,
|
|
6
|
+
fg: (_name: string, text: string) => text,
|
|
7
|
+
bold: (text: string) => text,
|
|
8
|
+
italic: (text: string) => text,
|
|
9
|
+
} as any;
|
|
10
|
+
|
|
11
|
+
const keybindings = { matches: () => false } as any;
|
|
12
|
+
const tui = {
|
|
13
|
+
terminal: { write: () => {} },
|
|
14
|
+
requestRender: () => {},
|
|
15
|
+
} as any;
|
|
16
|
+
|
|
17
|
+
function transcriptLines(entries: unknown[]): string[] {
|
|
18
|
+
const component = new BtwOverlayComponent(
|
|
19
|
+
tui,
|
|
20
|
+
theme,
|
|
21
|
+
keybindings,
|
|
22
|
+
() => entries,
|
|
23
|
+
() => null,
|
|
24
|
+
() => "contextual",
|
|
25
|
+
() => {},
|
|
26
|
+
() => {},
|
|
27
|
+
() => {},
|
|
28
|
+
);
|
|
29
|
+
return (component as any).buildTranscriptLines(80) as string[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
describe("BTW transcript message layout", () => {
|
|
33
|
+
it("renders a user badge on its own line before the prompt", () => {
|
|
34
|
+
const lines = transcriptLines([
|
|
35
|
+
{ id: 1, turnId: 1, type: "user-message", text: "Prompt" },
|
|
36
|
+
]);
|
|
37
|
+
|
|
38
|
+
expect(lines.slice(0, 2)).toEqual([" You ", " Prompt"]);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("keeps assistant heading and response on separate lines", () => {
|
|
42
|
+
const lines = transcriptLines([
|
|
43
|
+
{ id: 1, turnId: 1, type: "assistant-text", text: "Response", streaming: false },
|
|
44
|
+
]);
|
|
45
|
+
|
|
46
|
+
expect(lines[0]).toBe(" Assistant ");
|
|
47
|
+
expect(lines[1].startsWith(" Response")).toBe(true);
|
|
48
|
+
});
|
|
49
|
+
});
|
package/extensions/btw.ts
CHANGED
|
@@ -850,7 +850,7 @@ function buildOverlayTranscript(entries: BtwTranscript, theme: ExtensionContext[
|
|
|
850
850
|
}
|
|
851
851
|
|
|
852
852
|
if (entry.type === "user-message") {
|
|
853
|
-
|
|
853
|
+
pushStackedBlock(userBadge, entry.text, { blankBefore: false });
|
|
854
854
|
continue;
|
|
855
855
|
}
|
|
856
856
|
|
|
@@ -1020,7 +1020,7 @@ function buildTranscriptBadge(
|
|
|
1020
1020
|
return theme.bg(background, theme.fg(foreground, theme.bold(` ${label} `)));
|
|
1021
1021
|
}
|
|
1022
1022
|
|
|
1023
|
-
class BtwOverlayComponent extends Container implements Focusable {
|
|
1023
|
+
export class BtwOverlayComponent extends Container implements Focusable {
|
|
1024
1024
|
private readonly input: TextArea;
|
|
1025
1025
|
private readonly transcript: Container;
|
|
1026
1026
|
private readonly statusText: Text;
|
|
@@ -1179,7 +1179,11 @@ class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1179
1179
|
|
|
1180
1180
|
if (entry.type === "user-message") {
|
|
1181
1181
|
pushBlank();
|
|
1182
|
-
allLines.push(
|
|
1182
|
+
allLines.push(userBadge);
|
|
1183
|
+
const styledLines = wrapTextWithAnsi(entry.text, mdContentWidth);
|
|
1184
|
+
for (const line of styledLines) {
|
|
1185
|
+
allLines.push(`${blockIndent}${line}`);
|
|
1186
|
+
}
|
|
1183
1187
|
continue;
|
|
1184
1188
|
}
|
|
1185
1189
|
|