From 0957cd7ad097c83a591e315f2e261996e72ea856 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 20 Nov 2026 15:13:48 -0300 Subject: tui: a pardes whose terminal hangs up (no daemon) or that is sent SIGTERM kills its language servers' groups as an exit does: Killed.handle dies by raise, so the language client's atexit group kill (lsp_client.zig killAllAtExit) never ran and a server busy in a build (zls at a cold start, its children) lived on after the editor; the handler calls it now (kill(2) only, async-signal-safe); test "tty editing: lsp-hangup" (the mock, LSPMOCK_MODE=busy, leaves a child in its group at the handshake and says its pid; the case hangs up the pty and wants the child gone in 5 s): ServerChildLivesOn on the base, passes now; a user could hit it: closing the terminal of a daemon-less pardes, or kill (TERM) of any pardes, with a language server busy; tui process-test 1 of 145 failed once in the whole run (the SIGTERM flags case, "the terminal left raw", load 8-15; 3 of 3 alone) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- dev/lsp/lsp_client.zig | 5 +++-- dev/tui/tui.zig | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'dev') diff --git a/dev/lsp/lsp_client.zig b/dev/lsp/lsp_client.zig index 4ad8dace..fdd4af55 100644 --- a/dev/lsp/lsp_client.zig +++ b/dev/lsp/lsp_client.zig @@ -2244,8 +2244,9 @@ fn reap(pid: libc.pid_t) void { /// At this process's exit, every server's group is killed: a server busy /// in a build (zls at a cold start) would not notice its socket close, and /// lived on with its children after the editor. Registered once, at the -/// first spawn; signals only, no locks (other threads may hold them). -fn killAllAtExit() callconv(.c) void { +/// first spawn; signals only, no locks (other threads may hold them): a +/// signal's handler calls it too (tui.zig `Killed`). +pub fn killAllAtExit() callconv(.c) void { for (&conns) |*c| if (c.pid > 0) { _ = libc.kill(-c.pid, .KILL); }; diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig index 72028b04..638f1400 100644 --- a/dev/tui/tui.zig +++ b/dev/tui/tui.zig @@ -906,7 +906,7 @@ const Screen = struct { /// the main screen, no mouse, paste or keyboard modes, the cursor shown, /// cooked termios -- and then the signal's own death. A nested editor /// killed in a pane must not leave that pane's terminal wedged. -/// Async-signal-safe: write, tcsetattr, sigaction, raise. +/// Async-signal-safe: write, tcsetattr, kill, sigaction, raise. const Killed = struct { var fd: posix.fd_t = -1; var cooked: posix.termios = undefined; @@ -937,6 +937,8 @@ const Killed = struct { ninep_io.unlinkOwnSocket(); host_io.Shell.unlinkOwnedRcs(); daemon.hangUp(); + // No exit hook runs: the language servers' groups go here. + @import("../lsp/lsp_client.zig").killAllAtExit(); // SA_RESETHAND put the default back: the same signal, now fatal. _ = std.c.raise(sig); } -- cgit v1.3 From 8953e01fba330404ded0e5b87bf4f4bb1cfddbb8 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 20 Nov 2026 15:52:03 -0300 Subject: tui: a frame with no caret hides the terminal's cursor: the frontend called showCursor for a frame with a caret and nothing for one without (dev/tui/tui.zig, the frame's end), vaxis keeps cursor_vis, so the block cursor stayed visible where the last caret was (hscroll: on the first text column of a view wheeled sideways past the caret; a +Search or a pane whose caret is off screen; a terminal pane's spawn); now win.hideCursor; the tty harness records a hidden cursor as `cursor=hidden` (where a hidden cursor was left is no one's: test/e2e_harness.zig `cursor` says `shown`, test/tty.zig's snap and stable key read it): with the harness alone no golden moved (0 of 145), with the fix ten moved, each only in snap headers from cursor=X,Y to cursor=hidden (checked line by line, golden_diff.py): collapse 2, follow 1, hscroll 1, images 2, jumps 1, lspcomplete 1, shrinktag 2, ttytaken 1, wheeldrift 4, wrap 1, re-recorded; a user saw it: a stale block cursor on the text in every frame with no caret Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- dev/tui/tui.zig | 4 +++- test/e2e_harness.zig | 6 ++++-- test/snapshots/collapse.golden | 4 ++-- test/snapshots/follow.golden | 2 +- test/snapshots/hscroll.golden | 2 +- test/snapshots/images.golden | 4 ++-- test/snapshots/jumps.golden | 2 +- test/snapshots/lspcomplete.golden | 2 +- test/snapshots/shrinktag.golden | 4 ++-- test/snapshots/ttytaken.golden | 2 +- test/snapshots/wheeldrift.golden | 8 ++++---- test/snapshots/wrap.golden | 2 +- test/tty.zig | 10 +++++----- 13 files changed, 28 insertions(+), 24 deletions(-) (limited to 'dev') diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig index 638f1400..30b334b3 100644 --- a/dev/tui/tui.zig +++ b/dev/tui/tui.zig @@ -1785,10 +1785,12 @@ const Shell = struct { vx.freeImage(sc.tty.writer(), removed.value.id); if (stale_len < stale.len) break; } + // A frame with no caret hides the terminal's cursor: shown, it + // would stay where the last caret was. if (shown.cursor) |cur| { win.showCursor(cur.x, cur.y); win.setCursorShape(if (cur.bar) .beam else .default); - } + } else win.hideCursor(); const tz_render = tracy.zone(@src(), "vx.render"); const before = sc.tty.tty_writer.pos + sc.tty.writer().end; vx.render(sc.tty.writer()) catch {}; diff --git a/test/e2e_harness.zig b/test/e2e_harness.zig index f9ed44c0..9481166e 100644 --- a/test/e2e_harness.zig +++ b/test/e2e_harness.zig @@ -349,11 +349,13 @@ pub const Harness = struct { }; } - /// The visual cursor position (viewport coords): { x, y }. - pub fn cursor(self: *Harness) struct { x: u16, y: u16 } { + /// The visual cursor position (viewport coords): { x, y }, and whether + /// the app shows it (DECTCEM). + pub fn cursor(self: *Harness) struct { x: u16, y: u16, shown: bool } { return .{ .x = self.term.screens.active.cursor.x, .y = self.term.screens.active.cursor.y, + .shown = self.term.modes.get(.cursor_visible), }; } diff --git a/test/snapshots/collapse.golden b/test/snapshots/collapse.golden index 241bc057..3f73e051 100644 --- a/test/snapshots/collapse.golden +++ b/test/snapshots/collapse.golden @@ -5,7 +5,7 @@ | 1 KEEP-FIRST | 2 KEEP-SECOND | 3 KEEP-THIRD -== snap middle-collapsed grid=160x25 cursor=7,3 +== snap middle-collapsed grid=160x25 cursor=hidden |3: |4: |5: @@ -64,7 +64,7 @@ |3: 1 KEEP-FIRST Collapse |4: 2 KEEP-SECOND |5: 3 KEEP-THIRD -== snap tab-collapsed grid=160x25 cursor=51,2 +== snap tab-collapsed grid=160x25 cursor=hidden |3: |4: |5: diff --git a/test/snapshots/follow.golden b/test/snapshots/follow.golden index c02ea08f..69749b42 100644 --- a/test/snapshots/follow.golden +++ b/test/snapshots/follow.golden @@ -31,7 +31,7 @@ | 27 line 27 52 line 52 77 line 77 == snap hop grid=150x30 cursor=82,5 |3: 1 line 1 Save Term Collapse Follow Del Unfoll Save Term Collapse Follow Del Unfo -== snap wheel grid=150x30 cursor=82,5 +== snap wheel grid=150x30 cursor=hidden |3: 2 line 2 Save Term Collapse Follow Del Unfoll Save Term Collapse Follow Del Unfo |4: 3 line 3 ow llow |5: 4 line 4 29 line 29 54 line 54 diff --git a/test/snapshots/hscroll.golden b/test/snapshots/hscroll.golden index 5f930ddf..4799b3b5 100644 --- a/test/snapshots/hscroll.golden +++ b/test/snapshots/hscroll.golden @@ -20,7 +20,7 @@ | Mode Filter Collapse Del | ls | wide.txt -== snap wheeled grid=90x31 cursor=7,9 +== snap wheeled grid=90x31 cursor=hidden |9: 1 ND_A_MARKER_WAY_OUT_RIGHT_padpadpadpad == snap clamped grid=90x31 cursor=7,9 |9: 1 short1 END_A_MARKER_WAY_OUT_RIGHT_padp diff --git a/test/snapshots/images.golden b/test/snapshots/images.golden index 6a06f55b..04797da3 100644 --- a/test/snapshots/images.golden +++ b/test/snapshots/images.golden @@ -1,4 +1,4 @@ -== snap img-open grid=150x31 cursor=11,8 +== snap img-open grid=150x31 cursor=hidden | Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config History Debug Exit | New Term Find Grep Joincol Delcol New Term Find Grep Joincol Delcol | /tmp/pardes-snap/images/cwd Term+bash Save Mode Filter Collapse Del /tmp/pardes-snap/images/cwd Term+bash Save Mode Filter Collapse Del @@ -63,7 +63,7 @@ |14: 0-0 d,#152019, 1-29 d,#0d1410, 30-32 p8,p4, 33-33 p4,p8, 34-34 p8,p12, 35-35 p12,p8, 36-45 p12,p12, 46-74 p12,#0d1410, 75-75 p12,#608269, 76-149 p12,#0d1410, |15: 0-0 d,#152019, 1-29 d,#0d1410, 30-30 p4,p8, 31-31 p8,p4, 32-32 p8,p12, 33-33 p12,p8, 34-45 p12,p12, 46-74 p12,#0d1410, 75-75 p12,#608269, 76-149 p12,#0d1410, |16: 0-0 d,#152019, 1-29 d,#0d1410, 30-30 p8,p12, 31-31 p12,p8, 32-45 p12,p12, 46-74 p12,#0d1410, 75-75 p12,#608269, 76-149 p12,#0d1410, -== snap no-ascii grid=150x31 cursor=11,8 +== snap no-ascii grid=150x31 cursor=hidden |6: img petscii:on palette:terminal ascii:off /tmp/pardes-snap/images/cwd/pic |8: Ascii |9: ██████████████🬝🬹 diff --git a/test/snapshots/jumps.golden b/test/snapshots/jumps.golden index 6cb8a45f..34712e6e 100644 --- a/test/snapshots/jumps.golden +++ b/test/snapshots/jumps.golden @@ -130,7 +130,7 @@ |3: 86 line 86 Last ls == snap last-back grid=150x31 cursor=7,17 |3: 86 line 86 ls Last -== snap jumplist grid=150x31 cursor=7,17 +== snap jumplist grid=150x31 cursor=hidden |3: 86 line 86 Jumplist ls |16: /tmp/pardes-snap/jumps/cwd/+Jumps Save Term Collapse Follow LocationsConf |17: ig Del diff --git a/test/snapshots/lspcomplete.golden b/test/snapshots/lspcomplete.golden index 48dac907..72b413cf 100644 --- a/test/snapshots/lspcomplete.golden +++ b/test/snapshots/lspcomplete.golden @@ -54,7 +54,7 @@ | 1 c.zig:7:23 verdigris Shade | 2 c.zig:7:23 cinnabar Shade | ~ -== snap nobrace grid=100x19 cursor=16,10 +== snap nobrace grid=100x19 cursor=hidden | Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config History Debug Exit | New Term Find Grep Joincol Delcol |^*/tmp/pardes-snap/lspcomplete/cwd/d.zig Save Term Collapse Follow TreeContext Def Refs Del diff --git a/test/snapshots/shrinktag.golden b/test/snapshots/shrinktag.golden index bfca20e3..c8ef1a13 100644 --- a/test/snapshots/shrinktag.golden +++ b/test/snapshots/shrinktag.golden @@ -20,7 +20,7 @@ | de Filter Collapse Del | ls | w.txt -== snap shrunk grid=100x31 cursor=4,9 +== snap shrunk grid=100x31 cursor=hidden |4: w.txt ls |5: w.txt |6: /tmp/pardes-snap/shrinktag/cwd Term+bash Save Mo @@ -31,7 +31,7 @@ |18: |19: |20: -== snap move-preview grid=100x31 cursor=4,9 +== snap move-preview grid=100x31 cursor=hidden == snap restored grid=100x31 cursor=4,9 |4: ls ls |5: w.txt w.txt diff --git a/test/snapshots/ttytaken.golden b/test/snapshots/ttytaken.golden index 765dc734..ee72ccc2 100644 --- a/test/snapshots/ttytaken.golden +++ b/test/snapshots/ttytaken.golden @@ -38,7 +38,7 @@ |28: line 26 |29: line 27 |30: big.txt -== snap spawned grid=210x31 cursor=109,2 +== snap spawned grid=210x31 cursor=hidden |2: /tmp/pardes-snap/ttytaken/cwd Term+bash Save Mode Filter Collapse Del @`echo TAKEN''ONE` @`echo TAKEN''TWO` |3: line 1 Exec |16: : diff --git a/test/snapshots/wheeldrift.golden b/test/snapshots/wheeldrift.golden index 2474411c..393a57e1 100644 --- a/test/snapshots/wheeldrift.golden +++ b/test/snapshots/wheeldrift.golden @@ -16,7 +16,7 @@ | 11 line 11_0123456789_abcdefghij_ZEND | 12 line 12_0123456789_abcdefghij_ZEND | 13 line 13_0123456789_abcdefghij_ZEND -== snap drifted grid=70x17 cursor=7,4 +== snap drifted grid=70x17 cursor=hidden |4: 6 line 6_0123456789_abcdefghij_ZEND |5: 7 line 7_0123456789_abcdefghij_ZEND |6: 8 line 8_0123456789_abcdefghij_ZEND @@ -30,8 +30,8 @@ |14: 16 line 16_0123456789_abcdefghij_ZEND |15: 17 line 17_0123456789_abcdefghij_ZEND |16: 18 line 18_0123456789_abcdefghij_ZEND -== snap paying grid=70x17 cursor=7,4 -== snap moved grid=70x17 cursor=7,4 +== snap paying grid=70x17 cursor=hidden +== snap moved grid=70x17 cursor=hidden |4: 6 123456789_abcdefghij_ZEND |5: 7 123456789_abcdefghij_ZEND |6: 8 123456789_abcdefghij_ZEND @@ -45,7 +45,7 @@ |14: 16 0123456789_abcdefghij_ZEND |15: 17 0123456789_abcdefghij_ZEND |16: 18 0123456789_abcdefghij_ZEND -== snap rearmed grid=70x17 cursor=7,4 +== snap rearmed grid=70x17 cursor=hidden |4: 5 123456789_abcdefghij_ZEND |5: 6 123456789_abcdefghij_ZEND |6: 7 123456789_abcdefghij_ZEND diff --git a/test/snapshots/wrap.golden b/test/snapshots/wrap.golden index 431664ee..ba115b3f 100644 --- a/test/snapshots/wrap.golden +++ b/test/snapshots/wrap.golden @@ -17,7 +17,7 @@ == snap visual-gj-again grid=48x15 cursor=10,6 == snap visual-gk grid=48x15 cursor=10,5 == snap visual-count-gj grid=48x15 cursor=10,7 -== snap off grid=48x15 cursor=10,7 +== snap off grid=48x15 cursor=hidden |4: 1 0---------1---------2---------3---- Wrap |5: 2 second line |6: 3 third line diff --git a/test/tty.zig b/test/tty.zig index 47fca229..f26328ca 100644 --- a/test/tty.zig +++ b/test/tty.zig @@ -584,7 +584,7 @@ fn stateKey(h: *eh.Harness) ![]u8 { styles.update("\x00"); } } - return std.fmt.allocPrint(h.gpa, "{d},{d},{x}\n{s}", .{ c.x, c.y, styles.final(), text }); + return std.fmt.allocPrint(h.gpa, "{d},{d},{},{x}\n{s}", .{ c.x, c.y, c.shown, styles.final(), text }); } /// A mouse column: either a screen column, or `@Word` / `@Word#2` - the column @@ -814,7 +814,8 @@ fn snap9pText(arena: std.mem.Allocator, h: *eh.Harness, label: []const u8, prev: return out.items; } -/// `== snap