Skip to content
This repository was archived by the owner on May 29, 2026. It is now read-only.

Commit d604ee4

Browse files
staticoclaude
andcommitted
Use alternate screen buffer to prevent scroll contamination in tmux
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e4b2d3f commit d604ee4

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

src/index.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ process.on("uncaughtException", (error) => {
151151
Logger.shutdown();
152152

153153
// Clear screen and show error
154-
process.stdout.write('\x1bc'); // Clear screen
154+
process.stdout.write("\x1b[?1049l"); // Leave alternate screen buffer
155155
console.error("Fatal error:", error.message);
156156
console.error(`Full stack trace saved to ${ERROR_LOG_PATH}`);
157157
console.error(`Exit details saved to ${EXIT_LOG_PATH}`);
@@ -178,7 +178,7 @@ process.on("unhandledRejection", (reason) => {
178178
Logger.shutdown();
179179

180180
// Clear screen and show error
181-
process.stdout.write('\x1bc'); // Clear screen
181+
process.stdout.write("\x1b[?1049l"); // Leave alternate screen buffer
182182
console.error("Unhandled promise rejection:", reason);
183183
console.error(`Full details saved to ${EXIT_LOG_PATH}`);
184184

@@ -224,7 +224,7 @@ process.on("SIGTERM", () => {
224224
Logger.shutdown();
225225
clearInterval(heartbeatInterval);
226226

227-
process.stdout.write('\x1bc'); // Clear screen
227+
process.stdout.write("\x1b[?1049l"); // Leave alternate screen buffer
228228
process.exit(0);
229229
});
230230

@@ -238,7 +238,7 @@ process.on("SIGINT", () => {
238238
Logger.shutdown();
239239
clearInterval(heartbeatInterval);
240240

241-
process.stdout.write('\x1bc'); // Clear screen
241+
process.stdout.write("\x1b[?1049l"); // Leave alternate screen buffer
242242
process.exit(0);
243243
});
244244

@@ -252,7 +252,7 @@ process.on("SIGHUP", () => {
252252
Logger.shutdown();
253253
clearInterval(heartbeatInterval);
254254

255-
process.stdout.write('\x1bc'); // Clear screen
255+
process.stdout.write("\x1b[?1049l"); // Leave alternate screen buffer
256256
process.exit(0);
257257
});
258258

@@ -271,7 +271,7 @@ process.on("exit", (code) => {
271271
Logger.shutdown();
272272

273273
// Final clear screen
274-
process.stdout.write('\x1bc');
274+
process.stdout.write("\x1b[?1049l");
275275
});
276276

277277
// Parse CLI arguments
@@ -482,6 +482,9 @@ db.setPacketRetentionLimit(packetLimit);
482482
const packetStore = new PacketStore(packetLimit);
483483
const nodeStore = new NodeStore();
484484

485+
// Enter alternate screen buffer (prevents scroll contamination in tmux)
486+
process.stdout.write("\x1b[?1049h");
487+
485488
const { waitUntilExit } = render(
486489
React.createElement(App, {
487490
address,
@@ -510,7 +513,7 @@ waitUntilExit()
510513
isShuttingDown = true;
511514
logExit("NORMAL_EXIT", 0, { reason: "User quit application" });
512515
clearInterval(heartbeatInterval);
513-
process.stdout.write('\x1bc'); // Clear screen
516+
process.stdout.write("\x1b[?1049l"); // Leave alternate screen buffer
514517
}
515518
})
516519
.catch((e) => {
@@ -527,7 +530,7 @@ waitUntilExit()
527530
Logger.error("Main", "Application exit error", error);
528531
Logger.shutdown();
529532

530-
process.stdout.write('\x1bc'); // Clear screen
533+
process.stdout.write("\x1b[?1049l"); // Leave alternate screen buffer
531534
console.error("Application failed:", error.message);
532535
console.error(`Full details saved to ${EXIT_LOG_PATH}`);
533536

src/ui/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3541,7 +3541,7 @@ export function App({ address, packetStore, nodeStore, skipConfig = false, skipN
35413541
setTimeout(() => {
35423542
Logger.info("App", "Shutdown complete - clearing screen and exiting");
35433543
Logger.shutdown(); // Force flush logs before exit
3544-
process.stdout.write('\x1bc'); // Clear screen on quit
3544+
process.stdout.write("\x1b[?1049l"); // Leave alternate screen buffer
35453545
process.exit(0);
35463546
}, 100);
35473547
}}

0 commit comments

Comments
 (0)