Răsfoiți Sursa

fix(tui): only use alternate screen buffer on Terminal.app

The alternate screen disables terminal scrollback. Only enable it
on Terminal.app where it's needed to prevent IME XPC crashes.
Other terminals (iTerm2, etc.) keep native scrolling.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
fanghanjun 7 luni în urmă
părinte
comite
e80a41def7
1 a modificat fișierele cu 10 adăugiri și 7 ștergeri
  1. 10 7
      packages/cli/src/tui/app.ts

+ 10 - 7
packages/cli/src/tui/app.ts

@@ -186,13 +186,14 @@ export async function launchTui(
     return (originalStderrWrite as Function)(chunk, ...args);
   };
 
-  // Enter alternate screen buffer — isolates Ink rendering from the primary
-  // terminal view. This prevents IME XPC corruption on Terminal.app (the IME's
+  // Terminal.app only: enter alternate screen buffer to isolate Ink rendering
+  // from the primary terminal view. This prevents IME XPC corruption (the IME's
   // NSRemoteView interacts with the primary screen; the alt screen is separate).
-  // Claude Code uses the same approach via <AlternateScreen> + DEC 1049.
-  const ENTER_ALT = "\x1b[?1049h";
-  const EXIT_ALT = "\x1b[?1049l";
-  process.stdout.write(ENTER_ALT);
+  // Other terminals keep their scrollback.
+  const useAltScreen = isAppleTerminal;
+  if (useAltScreen) {
+    process.stdout.write("\x1b[?1049h");
+  }
 
   try {
     await animateStartup(version, basename(projectRoot), session.activeBookId, modelInfo);
@@ -214,7 +215,9 @@ export async function launchTui(
     );
     await app.waitUntilExit();
   } finally {
-    process.stdout.write(EXIT_ALT);
+    if (useAltScreen) {
+      process.stdout.write("\x1b[?1049l");
+    }
     process.emitWarning = originalEmitWarning;
     process.stderr.write = originalStderrWrite;
   }