summaryrefslogtreecommitdiff
path: root/dev
diff options
context:
space:
mode:
Diffstat (limited to 'dev')
-rw-r--r--dev/lsp/lsp_client.zig5
-rw-r--r--dev/tui/tui.zig31
2 files changed, 24 insertions, 12 deletions
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..e441df92 100644
--- a/dev/tui/tui.zig
+++ b/dev/tui/tui.zig
@@ -721,19 +721,22 @@ pub fn runClient(init: std.process.Init, opts: pardes.Options, path: []const u8,
std.process.exit(1);
}
};
- var start: client_loop.Start = undefined;
- if (!start.open(init, opts, .{ .path = path, .session = session, .far = far_link })) Said.no(io, "{s}", .{start.said()});
- defer start.close();
-
+ // Blocked before its join makes a thread, so that winchWatch alone
+ // takes them: a hangup (its terminal closed) or a TERM ends it the
+ // normal way (`quit`), its goodbye a close (a pair's session not kept
+ // ends at its last client's), what it made kept on disk (`Have.keep`)
+ // and its ssh forward's socket unlinked (main.zig).
var winch_set = posix.sigemptyset();
posix.sigaddset(&winch_set, posix.SIG.WINCH);
- // A hangup ends it the normal way (`quit`), what it made kept on disk
- // (`Have.keep`) and its ssh forward's socket unlinked (main.zig).
posix.sigaddset(&winch_set, posix.SIG.HUP);
+ posix.sigaddset(&winch_set, posix.SIG.TERM);
hangup_quits = true;
if (comptime builtin.os.tag == .freebsd)
posix.sigaction(.WINCH, &.{ .handler = .{ .handler = keepSignal }, .mask = posix.sigemptyset(), .flags = 0 }, null);
posix.sigprocmask(posix.SIG.BLOCK, &winch_set, null);
+ var start: client_loop.Start = undefined;
+ if (!start.open(init, opts, .{ .path = path, .session = session, .far = far_link })) Said.no(io, "{s}", .{start.said()});
+ defer start.close();
var tty_buf: [0x10000]u8 = undefined;
var screen: Screen = .{ .io = io, .gpa = gpa, .env = init.environ_map, .buf = &tty_buf, .kitty = .init(gpa) };
defer screen.kitty.deinit();
@@ -906,7 +909,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 +940,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);
}
@@ -1544,7 +1549,10 @@ const Shell = struct {
virtual.* = @max(virtual.*, s.wake_to);
},
.quit => {
+ // A client's terminal went (a hangup, its input's end) or it
+ // took a TERM: a close, as a window's close button.
if (s.client) |c| {
+ c.link.close = true;
c.link.quit = true;
return true;
}
@@ -1783,10 +1791,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 {};
@@ -1939,19 +1949,20 @@ const Shell = struct {
fn keepSignal(_: posix.SIG) callconv(.c) void {}
-/// A replica client's (`runClient`): a hangup is its end, whoever sent it.
+/// A replica client's (`runClient`): a hangup or a TERM is its end.
var hangup_quits = false;
fn winchWatch(loop: *Loop) void {
var set = posix.sigemptyset();
posix.sigaddset(&set, posix.SIG.WINCH);
if (daemon.link >= 0 or hangup_quits) posix.sigaddset(&set, posix.SIG.HUP);
+ if (hangup_quits) posix.sigaddset(&set, posix.SIG.TERM);
while (true) {
var sig: c_int = 0;
if (libc.sigwait(&set, &sig) != 0) continue;
// The terminals are the loop's: it asks each its size, and takes a
// hangup as the end of the one that hung up.
- const ev: Msg = if (sig != @backingInt(posix.SIG.HUP)) .winched else if (hangup_quits) .quit else .hangup;
+ const ev: Msg = if (sig == @backingInt(posix.SIG.WINCH)) .winched else if (hangup_quits) .quit else .hangup;
loop.postEvent(ev) catch {};
}
}