TUI: coalesce multiline paste submits on macOS terminals

This commit is contained in:
Vignesh Natarajan
2026-02-21 19:19:55 -08:00
parent f2d664e24f
commit a10d689860
3 changed files with 37 additions and 3 deletions

View File

@@ -130,10 +130,32 @@ describe("shouldEnableWindowsGitBashPasteFallback", () => {
).toBe(true);
});
it("disables fallback outside Windows", () => {
it("enables fallback on macOS iTerm", () => {
expect(
shouldEnableWindowsGitBashPasteFallback({
platform: "darwin",
env: {
TERM_PROGRAM: "iTerm.app",
} as NodeJS.ProcessEnv,
}),
).toBe(true);
});
it("enables fallback on macOS Terminal.app", () => {
expect(
shouldEnableWindowsGitBashPasteFallback({
platform: "darwin",
env: {
TERM_PROGRAM: "Apple_Terminal",
} as NodeJS.ProcessEnv,
}),
).toBe(true);
});
it("disables fallback outside Windows", () => {
expect(
shouldEnableWindowsGitBashPasteFallback({
platform: "linux",
env: {
MSYSTEM: "MINGW64",
} as NodeJS.ProcessEnv,

View File

@@ -84,13 +84,24 @@ export function shouldEnableWindowsGitBashPasteFallback(params?: {
env?: NodeJS.ProcessEnv;
}): boolean {
const platform = params?.platform ?? process.platform;
const env = params?.env ?? process.env;
const termProgram = (env.TERM_PROGRAM ?? "").toLowerCase();
// Some macOS terminals emit multiline paste as rapid single-line submits.
// Enable burst coalescing so pasted blocks stay as one user message.
if (platform === "darwin") {
if (termProgram.includes("iterm") || termProgram.includes("apple_terminal")) {
return true;
}
return false;
}
if (platform !== "win32") {
return false;
}
const env = params?.env ?? process.env;
const msystem = (env.MSYSTEM ?? "").toUpperCase();
const shell = env.SHELL ?? "";
const termProgram = (env.TERM_PROGRAM ?? "").toLowerCase();
if (msystem.startsWith("MINGW") || msystem.startsWith("MSYS")) {
return true;
}