summaryrefslogtreecommitdiff
path: root/dev
diff options
context:
space:
mode:
Diffstat (limited to 'dev')
-rw-r--r--dev/gui/gui.zig4
-rw-r--r--dev/host_io.zig2
-rw-r--r--dev/tui/tui.zig44
3 files changed, 43 insertions, 7 deletions
diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig
index d779cf47..aa28a3f0 100644
--- a/dev/gui/gui.zig
+++ b/dev/gui/gui.zig
@@ -808,7 +808,9 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, detached: bool, di
var want_w: c_int = 1120;
var want_h: c_int = 720;
var want_at: ?[2]c_int = null;
- if (opts_in.geometry) |spec| geometry: {
+ // ...or the size an Upgrade's exec says its window had (client.zig
+ // `execAgain`).
+ if (opts_in.geometry orelse if (std.c.getenv("PARDES_JOIN_SIZE")) |e| std.mem.span(e) else null) |spec| geometry: {
const x_at = std.mem.indexOfScalar(u8, spec, 'x') orelse break :geometry;
const plus = std.mem.indexOfAnyPos(u8, spec, x_at, "+-") orelse spec.len;
want_w = std.math.clamp(std.fmt.parseInt(c_int, spec[0..x_at], 10) catch break :geometry, 200, 16384);
diff --git a/dev/host_io.zig b/dev/host_io.zig
index a22bf5ce..419c4570 100644
--- a/dev/host_io.zig
+++ b/dev/host_io.zig
@@ -52,7 +52,7 @@ pub fn stopWorkers() void {
/// session is one view, the live one's (the tty's terminal, the window's
/// window): the others are let go, as a detach of each.
pub fn restoreCore(gpa: std.mem.Allocator, core: *pardes.Pardes, path: []const u8, peers: *replica.Peers, inotify_fd: c_int, watches: *file_watch.Table) ?*pardes.Pardes {
- peers.dropAll(core);
+ peers.restoring(core);
const bytes = pardes.dump.restoreBytes(core, gpa, path) catch |err| {
core.reportError(.at(core.view().active), "Restore", err);
return null;
diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig
index 09704424..92ac6a0c 100644
--- a/dev/tui/tui.zig
+++ b/dev/tui/tui.zig
@@ -731,17 +731,30 @@ pub fn runClient(init: std.process.Init, opts: pardes.Options, path: []const u8,
posix.sigaddset(&winch_set, posix.SIG.HUP);
posix.sigaddset(&winch_set, posix.SIG.TERM);
hangup_quits = true;
+ // Last of all, after its goodbye and its terminal put back: dead of the
+ // TERM or HUP that ended it, as the own path's stub dies (the shell's
+ // $? is 128+N), not exit 0.
+ defer dieOfQuitSignal();
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();
- try screen.enter(try vaxis.Tty.init(io, &tty_buf));
+ // A pair's terminal is its own before its join, as the own frontend's
+ // is before its core: that join is the pair's whole start (its own
+ // boot, replica.ownBoot), and keys typed meanwhile are its input, not
+ // echoed by the line discipline and lost as it enters. An attach enters
+ // once joined, a refusal said on the terminal as it was.
+ if (opts.pair != null) try screen.enter(try vaxis.Tty.init(io, &tty_buf));
defer screen.leave();
+ var start: client_loop.Start = undefined;
+ if (!start.open(init, opts, .{ .path = path, .session = session, .far = far_link })) {
+ screen.leave();
+ Said.no(io, "{s}", .{start.said()});
+ }
+ defer start.close();
+ if (opts.pair == null) try screen.enter(try vaxis.Tty.init(io, &tty_buf));
defer screen.glide.deinit(gpa);
defer screen.art.deinit(gpa);
var paste_buf: std.Io.Writer.Allocating = .init(gpa);
@@ -808,6 +821,7 @@ pub fn runClient(init: std.process.Init, opts: pardes.Options, path: []const u8,
var status: c_int = 0;
while (libc.waitpid(@intCast(start.joined.pid), &status, 0) < 0 and libc.errno(-1) == .INTR) {}
}
+ dieOfQuitSignal();
std.process.exit(code);
},
.failed => {
@@ -1626,9 +1640,12 @@ const Shell = struct {
return false;
}
- /// Terminal `screen` (its view live) is `ws` big.
+ /// Terminal `screen` (its view live) is `ws` big; the size it has is no
+ /// resize (a client's start takes its size before its input thread's
+ /// first one comes: Tty.start).
fn resized(s: *Shell, screen: ?*Screen, ws: vaxis.Winsize) void {
if (screen) |sc| {
+ if (sc.size) |was| if (std.meta.eql(was, ws)) return;
sc.size = ws;
sc.vx.resize(s.gpa, sc.tty.writer(), ws) catch {};
}
@@ -1954,6 +1971,22 @@ fn keepSignal(_: posix.SIG) callconv(.c) void {}
/// A replica client's (`runClient`): a hangup or a TERM is its end.
var hangup_quits = false;
+/// The signal a client's `.quit` came of (`winchWatch`), 0 for none.
+var quit_signal: std.atomic.Value(c_int) = .init(0);
+
+/// A client ended by TERM or HUP dies of it, its goodbye said and its
+/// terminal put back first; no other way out.
+fn dieOfQuitSignal() void {
+ const sig: posix.SIG = @enumFromInt(quit_signal.load(.acquire));
+ if (@backingInt(sig) == 0) return;
+ const default: posix.Sigaction = .{ .handler = .{ .handler = posix.SIG.DFL }, .mask = posix.sigemptyset(), .flags = 0 };
+ posix.sigaction(sig, &default, null);
+ var set = posix.sigemptyset();
+ posix.sigaddset(&set, sig);
+ posix.sigprocmask(posix.SIG.UNBLOCK, &set, null);
+ _ = std.c.raise(sig);
+}
+
fn winchWatch(loop: *Loop) void {
var set = posix.sigemptyset();
posix.sigaddset(&set, posix.SIG.WINCH);
@@ -1965,6 +1998,7 @@ fn winchWatch(loop: *Loop) void {
// 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.WINCH)) .winched else if (hangup_quits) .quit else .hangup;
+ if (ev == .quit) quit_signal.store(sig, .release);
loop.postEvent(ev) catch {};
}
}