@narumitw/pi-btw 0.61.1 → 0.62.0
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 +14 -5
- package/dist/index.ts +1067 -557
- package/dist/index.ts.map +4 -4
- package/docs/core-alignment.md +277 -0
- package/docs/native-appearance.md +857 -0
- package/docs/workflows.md +34 -13
- package/package.json +4 -4
- package/src/btw.ts +152 -108
- package/src/conversation-chrome.ts +93 -0
- package/src/fullscreen-renderer.ts +329 -0
- package/src/fullscreen-ui.ts +109 -309
- package/src/keybindings.ts +101 -23
- package/src/menu.ts +42 -27
- package/src/session-lifetime.ts +66 -0
- package/src/transcript-pager.ts +366 -164
- package/src/workspace-layout.ts +96 -36
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { Loader, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
3
|
+
import type { BtwThinkingLevel } from "./side-thread.js";
|
|
4
|
+
import { sanitizeSingleLine } from "./text.js";
|
|
5
|
+
|
|
6
|
+
/** Display-only identity, not a model/session runtime or a source of request options. */
|
|
7
|
+
export interface BtwDisplayModel {
|
|
8
|
+
id: string;
|
|
9
|
+
provider: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface BtwWorkspaceFocus {
|
|
13
|
+
pane: "side" | "main";
|
|
14
|
+
shortcutLabel: string | undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Pi's status classes are not root exports. Use the public Loader extension
|
|
18
|
+
// points to supply the same border text without importing app-owned handlers.
|
|
19
|
+
export class BtwWorkingIndicator extends Loader {
|
|
20
|
+
renderInBorder(width: number): string {
|
|
21
|
+
const line = super.render(width + 2)[1] ?? "";
|
|
22
|
+
return truncateToWidth(line.startsWith(" ") ? line.slice(1).trimEnd() : line.trimEnd(), width, "");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
renderSpinnerInBorder(width: number): string {
|
|
26
|
+
return truncateToWidth(this.getRenderedIndicator(), width, "");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Native CustomEditor's border geometry, through public Editor/Loader hooks. */
|
|
31
|
+
export function renderWorkingBorder(
|
|
32
|
+
width: number,
|
|
33
|
+
hiddenLineCount: number,
|
|
34
|
+
borderColor: (text: string) => string,
|
|
35
|
+
status: BtwWorkingIndicator,
|
|
36
|
+
): string | undefined {
|
|
37
|
+
if (width <= 0) return "";
|
|
38
|
+
let label = status.renderInBorder(Math.max(1, width - 5));
|
|
39
|
+
let labelWidth = visibleWidth(label);
|
|
40
|
+
if (labelWidth === 0) return undefined;
|
|
41
|
+
const overflow = hiddenLineCount > 0 ? ` ↑ ${hiddenLineCount} more ` : undefined;
|
|
42
|
+
const overflowWidth = overflow ? visibleWidth(overflow) : 0;
|
|
43
|
+
const overflowStart = Math.floor((width - overflowWidth) / 2);
|
|
44
|
+
const fitsOverflow = () =>
|
|
45
|
+
overflow !== undefined && overflowWidth + 2 <= width && overflowStart - (3 + labelWidth + 1) >= 1;
|
|
46
|
+
if (overflow && !fitsOverflow()) {
|
|
47
|
+
label = status.renderSpinnerInBorder(width);
|
|
48
|
+
labelWidth = visibleWidth(label);
|
|
49
|
+
}
|
|
50
|
+
if (fitsOverflow()) {
|
|
51
|
+
const leftWidth = 3 + labelWidth + 1;
|
|
52
|
+
return (
|
|
53
|
+
borderColor("── ") +
|
|
54
|
+
label +
|
|
55
|
+
borderColor(
|
|
56
|
+
` ${"─".repeat(overflowStart - leftWidth)}${overflow}${"─".repeat(width - overflowStart - overflowWidth)}`,
|
|
57
|
+
)
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
if (width >= labelWidth + 5) {
|
|
61
|
+
return borderColor("── ") + label + borderColor(` ${"─".repeat(width - labelWidth - 4)}`);
|
|
62
|
+
}
|
|
63
|
+
label = status.renderSpinnerInBorder(width);
|
|
64
|
+
labelWidth = visibleWidth(label);
|
|
65
|
+
const prefix = Math.min(3, Math.max(0, width - labelWidth));
|
|
66
|
+
return borderColor("─".repeat(prefix)) + label + borderColor("─".repeat(Math.max(0, width - prefix - labelWidth)));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function renderConversationFooter(
|
|
70
|
+
width: number,
|
|
71
|
+
theme: Theme,
|
|
72
|
+
options: {
|
|
73
|
+
model?: BtwDisplayModel;
|
|
74
|
+
thinkingLevel?: BtwThinkingLevel;
|
|
75
|
+
focus?: BtwWorkspaceFocus;
|
|
76
|
+
hint: string;
|
|
77
|
+
warning?: boolean;
|
|
78
|
+
},
|
|
79
|
+
): string[] {
|
|
80
|
+
if (width < 3) return [];
|
|
81
|
+
const focus = options.focus ? `${options.focus.pane === "side" ? "BTW" : "Main"} focus` : undefined;
|
|
82
|
+
const left = focus && visibleWidth(`btw · ${focus}`) <= width ? `btw · ${focus}` : "btw";
|
|
83
|
+
const model = options.model ? sanitizeSingleLine(`${options.model.provider}/${options.model.id}`) : "";
|
|
84
|
+
const thinking = options.thinkingLevel ? `thinking ${options.thinkingLevel}` : "";
|
|
85
|
+
const right = [[model, thinking].filter(Boolean).join(" • "), thinking, model].find(
|
|
86
|
+
(value) => value && visibleWidth(left) + 2 + visibleWidth(value) <= width,
|
|
87
|
+
);
|
|
88
|
+
const identity = right ? `${left}${" ".repeat(width - visibleWidth(left) - visibleWidth(right))}${right}` : left;
|
|
89
|
+
return [
|
|
90
|
+
theme.fg("dim", identity),
|
|
91
|
+
...(options.hint ? [theme.fg(options.warning ? "warning" : "muted", options.hint)] : []),
|
|
92
|
+
];
|
|
93
|
+
}
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import {
|
|
4
|
+
type Component,
|
|
5
|
+
isKeyRelease,
|
|
6
|
+
isKittyProtocolActive,
|
|
7
|
+
Key,
|
|
8
|
+
type KeybindingsManager,
|
|
9
|
+
parseKey,
|
|
10
|
+
type ScrollView,
|
|
11
|
+
type TUI,
|
|
12
|
+
TuiAltScreen,
|
|
13
|
+
type TuiInputListener,
|
|
14
|
+
type TuiInputListenerResult,
|
|
15
|
+
type TuiStopOptions,
|
|
16
|
+
} from "@earendil-works/pi-tui";
|
|
17
|
+
import { formatKeyLabel, sanitizeSingleLine } from "./text.js";
|
|
18
|
+
|
|
19
|
+
export type BtwFullscreenTui = TUI & {
|
|
20
|
+
flash?: (message: string, durationMs?: number) => void;
|
|
21
|
+
setLayoutRoot(component: Component | undefined): void;
|
|
22
|
+
hasFocusedOverlay?(): boolean;
|
|
23
|
+
addInputListenerBeforeAll?(listener: TuiInputListener): () => void;
|
|
24
|
+
addInputListenerBeforeViewport?(listener: TuiInputListener): () => void;
|
|
25
|
+
setViewportTarget?(scrollView: ScrollView | undefined): void;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
type BtwInputListeners = {
|
|
29
|
+
beforeAll: Set<TuiInputListener>;
|
|
30
|
+
beforeViewport: Set<TuiInputListener>;
|
|
31
|
+
regular: Set<TuiInputListener>;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const btwInputListeners = new WeakMap<BtwTuiAltScreen, BtwInputListeners>();
|
|
35
|
+
|
|
36
|
+
function dispatchBtwInput(listeners: BtwInputListeners, data: string): TuiInputListenerResult {
|
|
37
|
+
let current = data;
|
|
38
|
+
for (const group of [listeners.beforeAll, listeners.beforeViewport, listeners.regular]) {
|
|
39
|
+
for (const listener of group) {
|
|
40
|
+
const result = listener(current);
|
|
41
|
+
if (result?.consume) return result;
|
|
42
|
+
if (result?.data !== undefined) current = result.data;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return current === data ? undefined : { data: current };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
class BtwTuiAltScreen extends TuiAltScreen {
|
|
49
|
+
private terminalActive = false;
|
|
50
|
+
|
|
51
|
+
protected override beforeTerminalStart(): void {
|
|
52
|
+
super.beforeTerminalStart();
|
|
53
|
+
this.terminalActive = true;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
protected override beforeTerminalStop(options: TuiStopOptions): void {
|
|
57
|
+
this.terminalActive = false;
|
|
58
|
+
super.beforeTerminalStop(options);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
override flash(message: string, durationMs?: number): void {
|
|
62
|
+
// Native clipboard callbacks cannot be cancelled. A late result must not
|
|
63
|
+
// create flash timers or redraw the terminal after ownership has moved.
|
|
64
|
+
if (this.terminalActive) super.flash(message, durationMs);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
hasFocusedOverlay(): boolean {
|
|
68
|
+
return this.isOverlayFocused();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
setViewportTarget(scrollView: ScrollView | undefined): void {
|
|
72
|
+
const layout: unknown = Reflect.get(this, "currentLayout");
|
|
73
|
+
if (layout === undefined) return;
|
|
74
|
+
if (typeof layout !== "object" || layout === null || !Reflect.set(layout, "primaryScrollView", scrollView)) {
|
|
75
|
+
throw new Error("Pi BTW cannot route this fullscreen layout; update Pi.");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
override addInputListener(listener: TuiInputListener): () => void {
|
|
80
|
+
let listeners = btwInputListeners.get(this);
|
|
81
|
+
if (!listeners) {
|
|
82
|
+
const registeredListeners: BtwInputListeners = {
|
|
83
|
+
beforeAll: new Set(),
|
|
84
|
+
beforeViewport: new Set(),
|
|
85
|
+
regular: new Set(),
|
|
86
|
+
};
|
|
87
|
+
btwInputListeners.set(this, registeredListeners);
|
|
88
|
+
super.addInputListener((data) => dispatchBtwInput(registeredListeners, data));
|
|
89
|
+
listeners = registeredListeners;
|
|
90
|
+
}
|
|
91
|
+
listeners.regular.add(listener);
|
|
92
|
+
return () => listeners.regular.delete(listener);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
addInputListenerBeforeAll(listener: TuiInputListener): () => void {
|
|
96
|
+
const listeners = btwInputListeners.get(this);
|
|
97
|
+
if (!listeners) return super.addInputListener(listener);
|
|
98
|
+
listeners.beforeAll.add(listener);
|
|
99
|
+
return () => listeners.beforeAll.delete(listener);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
addInputListenerBeforeViewport(listener: TuiInputListener): () => void {
|
|
103
|
+
const listeners = btwInputListeners.get(this);
|
|
104
|
+
if (!listeners) return super.addInputListener(listener);
|
|
105
|
+
listeners.beforeViewport.add(listener);
|
|
106
|
+
return () => listeners.beforeViewport.delete(listener);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
override removeInputListener(listener: TuiInputListener): void {
|
|
110
|
+
const listeners = btwInputListeners.get(this);
|
|
111
|
+
if (!listeners) {
|
|
112
|
+
super.removeInputListener(listener);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
listeners.beforeAll.delete(listener);
|
|
116
|
+
listeners.beforeViewport.delete(listener);
|
|
117
|
+
listeners.regular.delete(listener);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const BRACKETED_PASTE_START = "\u001b[200~";
|
|
122
|
+
const BRACKETED_PASTE_END = "\u001b[201~";
|
|
123
|
+
|
|
124
|
+
// TuiAltScreen evaluates these actions before bottom, so shared keys cannot jump to latest.
|
|
125
|
+
const ALT_SCREEN_ACTIONS_BEFORE_BOTTOM = [
|
|
126
|
+
"tui.altScreen.search",
|
|
127
|
+
"tui.altScreen.searchNext",
|
|
128
|
+
"tui.altScreen.searchPrevious",
|
|
129
|
+
"tui.altScreen.searchClose",
|
|
130
|
+
"tui.altScreen.pageUp",
|
|
131
|
+
"tui.altScreen.pageDown",
|
|
132
|
+
"tui.altScreen.halfPageUp",
|
|
133
|
+
"tui.altScreen.halfPageDown",
|
|
134
|
+
"tui.altScreen.lineUp",
|
|
135
|
+
"tui.altScreen.lineDown",
|
|
136
|
+
"tui.altScreen.previousPrompt",
|
|
137
|
+
"tui.altScreen.nextPrompt",
|
|
138
|
+
"tui.altScreen.top",
|
|
139
|
+
] as const;
|
|
140
|
+
const KEY_MODIFIER_ORDER = ["shift", "ctrl", "alt", "super"] as const;
|
|
141
|
+
const MATCHABLE_SPECIAL_KEYS = new Set([
|
|
142
|
+
"space",
|
|
143
|
+
"tab",
|
|
144
|
+
"enter",
|
|
145
|
+
"backspace",
|
|
146
|
+
"delete",
|
|
147
|
+
"insert",
|
|
148
|
+
"home",
|
|
149
|
+
"end",
|
|
150
|
+
"pageup",
|
|
151
|
+
"pagedown",
|
|
152
|
+
"up",
|
|
153
|
+
"down",
|
|
154
|
+
"left",
|
|
155
|
+
"right",
|
|
156
|
+
]);
|
|
157
|
+
const MATCHABLE_SYMBOL_KEYS = new Set("`-=[]\\;',./!@#$%^&*()_+|~{}:<>?");
|
|
158
|
+
|
|
159
|
+
function normalizedKeyId(key: string): string {
|
|
160
|
+
const parts = key.toLowerCase().split("+");
|
|
161
|
+
const base = parts.at(-1);
|
|
162
|
+
if (!base) return "";
|
|
163
|
+
const configuredModifiers = parts.slice(0, -1);
|
|
164
|
+
if (
|
|
165
|
+
new Set(configuredModifiers).size !== configuredModifiers.length ||
|
|
166
|
+
configuredModifiers.some((modifier) => !KEY_MODIFIER_ORDER.includes(modifier as never))
|
|
167
|
+
)
|
|
168
|
+
return "";
|
|
169
|
+
const normalizedBase = base === "esc" ? "escape" : base === "return" ? "enter" : base;
|
|
170
|
+
const modifiers = KEY_MODIFIER_ORDER.filter((modifier) => parts.includes(modifier));
|
|
171
|
+
return [...modifiers, normalizedBase].join("+");
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function formatEffectiveKeyLabel(key: string): string {
|
|
175
|
+
const parts = key.split("+");
|
|
176
|
+
const base = parts.at(-1);
|
|
177
|
+
if (base === "pageup") parts[parts.length - 1] = "pageUp";
|
|
178
|
+
if (base === "pagedown") parts[parts.length - 1] = "pageDown";
|
|
179
|
+
return formatKeyLabel(parts.join("+"));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function canMatchKeyInput(key: string): boolean {
|
|
183
|
+
const parts = key.split("+");
|
|
184
|
+
const base = parts.at(-1) ?? "";
|
|
185
|
+
const modifiers = parts.slice(0, -1);
|
|
186
|
+
if (base === "escape") return modifiers.length === 0;
|
|
187
|
+
if (base === "clear") {
|
|
188
|
+
return modifiers.length === 0 || (modifiers.length === 1 && (modifiers[0] === "shift" || modifiers[0] === "ctrl"));
|
|
189
|
+
}
|
|
190
|
+
if (/^f(?:[1-9]|1[0-2])$/u.test(base)) return modifiers.length === 0;
|
|
191
|
+
return (
|
|
192
|
+
MATCHABLE_SPECIAL_KEYS.has(base) ||
|
|
193
|
+
(base.length === 1 && (/^[a-z0-9]$/u.test(base) || MATCHABLE_SYMBOL_KEYS.has(base)))
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function rawCtrlInput(base: string): string | undefined {
|
|
198
|
+
if (base.length !== 1) return undefined;
|
|
199
|
+
const rawBase = base === "-" ? "_" : base;
|
|
200
|
+
if (!"abcdefghijklmnopqrstuvwxyz[\\]_".includes(rawBase)) return undefined;
|
|
201
|
+
return String.fromCharCode(rawBase.charCodeAt(0) & 0x1f);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function legacyRawInput(key: string): string | undefined {
|
|
205
|
+
const parts = key.split("+");
|
|
206
|
+
const base = parts.at(-1) ?? "";
|
|
207
|
+
if (parts.length === 2 && parts[0] === "ctrl") return rawCtrlInput(base);
|
|
208
|
+
if (isKittyProtocolActive()) return undefined;
|
|
209
|
+
if (parts.length === 2 && parts[0] === "alt" && base.length === 1) return `\u001b${base}`;
|
|
210
|
+
if (parts.length === 3 && parts[0] === "ctrl" && parts[1] === "alt") {
|
|
211
|
+
const input = rawCtrlInput(base);
|
|
212
|
+
return input ? `\u001b${input}` : undefined;
|
|
213
|
+
}
|
|
214
|
+
return undefined;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Mirror matchesKey(), using parseKey() to canonicalize IDs that share legacy raw input.
|
|
218
|
+
function keyInputIdentity(key: string): string {
|
|
219
|
+
const identity = normalizedKeyId(key);
|
|
220
|
+
const input = legacyRawInput(identity);
|
|
221
|
+
return input ? normalizedKeyId(parseKey(input) ?? identity) : identity;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export function hasManualSelectionCopyApi(): boolean {
|
|
225
|
+
return (
|
|
226
|
+
typeof TuiAltScreen.prototype.hasActiveSelection === "function" &&
|
|
227
|
+
typeof TuiAltScreen.prototype.copyActiveSelectionToClipboard === "function"
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export function createBtwFullscreenTui(
|
|
232
|
+
parent: TUI,
|
|
233
|
+
theme: Theme,
|
|
234
|
+
keybindings: KeybindingsManager,
|
|
235
|
+
copyOnSelect: boolean,
|
|
236
|
+
manualSelectionCopySupported: boolean,
|
|
237
|
+
openUrl: (url: string) => void,
|
|
238
|
+
copyToClipboard: (text: string) => Promise<void>,
|
|
239
|
+
): BtwFullscreenTui {
|
|
240
|
+
if (!copyOnSelect && !manualSelectionCopySupported) {
|
|
241
|
+
throw new Error(
|
|
242
|
+
"Manual fullscreen selection copying is unavailable in this Pi version; update Pi or enable automatic selection copying.",
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
const styleSearchMatch = (text: string) => theme.bg("searchMatchBg", theme.fg("searchMatchText", text));
|
|
246
|
+
const fullscreen = new BtwTuiAltScreen(parent.terminal, parent.getShowHardwareCursor(), undefined, {
|
|
247
|
+
mouse: true,
|
|
248
|
+
wheelScrollLines: "auto",
|
|
249
|
+
copyOnSelect,
|
|
250
|
+
searchMatchStyle: (text) => theme.underline(styleSearchMatch(text)),
|
|
251
|
+
scrollToEndIndicator: () => {
|
|
252
|
+
const unavailableKeyIdentities = new Set<string>([keyInputIdentity(Key.ctrl("c"))]);
|
|
253
|
+
for (const action of ALT_SCREEN_ACTIONS_BEFORE_BOTTOM) {
|
|
254
|
+
for (const actionKey of keybindings.getKeys(action)) {
|
|
255
|
+
unavailableKeyIdentities.add(keyInputIdentity(String(actionKey)));
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (!copyOnSelect) {
|
|
259
|
+
for (const copyKey of keybindings.getKeys("app.message.copy")) {
|
|
260
|
+
unavailableKeyIdentities.add(keyInputIdentity(String(copyKey)));
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
const key = keybindings
|
|
264
|
+
.getKeys("tui.altScreen.bottom")
|
|
265
|
+
.map((candidate) => keyInputIdentity(String(candidate)))
|
|
266
|
+
.find(
|
|
267
|
+
(identity) =>
|
|
268
|
+
identity &&
|
|
269
|
+
canMatchKeyInput(identity) &&
|
|
270
|
+
!unavailableKeyIdentities.has(identity) &&
|
|
271
|
+
formatEffectiveKeyLabel(identity),
|
|
272
|
+
);
|
|
273
|
+
const label = theme.fg("text", " ↓ Jump to latest message");
|
|
274
|
+
const shortcut = key ? theme.fg("muted", ` · ${formatEffectiveKeyLabel(key)}`) : "";
|
|
275
|
+
return theme.bg("selectedBg", `${label}${shortcut} `);
|
|
276
|
+
},
|
|
277
|
+
searchCurrentMatchStyle: (text) => theme.bold(theme.inverse(styleSearchMatch(text))),
|
|
278
|
+
searchNavigationButtonStyle: (text, hovered) => (hovered ? theme.underline(text) : text),
|
|
279
|
+
openUrl,
|
|
280
|
+
copySelection: async (text) => {
|
|
281
|
+
try {
|
|
282
|
+
await copyToClipboard(text);
|
|
283
|
+
return true;
|
|
284
|
+
} catch (error) {
|
|
285
|
+
return sanitizeSingleLine(error instanceof Error ? error.message : String(error)) || "Copy failed";
|
|
286
|
+
}
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
if (!copyOnSelect) {
|
|
290
|
+
let isInBracketedPaste = false;
|
|
291
|
+
fullscreen.addInputListenerBeforeViewport((data) => {
|
|
292
|
+
const wasInBracketedPaste = isInBracketedPaste;
|
|
293
|
+
const startsBracketedPaste = data.includes(BRACKETED_PASTE_START);
|
|
294
|
+
if (startsBracketedPaste) isInBracketedPaste = true;
|
|
295
|
+
if (isInBracketedPaste && data.includes(BRACKETED_PASTE_END)) {
|
|
296
|
+
isInBracketedPaste = false;
|
|
297
|
+
}
|
|
298
|
+
if (
|
|
299
|
+
wasInBracketedPaste ||
|
|
300
|
+
startsBracketedPaste ||
|
|
301
|
+
fullscreen.hasFocusedOverlay() ||
|
|
302
|
+
isKeyRelease(data) ||
|
|
303
|
+
!keybindings.matches(data, "app.message.copy")
|
|
304
|
+
) {
|
|
305
|
+
return undefined;
|
|
306
|
+
}
|
|
307
|
+
if (!fullscreen.hasActiveSelection()) {
|
|
308
|
+
fullscreen.flash("No selection to copy");
|
|
309
|
+
return { consume: true };
|
|
310
|
+
}
|
|
311
|
+
void fullscreen.copyActiveSelectionToClipboard().catch(() => fullscreen.flash("Copy failed"));
|
|
312
|
+
return { consume: true };
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
return fullscreen;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// Pi does not export its browser opener, so mirror its shell-free launcher for this isolated TUI.
|
|
319
|
+
export function openUrlInBrowser(target: string): void {
|
|
320
|
+
const [command, args] =
|
|
321
|
+
process.platform === "darwin"
|
|
322
|
+
? ["open", [target]]
|
|
323
|
+
: process.platform === "win32"
|
|
324
|
+
? ["rundll32", ["url.dll,FileProtocolHandler", target]]
|
|
325
|
+
: ["xdg-open", [target]];
|
|
326
|
+
spawn(command, args, { stdio: "ignore", detached: true })
|
|
327
|
+
.on("error", () => {})
|
|
328
|
+
.unref();
|
|
329
|
+
}
|