xonecas.io
70160
Ce

cel-tui / commit 4facee8

fix(core): use alternate screen buffer for clean exit

Switch to the alternate screen buffer (CSI ? 1049 h) on start and
restore the main buffer (CSI ? 1049 l) on stop. This prevents the
app's rendered output from persisting after exit — the shell prompt
now appears cleanly below the original command.

xonecas2026-04-04 4facee837e5ae227456d15d6b74b63ce87672822 parent 16aaec1

1 file changed

packages/core/src/terminal.ts+4−0
@@ -64,6 +64,8 @@ export class ProcessTerminal implements Terminal {
6464 process.stdin.on("data", onInput);
6565 process.stdout.on("resize", this.resizeHandler);
6666
67+ // Switch to alternate screen buffer (restored on exit)
68+ this.write("\x1b[?1049h");
6769 // Enable Kitty keyboard protocol level 1 (disambiguate) with push flag
6870 this.write("\x1b[>1u");
6971 // Enable mouse tracking (normal mode) + SGR encoding
@@ -103,6 +105,8 @@ export class ProcessTerminal implements Terminal {
103105 // Pop Kitty keyboard protocol mode
104106 this.write("\x1b[<u");
105107 this.showCursor();
108+ // Restore main screen buffer
109+ this.write("\x1b[?1049l");
106110
107111 if (this.resizeHandler) {
108112 process.stdout.removeListener("resize", this.resizeHandler);