diff --git a/src/ui/TerminalPane.tsx b/src/ui/TerminalPane.tsx index 178bd2d..a4caa4b 100644 --- a/src/ui/TerminalPane.tsx +++ b/src/ui/TerminalPane.tsx @@ -164,6 +164,15 @@ function attachServer(session: T3Session, target: TerminalTarget, term: Embedded }; } +/** + * The emulator's answers, except that it doesn't know in-band resize (mode 2048). It says it + * does, but never sends the reports, and a program that takes it at its word, like Neovim, + * stops listening for SIGWINCH and so never sees the pane change size. + */ +function withoutInBandResize(data: Uint8Array): Uint8Array { + return Buffer.from(Buffer.from(data).toString("latin1").replace(/\x1b\[\?2048;\d\$y/g, "\x1b[?2048;0$y"), "latin1"); +} + /** A program run here on its own pty, answering its terminal queries through the emulator. */ function spawnLocal(program: Extract, term: EmbeddedTerminalRenderable, cols: number, rows: number, close: (message?: string) => void): Link { let stopped = false; @@ -178,7 +187,7 @@ function spawnLocal(program: Extract, term: Embe close(); }); return { - send: (data) => void child.terminal?.write(data), + send: (data, source) => void child.terminal?.write(source === "response" ? withoutInBandResize(data) : data), resize: (next, height) => child.terminal?.resize(next, height), stop: () => { if (stopped) return; diff --git a/test/app/pane.test.tsx b/test/app/pane.test.tsx index 2b2bfca..119ace3 100644 --- a/test/app/pane.test.tsx +++ b/test/app/pane.test.tsx @@ -371,6 +371,16 @@ describe("terminal drawer", () => { expect(zoomed).toBeGreaterThan(rows); expect(app.frame()).toContain(`bottom ${zoomed} `); }); + + test("$EDITOR is told in-band resize isn't available, since no reports would come and it would miss the pane's size changing", async () => { + // It asks about mode 2048, as Neovim does, and shows the answer without its escape. + setEditor(`stty raw -echo; printf '\\033[?2048$p'; head -c 11 | tr -d '\\033'; sleep 5 #`); + const app = await open(); + await app.press("i"); + await app.press("g", { ctrl: true }); + await waitFor(() => app.frame().includes("?2048;")); + expect(app.frame()).toContain("[?2048;0$y"); + }); }); describe("the panes together", () => {