Skip to content

Commit dd8362c

Browse files
Copilotsawka
andcommitted
chore: finalize osc 16162 readback validation
Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
1 parent 0c131d9 commit dd8362c

2 files changed

Lines changed: 7 additions & 9 deletions

File tree

frontend/app/view/term/osc-handlers.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,20 +125,21 @@ function handleShellIntegrationInputReadback(
125125
cmd: { command: "I"; data: { buffer64?: string; cursor?: number } },
126126
rtInfo: ObjRTInfo
127127
): void {
128-
if (cmd.data.buffer64 == null || cmd.data.cursor == null) {
128+
const { buffer64, cursor } = cmd.data;
129+
if (buffer64 == null || typeof cursor != "number" || !isFinite(cursor)) {
129130
return;
130131
}
131132
let decodedBuffer: string;
132133
try {
133-
decodedBuffer = base64ToString(cmd.data.buffer64);
134+
decodedBuffer = base64ToString(buffer64);
134135
} catch (e) {
135136
console.error("Error decoding shell input buffer64:", e);
136137
return;
137138
}
138-
rtInfo["shell:inputbuffer64"] = cmd.data.buffer64;
139-
rtInfo["shell:inputcursor"] = cmd.data.cursor;
139+
rtInfo["shell:inputbuffer64"] = buffer64;
140+
rtInfo["shell:inputcursor"] = cursor;
140141
globalStore.set(termWrap.shellInputBufferAtom, decodedBuffer);
141-
globalStore.set(termWrap.shellInputCursorAtom, cmd.data.cursor);
142+
globalStore.set(termWrap.shellInputCursorAtom, cursor);
142143
}
143144

144145
// for xterm OSC handlers, we return true always because we "own" the OSC number.
@@ -311,11 +312,7 @@ export function handleOsc16162Command(data: string, blockId: string, loaded: boo
311312
switch (cmd.command) {
312313
case "A": {
313314
rtInfo["shell:state"] = "ready";
314-
rtInfo["shell:inputbuffer64"] = "";
315-
rtInfo["shell:inputcursor"] = 0;
316315
globalStore.set(termWrap.shellIntegrationStatusAtom, "ready");
317-
globalStore.set(termWrap.shellInputBufferAtom, "");
318-
globalStore.set(termWrap.shellInputCursorAtom, 0);
319316
const marker = terminal.registerMarker(0);
320317
if (marker) {
321318
termWrap.promptMarkers.push(marker);

pkg/util/shellutil/shellintegration/zsh_zshrc.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ _waveterm_si_preexec() {
113113
_waveterm_si_inputreadback() {
114114
_waveterm_si_blocked && return
115115
local buffer64 cursor
116+
# base64 may wrap lines on some platforms, so strip newlines before embedding JSON
116117
buffer64=$(printf '%s' "$BUFFER" | base64 2>/dev/null | tr -d '\n\r')
117118
cursor=$CURSOR
118119
zle -I

0 commit comments

Comments
 (0)