pi-render-btw 0.6.8 → 0.6.9
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 +1 -0
- package/extensions/btw-transcript.test.ts +21 -1
- package/extensions/btw.ts +34 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -94,6 +94,7 @@ pi install /path/to/pi-render-btw
|
|
|
94
94
|
- `Alt+/` toggles focus between BTW and the main editor without closing the overlay
|
|
95
95
|
- `Ctrl+Alt+W` is a fallback focus toggle for terminals that do not deliver `Alt+/` as a usable shortcut
|
|
96
96
|
- `Ctrl+G` opens the current BTW draft in `$VISUAL`/`$EDITOR` (falling back to `nano`) and reads it back when the editor exits successfully
|
|
97
|
+
- the composer uses Pi's native editor behavior for undo, paste, prompt history, and Tab file-path completion relative to the BTW working directory
|
|
97
98
|
- `Esc` still dismisses BTW immediately while the overlay is focused
|
|
98
99
|
- BTW opens top-centered so the main session remains visible underneath it
|
|
99
100
|
|
|
@@ -10,8 +10,10 @@ const theme = {
|
|
|
10
10
|
|
|
11
11
|
const keybindings = { matches: () => false } as any;
|
|
12
12
|
const tui = {
|
|
13
|
-
terminal: { write: () => {} },
|
|
13
|
+
terminal: { write: () => {}, rows: 30 },
|
|
14
14
|
requestRender: () => {},
|
|
15
|
+
start: () => {},
|
|
16
|
+
stop: () => {},
|
|
15
17
|
} as any;
|
|
16
18
|
|
|
17
19
|
function transcriptLines(entries: unknown[]): string[] {
|
|
@@ -120,6 +122,24 @@ describe("BTW transcript message layout", () => {
|
|
|
120
122
|
expect(component.render(80).join("\n")).toContain("q:exit");
|
|
121
123
|
});
|
|
122
124
|
|
|
125
|
+
it("setDraft/getDraft round-trips through editor getText/setText", () => {
|
|
126
|
+
const component = new BtwOverlayComponent(
|
|
127
|
+
tui,
|
|
128
|
+
theme,
|
|
129
|
+
keybindings,
|
|
130
|
+
() => [],
|
|
131
|
+
() => null,
|
|
132
|
+
() => "contextual",
|
|
133
|
+
() => {},
|
|
134
|
+
() => {},
|
|
135
|
+
() => {},
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
const testValue = "hello from the editor";
|
|
139
|
+
component.setDraft(testValue);
|
|
140
|
+
expect(component.getDraft()).toBe(testValue);
|
|
141
|
+
});
|
|
142
|
+
|
|
123
143
|
it("routes Ctrl+G to the external-editor callback", () => {
|
|
124
144
|
let opened = 0;
|
|
125
145
|
const externalKeybindings = {
|
package/extensions/btw.ts
CHANGED
|
@@ -32,7 +32,8 @@ import {
|
|
|
32
32
|
type OverlayHandle,
|
|
33
33
|
type TUI,
|
|
34
34
|
} from "@earendil-works/pi-tui";
|
|
35
|
-
import {
|
|
35
|
+
import { CustomEditor } from "@earendil-works/pi-coding-agent";
|
|
36
|
+
import { CombinedAutocompleteProvider, type EditorTheme } from "@earendil-works/pi-tui";
|
|
36
37
|
import {
|
|
37
38
|
buildPeekBlocks,
|
|
38
39
|
createPeekState,
|
|
@@ -1038,7 +1039,7 @@ function buildTranscriptBadge(
|
|
|
1038
1039
|
}
|
|
1039
1040
|
|
|
1040
1041
|
export class BtwOverlayComponent extends Container implements Focusable {
|
|
1041
|
-
private readonly input:
|
|
1042
|
+
private readonly input: CustomEditor;
|
|
1042
1043
|
private readonly transcript: Container;
|
|
1043
1044
|
private readonly statusText: Text;
|
|
1044
1045
|
private readonly modeText: Text;
|
|
@@ -1092,6 +1093,7 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1092
1093
|
onDismiss: () => void,
|
|
1093
1094
|
onUnfocus: () => void,
|
|
1094
1095
|
onExternalEditor?: () => void,
|
|
1096
|
+
cwd?: string,
|
|
1095
1097
|
) {
|
|
1096
1098
|
super();
|
|
1097
1099
|
this.tui = tui;
|
|
@@ -1109,8 +1111,22 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1109
1111
|
this.transcript = new Container();
|
|
1110
1112
|
this.statusText = new Text("", 1, 0);
|
|
1111
1113
|
|
|
1112
|
-
|
|
1114
|
+
const editorTheme: EditorTheme = {
|
|
1115
|
+
borderColor: (text: string) => theme.fg("borderMuted", text),
|
|
1116
|
+
selectList: {
|
|
1117
|
+
selectedPrefix: (text: string) => theme.fg("accent", text),
|
|
1118
|
+
selectedText: (text: string) => theme.fg("accent", text),
|
|
1119
|
+
description: (text: string) => theme.fg("muted", text),
|
|
1120
|
+
scrollInfo: (text: string) => theme.fg("muted", text),
|
|
1121
|
+
noMatch: (text: string) => theme.fg("muted", text),
|
|
1122
|
+
},
|
|
1123
|
+
};
|
|
1124
|
+
// Pi may expose KeybindingsManager from a different installed package copy;
|
|
1125
|
+
// both variants provide the runtime `matches()` interface CustomEditor uses.
|
|
1126
|
+
const editorKeybindings = keybindings as unknown as ConstructorParameters<typeof CustomEditor>[2];
|
|
1127
|
+
this.input = new CustomEditor(tui, editorTheme, editorKeybindings);
|
|
1113
1128
|
this.input.onSubmit = (value) => {
|
|
1129
|
+
this.input.addToHistory(value);
|
|
1114
1130
|
this.followTranscript = true;
|
|
1115
1131
|
this.onSubmitCallback(value);
|
|
1116
1132
|
};
|
|
@@ -1118,6 +1134,11 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1118
1134
|
this.onDismissCallback();
|
|
1119
1135
|
};
|
|
1120
1136
|
|
|
1137
|
+
// Wire up autocomplete (file-path completion only, no commands)
|
|
1138
|
+
const cwdPath = cwd ?? process.cwd();
|
|
1139
|
+
const autocompleteProvider = new CombinedAutocompleteProvider([], cwdPath);
|
|
1140
|
+
this.input.setAutocompleteProvider(autocompleteProvider);
|
|
1141
|
+
|
|
1121
1142
|
this.peekState = createPeekState();
|
|
1122
1143
|
this.hintsText = new Text("", 1, 0);
|
|
1123
1144
|
this.mdTheme = getMarkdownTheme();
|
|
@@ -1137,19 +1158,16 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1137
1158
|
}
|
|
1138
1159
|
|
|
1139
1160
|
// app.clear with non-empty input → clear input
|
|
1140
|
-
if (keybindings.matches(data, "app.clear") && this.input.
|
|
1141
|
-
this.input.
|
|
1161
|
+
if (keybindings.matches(data, "app.clear") && this.input.getText().length > 0) {
|
|
1162
|
+
this.input.setText("");
|
|
1142
1163
|
this.tui.requestRender();
|
|
1143
1164
|
return;
|
|
1144
1165
|
}
|
|
1145
1166
|
|
|
1146
1167
|
// Everything else (including Escape → dismiss, Enter → submit,
|
|
1147
|
-
// Ctrl+Enter → newline) goes to
|
|
1168
|
+
// Ctrl+Enter → newline) goes to CustomEditor's own handler
|
|
1169
|
+
// (CustomEditor delegates app keybindings, then Editor).
|
|
1148
1170
|
originalHandleInput(data);
|
|
1149
|
-
|
|
1150
|
-
// After TextArea processed the key, check if Escape was pressed
|
|
1151
|
-
// (TextArea calls onEscape which calls onDismissCallback).
|
|
1152
|
-
// tui.select.cancel is handled by TextArea internally.
|
|
1153
1171
|
};
|
|
1154
1172
|
|
|
1155
1173
|
this.refresh();
|
|
@@ -1165,7 +1183,7 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1165
1183
|
const filePath = path.join(dir, "prompt.md");
|
|
1166
1184
|
|
|
1167
1185
|
try {
|
|
1168
|
-
writeFileSync(filePath, this.input.
|
|
1186
|
+
writeFileSync(filePath, this.input.getText(), "utf8");
|
|
1169
1187
|
this.tui.stop();
|
|
1170
1188
|
process.stdout.write(`Launching external editor: ${editorCommand}\nPi will resume when the editor exits.\n`);
|
|
1171
1189
|
|
|
@@ -1179,7 +1197,7 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1179
1197
|
});
|
|
1180
1198
|
|
|
1181
1199
|
if (status === 0) {
|
|
1182
|
-
this.input.
|
|
1200
|
+
this.input.setText(readFileSync(filePath, "utf8").replace(/\n$/, ""));
|
|
1183
1201
|
}
|
|
1184
1202
|
} finally {
|
|
1185
1203
|
rmSync(dir, { recursive: true, force: true });
|
|
@@ -1467,12 +1485,12 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1467
1485
|
}
|
|
1468
1486
|
|
|
1469
1487
|
setDraft(value: string): void {
|
|
1470
|
-
this.input.
|
|
1488
|
+
this.input.setText(value);
|
|
1471
1489
|
this.tui.requestRender();
|
|
1472
1490
|
}
|
|
1473
1491
|
|
|
1474
1492
|
getDraft(): string {
|
|
1475
|
-
return this.input.
|
|
1493
|
+
return this.input.getText();
|
|
1476
1494
|
}
|
|
1477
1495
|
|
|
1478
1496
|
getTranscriptEntries(): BtwTranscript {
|
|
@@ -2368,6 +2386,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
2368
2386
|
overlayRuntime?.handle?.unfocus();
|
|
2369
2387
|
overlayRuntime?.refresh?.();
|
|
2370
2388
|
},
|
|
2389
|
+
undefined,
|
|
2390
|
+
ctx.cwd,
|
|
2371
2391
|
);
|
|
2372
2392
|
|
|
2373
2393
|
overlay.focused = runtime.handle?.isFocused() ?? true;
|