fix(web): clear terminal on workspace change; disable Mac Option as Meta

- terminal: on workspaceId change call terminal.clear() and
  terminal.reset() so the previous workspace's scrollback is wiped
  before the new shell's output appears.
- terminal: set macOptionIsMeta: false. With the default (true),
  Mac Option+key sequences (e.g. Option+[ emits ESC) leak a literal
  0x1b into the shell's stdin, which crashes downstream REPLs like
  Python's with "invalid non-printable character U+001B".
This commit is contained in:
tao.chen
2026-07-06 13:39:20 +08:00
parent 90f6f877b5
commit 041c3dc002
@@ -38,6 +38,12 @@ export function TerminalPanel({ workspaceId }: TerminalPanelProps) {
terminal = new Terminal({
cursorBlink: true,
convertEol: true,
// Prevent Mac Option+key from emitting ESC. Without this, typing
// Option+[ etc. leaks a literal 0x1b into the shell's stdin, which
// can break downstream programs that don't interpret escape
// sequences (e.g. Python's REPL reports "invalid non-printable
// character U+001B").
macOptionIsMeta: false,
fontFamily:
'Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',
fontSize: 12,
@@ -102,6 +108,10 @@ export function TerminalPanel({ workspaceId }: TerminalPanelProps) {
hasWelcomedRef.current = false;
isDeadRef.current = false;
setIsDead(false);
// Clear the previous workspace's scrollback so the user does not see
// shell output from another workspace in the new one.
terminal.clear();
terminal.reset();
const removeInputHandler = terminal.onData((input) => {
if (!isDeadRef.current) {