summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-04 23:11:55 -0300
committerGabriel Schneider <[email protected]>2026-11-05 01:20:23 -0300
commitbf283c3a8e14789fc6c2009e354a5265d5c8af91 (patch)
treea6f03475d66232496fa9b20c01fc501e0cb56db5
parentd2129a6e2c6348ee9630c5b5918fbcfadf4411fe (diff)
downloadpardes-bf283c3a8e14789fc6c2009e354a5265d5c8af91.tar.gz
pardes-bf283c3a8e14789fc6c2009e354a5265d5c8af91.zip
tui: the loop's queue carries a named Msg union, not the type of a global var declared only to be named (`@TypeOf(Command.value)`), and the Windows branches go (startInput's `loop.start()` and seven test skips: the tty cannot build for Windows, it calls sigprocmask, sigwait and shm_open)
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
-rw-r--r--src/tui/tui.zig116
1 files changed, 54 insertions, 62 deletions
diff --git a/src/tui/tui.zig b/src/tui/tui.zig
index a8f32c98..aaf958dc 100644
--- a/src/tui/tui.zig
+++ b/src/tui/tui.zig
@@ -53,7 +53,7 @@ const Poster = struct {
var lock: std.Io.Mutex = .init;
var last: u8 = 0;
- pub fn postEvent(p: Poster, ev: @TypeOf(Command.value)) !void {
+ pub fn postEvent(p: Poster, ev: Msg) !void {
lock.lockUncancelable(p.loop.io);
defer lock.unlock(p.loop.io);
if (last != p.view) {
@@ -116,55 +116,54 @@ fn kittyShmProbe(w: *std.Io.Writer, feed: *Feed) void {
w.flush() catch {};
}
-pub const Command = struct {
- pub var value: union(enum) {
- nop,
- /// The terminal's input ended: its end of file, a hangup. A session
- /// a daemon keeps carries on detached; any other ends.
- quit,
- /// A terminal for this detached session, and its stub's pipe
- /// (daemon.Note.attach).
- attach: struct { tty: posix.fd_t, stub: posix.fd_t },
- /// A shell a dead session left, its pty's master (daemon.Note.adopted).
- adopted: struct { pid: posix.pid_t, fd: posix.fd_t },
- /// A timed wait ran out: the core's next wake has come.
- wake,
- /// The input after this is the terminal of this view's (Poster).
- from: u8,
- /// A SIGWINCH: a terminal changed size (Shell.winched).
- winched,
- /// A SIGHUP: the session's own terminal hung up.
- hangup,
- key_press: vaxis.Key,
- pty_read: struct { id: usize, gen: u32, bytes: []u8 },
- pty_eof: struct { id: usize, gen: u32 },
- winsize: vaxis.Winsize,
- mouse: vaxis.Mouse,
- focus_in,
- focus_out,
- paste: []const u8,
- paste_start,
- paste_end,
- lsp_done: struct { id: u32, rows: ?[]u8 },
- lsp_status: []u8,
- pipe_done: selection_pipe.Response,
- /// A streaming search's rows (pardes.Stream).
- search_rows: pardes.Stream.Batch,
- files_changed,
- fs_ready,
- /// A replica's connection, handed over by the daemon (Peers).
- replica: daemon.Joining,
- /// A replica's reader posted: the step boundary takes it in.
- replica_mail,
- /// A replica client's: what the session streamed (replica.Link).
- said: replica.Said,
- link_gone,
- } = .nop;
+/// What the loop's queue carries: a terminal's input, a pane's output, a
+/// worker's answer, a wake.
+const Msg = union(enum) {
+ nop,
+ /// The terminal's input ended: its end of file, a hangup. A session
+ /// a daemon keeps carries on detached; any other ends.
+ quit,
+ /// A terminal for this detached session, and its stub's pipe
+ /// (daemon.Note.attach).
+ attach: struct { tty: posix.fd_t, stub: posix.fd_t },
+ /// A shell a dead session left, its pty's master (daemon.Note.adopted).
+ adopted: struct { pid: posix.pid_t, fd: posix.fd_t },
+ /// A timed wait ran out: the core's next wake has come.
+ wake,
+ /// The input after this is the terminal of this view's (Poster).
+ from: u8,
+ /// A SIGWINCH: a terminal changed size (Shell.winched).
+ winched,
+ /// A SIGHUP: the session's own terminal hung up.
+ hangup,
+ key_press: vaxis.Key,
+ pty_read: struct { id: usize, gen: u32, bytes: []u8 },
+ pty_eof: struct { id: usize, gen: u32 },
+ winsize: vaxis.Winsize,
+ mouse: vaxis.Mouse,
+ focus_in,
+ focus_out,
+ paste: []const u8,
+ paste_start,
+ paste_end,
+ lsp_done: struct { id: u32, rows: ?[]u8 },
+ lsp_status: []u8,
+ pipe_done: selection_pipe.Response,
+ /// A streaming search's rows (pardes.Stream).
+ search_rows: pardes.Stream.Batch,
+ files_changed,
+ fs_ready,
+ /// A replica's connection, handed over by the daemon (Peers).
+ replica: daemon.Joining,
+ /// A replica's reader posted: the step boundary takes it in.
+ replica_mail,
+ /// A replica client's: what the session streamed (replica.Link).
+ said: replica.Said,
+ link_gone,
};
-const Loop = vaxis.Loop(@TypeOf(Command.value));
+const Loop = vaxis.Loop(Msg);
fn startInput(loop: *Loop, sc: *Screen) !void {
- if (comptime builtin.os.tag == .windows) return loop.start();
if (sc.thread != null) return;
sc.thread = try loop.io.concurrent(inputThread, .{ loop, sc });
}
@@ -253,7 +252,7 @@ fn readInput(loop: *Loop, tty: anytype, vx: *vaxis.Vaxis, feed: *Feed) !void {
// chord, and a shell pane was typed its private-use code.
if (result.event) |event| if (event == .key_press and event.key_press.isModifier()) continue;
if (result.event) |event|
- vaxis.loop.handleEventGeneric(post, vx, &feed.cache, @TypeOf(Command.value), event, vx.opts.system_clipboard_allocator) catch |err| {
+ vaxis.loop.handleEventGeneric(post, vx, &feed.cache, Msg, event, vx.opts.system_clipboard_allocator) catch |err| {
if (event == .paste) if (vx.opts.system_clipboard_allocator) |gpa| gpa.free(@constCast(event.paste));
return err;
};
@@ -343,7 +342,6 @@ fn inputFollows(tty: anytype, io: std.Io, ms: u32) !bool {
}
test "terminal input preserves fragmented keys queries paste and text after EOF" {
- if (comptime builtin.os.tag == .windows) return error.SkipZigTest;
const gpa = std.testing.allocator;
const io = std.testing.io;
var env = try std.testing.environ.createMap(gpa);
@@ -428,7 +426,6 @@ test "terminal input preserves fragmented keys queries paste and text after EOF"
}
test "terminal replies and malformed sequences never become typed text" {
- if (comptime builtin.os.tag == .windows) return error.SkipZigTest;
const gpa = std.testing.allocator;
const io = std.testing.io;
var env = try std.testing.environ.createMap(gpa);
@@ -511,7 +508,6 @@ test "terminal replies and malformed sequences never become typed text" {
}
test "terminal input split at every byte with a gap reads as it does whole" {
- if (comptime builtin.os.tag == .windows) return error.SkipZigTest;
const gpa = std.testing.allocator;
const io = std.testing.io;
var env = try std.testing.environ.createMap(gpa);
@@ -607,7 +603,6 @@ test "terminal input split at every byte with a gap reads as it does whole" {
}
test "an ESC read by itself is the Escape key at once" {
- if (comptime builtin.os.tag == .windows) return error.SkipZigTest;
const gpa = std.testing.allocator;
const io = std.testing.io;
var env = try std.testing.environ.createMap(gpa);
@@ -658,7 +653,6 @@ test "an ESC read by itself is the Escape key at once" {
}
test "a frame's answer is taken wherever the reads cut it, and never typed" {
- if (comptime builtin.os.tag == .windows) return error.SkipZigTest;
const gpa = std.testing.allocator;
const io = std.testing.io;
var env = try std.testing.environ.createMap(gpa);
@@ -746,7 +740,6 @@ test "a terminal that never answers a frame stops being asked after one timeout"
}
test "terminal input cancellation joins blocked reads and queued EOF" {
- if (comptime builtin.os.tag == .windows) return error.SkipZigTest;
const gpa = std.testing.allocator;
const io = std.testing.io;
var env = try std.testing.environ.createMap(gpa);
@@ -808,7 +801,7 @@ test "terminal input cancellation joins blocked reads and queued EOF" {
try std.testing.expect(thread == null);
var count: usize = 0;
while (try loop.tryEvent()) |event| {
- const expected: std.meta.Tag(@TypeOf(Command.value)) = if (case == .deliver_eof and count == 511) .quit else .nop;
+ const expected: std.meta.Tag(Msg) = if (case == .deliver_eof and count == 511) .quit else .nop;
try std.testing.expectEqual(expected, std.meta.activeTag(event));
count += 1;
}
@@ -1940,7 +1933,7 @@ const Shell = struct {
/// Each view's terminal, by view (views.zig): the session's own first;
/// none in tests.
terms: [pardes.views.max]?*Screen = @splat(null),
- /// The view the input taken now is from (`Command.value.from`).
+ /// The view the input taken now is from (`Msg.from`).
from: u8 = 0,
frame: *std.heap.ArenaAllocator,
paste_buf: *std.Io.Writer.Allocating,
@@ -1991,7 +1984,7 @@ const Shell = struct {
/// This wait's steps so far, and the input held for the next (`split`).
took_input: bool = false,
took_output: bool = false,
- held: ?@TypeOf(Command.value) = null,
+ held: ?Msg = null,
/// This process a replica client of a session elsewhere (`remote`):
/// its inputs go to the replica, never straight to the core.
remote: ?*Remote = null,
@@ -2503,7 +2496,7 @@ const Shell = struct {
batch = 1;
// A run of queued motions is one move to its last cell: each would
// otherwise redo hover and selection work the next one undoes.
- var motion: ?@TypeOf(Command.value) = null;
+ var motion: ?Msg = null;
var ev = first;
while (true) {
if (s.split(ev)) break;
@@ -2535,7 +2528,7 @@ const Shell = struct {
/// terminals as the clients' deltas bring them, sent after each unit
/// (docs/next-daemon.md, part B terminal notes). One that must wait is
/// held for the next. Whether `ev` is.
- fn split(s: *Shell, ev: @TypeOf(Command.value)) bool {
+ fn split(s: *Shell, ev: Msg) bool {
if (!s.peers.recording) return false;
switch (ev) {
.pty_read => {
@@ -2555,7 +2548,7 @@ const Shell = struct {
return false;
}
- fn apply(s: *Shell, event: @TypeOf(Command.value)) bool {
+ fn apply(s: *Shell, event: Msg) bool {
const core = s.core;
const tz_event = tracy.zone(@src(), "event");
defer tz_event.end();
@@ -3275,7 +3268,7 @@ fn winchWatch(loop: *Loop) void {
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: @TypeOf(Command.value) = if (sig != @backingInt(posix.SIG.HUP)) .winched else if (hangup_quits) .quit else .hangup;
+ const ev: Msg = if (sig != @backingInt(posix.SIG.HUP)) .winched else if (hangup_quits) .quit else .hangup;
loop.postEvent(ev) catch {};
}
}
@@ -3405,7 +3398,6 @@ fn pasteBytes(key: vaxis.Key) []const u8 {
}
test "a terminal pane gets function keys as their sequences and lone modifiers not at all" {
- if (comptime builtin.os.tag == .windows) return error.SkipZigTest;
const gpa = std.testing.allocator;
const io = std.testing.io;
var env = try std.testing.environ.createMap(gpa);