Severity: MEDIUM
Status: ✅ FIXED
Files: src/main.zig, src/server/render.zig
After the #539 fix, exiting szn still left a remnant of the status bar painted at the bottom of the screen. Detailed investigation uncovered three contributing defects:
Duplicate display.exitAltScreen() execution (Commit 344b7f9 / rev 782):
When moving the stdout drain and exitAltScreen() into a defer block, the existing defer display.exitAltScreen() catch ...; on line 702 was not removed. Because Zig executes defers in LIFO order, the inner defer drained out_buf and called exitAltScreen(), and then the outer defer called exitAltScreen() a second time. This sent duplicate \x1b[<1u and \x1b[?1049l sequences, corrupting keyboard protocol pop counts and restoring the cursor on the primary screen twice without a matching DECSC.
Display.exitAltScreen:
Display.exitAltScreen sent only \x1b[?7h\x1b[<1u\x1b[?1000l\x1b[?1002l\x1b[?1006l\x1b[?2004l\x1b[?25h\x1b[?1049l.
Unlike upstream tmux (which emits \x1b[m\x1b[H\x1b[2J...\x1b[?1049l), it lacked:
\x1b[m (SGR reset): The status bar applies background colours (e.g. \x1b[48;2;...m); without reset, text rendition attributes bleed into subsequent terminal output.\x1b[H\x1b[2J (home + erase display): For terminal environments that do not isolate alternate screen buffers cleanly (or where alternate screen is disabled/unsupported), omitting display clear leaves the status bar intact on row sy.\x1b[?2026l (synchronized update end): Any pending synchronized frame was left unterminated.stdout_fd during enterAltScreen():
setNonBlocking(stdout_fd) was called before display.enterAltScreen(). If writeBytes hit EAGAIN during startup, enterAltScreen() failed silently, causing szn to render entirely on the primary screen buffer where its status bar remained permanently after exit.src/main.zig:
stdout_fd blocking until after display.enterAltScreen() completes.defer display.exitAltScreen().defer block that restores blocking mode, drains out_buf, and runs display.exitAltScreen().setNonBlocking(stdout_fd) only after alternate screen entry.src/server/render.zig:
Display.exitAltScreen to emit \x1b[m\x1b[?2026l\x1b[H\x1b[2J\x1b[?7h\x1b[<1u\x1b[?1000l\x1b[?1002l\x1b[?1006l\x1b[?2004l\x1b[?25h\x1b[?1049l, matching upstream tmux behaviour.enterAltScreen and exitAltScreen byte sequences.zig build and zig build test pass on Zig 0.16.0 (1066/1066 tests).zig build and zig build test pass on Zig 0.17.0.zig fmt --check . passes.