summaryrefslogtreecommitdiff
path: root/dev/tui
diff options
context:
space:
mode:
Diffstat (limited to 'dev/tui')
-rw-r--r--dev/tui/tui.zig61
1 files changed, 39 insertions, 22 deletions
diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig
index 86956eb5..e5e28f6e 100644
--- a/dev/tui/tui.zig
+++ b/dev/tui/tui.zig
@@ -700,7 +700,7 @@ const Tty = struct {
while (t.loop.tryEvent() catch null) |ev| switch (ev) {
.said => |msg| switch (msg) {
.unit, .screen, .refused, .blob => |b| std.heap.c_allocator.free(b),
- .checked => {},
+ .checked, .ended, .left => {},
},
.paste => |b| t.sh.gpa.free(@constCast(b)),
else => {},
@@ -789,6 +789,22 @@ pub fn runClient(init: std.process.Init, opts: pardes.Options, path: []const u8,
screen.leave();
Said.no(io, "'{s}' let this client go (a Detach in it, or the session's end)", .{session});
},
+ .left => {
+ screen.leave();
+ var said: [600]u8 = undefined;
+ std.Io.File.stderr().writeStreamingAll(io, std.fmt.bufPrint(&said, "pardes: detached from '{s}', which is still running; come back with `pardes attach {s}`\n", .{ session, session }) catch "pardes: detached\n") catch {};
+ std.process.exit(0);
+ },
+ .ended => |code| {
+ screen.leave();
+ // A pair's client is its session's parent: its status once it
+ // is gone, as a terminal's job ends with its program.
+ if (opts.pair != null) {
+ var status: c_int = 0;
+ while (libc.waitpid(@intCast(start.joined.pid), &status, 0) < 0 and libc.errno(-1) == .INTR) {}
+ }
+ std.process.exit(code);
+ },
.failed => {
screen.leave();
Said.no(io, "{s}", .{start.said()});
@@ -949,7 +965,6 @@ const Own = struct {
.test_clock = host_io.testClock(),
.peers = &l.peers,
.ptys = &l.ptys,
- .session = l,
};
const sh = &o.sh;
sh.screen = o.screen;
@@ -1077,9 +1092,6 @@ const Shell = struct {
/// The session's ptys (runtime/session.zig's); a client's, an empty
/// table over an empty queue.
ptys: *host_io.Ptys,
- /// The session's loop (its `watch`, the daemon's notes); a client's
- /// and a test's, none.
- session: ?*Own.Session = null,
/// What `takeQueue` takes off the ptys' queue, and whether the loop
/// was woken for it since it last did (one wake, not one a read ahead
/// of the terminal's keys in the loop's queue).
@@ -1150,17 +1162,9 @@ const Shell = struct {
}
fn host(s: *Shell) host_io.Host {
- return .{ .ctx = s, .vtable = if (comptime pardes.isolated) &isolated_vtable else &vtable };
+ return .{ .ctx = s, .vtable = &vtable };
}
- const isolated_vtable: host_io.Host.VTable = .{
- .wait_input = waitInput,
- .now = clockNow,
- .present = presentFrame,
- .post_present = postPresent,
- .poll_frame = ownFrame,
- };
-
const vtable: host_io.Host.VTable = .{
.wait_input = waitInput,
.now = clockNow,
@@ -1224,10 +1228,10 @@ const Shell = struct {
/// and the shell has its terminal again), the session left running.
fn detach(ctx: ?*anyopaque) void {
const s = of(ctx);
- // A replica client's: its link ends.
+ if (!daemon.kept()) return s.core.reportFailure(s.core.view().active, "Detach: no pardes daemon lists this session (it is its terminal's job)");
+ // A replica client's: its last word, and its link ends.
if (s.peers.detach(s.core.live)) return;
if (s.detached()) return s.core.reportFailure(s.core.view().active, "Detach: detached already (no terminal of its own)");
- if (!daemon.kept()) return s.core.reportFailure(s.core.view().active, "Detach: no pardes daemon lists this session (it is its terminal's job)");
s.leaveTerminal();
}
@@ -1535,10 +1539,7 @@ const Shell = struct {
return true;
}
// The terminal went: a session the daemon keeps carries on
- // without it, to be attached again. Gone before the first
- // frame, the reader that takes the daemon's `ok` (kept
- // waits on it) is not started yet: started here.
- if (s.session) |l| l.watch();
+ // without it, to be attached again.
if (daemon.kept()) {
if (!s.detached()) s.leaveTerminal();
return true;
@@ -1561,10 +1562,10 @@ const Shell = struct {
};
if (echo) s.focused_ns = @intCast(std.Io.Clock.awake.now(s.io).nanoseconds);
c.take(said);
- if (said == .refused) return true;
+ if (said == .refused or said == .ended or said == .left) return true;
} else switch (said) {
.unit, .screen, .refused, .blob => |b| std.heap.c_allocator.free(b),
- .checked => {},
+ .checked, .ended, .left => {},
},
.link_gone => if (s.client) |c| {
c.link.quit = true;
@@ -2359,6 +2360,22 @@ test "an ESC read by itself is the Escape key at once" {
t.vx.caps.kitty_keyboard = false;
}
+test "an Escape read with the click after it is the Escape key, then the click" {
+ var t: TestInput = undefined;
+ try t.init();
+ defer t.deinit();
+ // A busy session reads them in one: no terminal sends Alt on a mouse
+ // report as an ESC before it (it is in the report's button).
+ var reader: TestReader = .{ .parts = &.{"\x1b\x1b[<1;105;9M"} };
+ try readInput(&t.loop, &reader, &t.vx, &t.feed);
+ try std.testing.expectEqual(.winsize, std.meta.activeTag((try t.loop.tryEvent()).?));
+ const escape = (try t.loop.tryEvent()).?.key_press;
+ try std.testing.expectEqual(vaxis.Key.escape, escape.codepoint);
+ try std.testing.expect(!escape.mods.alt);
+ try std.testing.expectEqual(.mouse, std.meta.activeTag((try t.loop.tryEvent()).?));
+ try std.testing.expect(try t.loop.tryEvent() == null);
+}
+
test "a frame's answer is taken wherever the reads cut it, and never typed" {
const gpa = std.testing.allocator;
var t: TestInput = undefined;