diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-20 01:45:46 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-20 02:33:46 -0300 |
| commit | 3eb6c09bc97c2e60a17e1663108f4b22e3d1308c (patch) | |
| tree | be4f3e4b73d299abcefb1abb52f1e6e8f31ba1c1 /dev/tui | |
| parent | 11f55f018a5eb0699d58627a4f2ea39c2b7f5e89 (diff) | |
| download | pardes-3eb6c09bc97c2e60a17e1663108f4b22e3d1308c.tar.gz pardes-3eb6c09bc97c2e60a17e1663108f4b22e3d1308c.zip | |
dev, runtime: a session's file watches once (file_watch.Watches, a working name), the session loop's beside its ptys and queue: the kernel's descriptor, the table (each pane's mark and the theme's slot), the reader that posts `files_changed` to the one queue (the Inbox) and the Host's three file calls (Watches.Calls fills both frontends' write_file, watch_file, watch_theme); the terminal's reader (an Io task posting to vaxis's queue, its files_changed message) and the window's (a thread with a stop pipe, polling a non-blocking descriptor) are deleted for one Io task on a blocking descriptor ended by its cancel, as the ptys' readers are; a Restore lets go of the loop's table, so the frontend call `watched` is gone (ten calls to nine); what a user sees: nothing (the queue keeps one change flag however many reads posted it; a reader that cannot start leaves the session running unwatched, as the terminal's did, where the window's start failed); tui core-test 857/1007 (150 skipped; +1, the device's test), shell-test 1047/1050, term 17/17, pane 183/184, kitty 45/45, behaviour-test and --replay 275/275, process-test 0 of 144 failed (ttytaken once in the run, passed on its retry), soaks --clients 5 and --bytes --clients 5 diverged 0, unequal 0, quiet checks 597/0 673/0 779/0 and 920/0 723/0 755/0, unlisted 0, corpus scene 22 of 22, no leak; gui unit-test 1643/1647 with only the perf check's BaselineHarnessMismatch; daemon.py plain, --far, --games, --window-clients, --upgrade both ways pass; the macOS library (Linux, aarch64-macos) and FreeBSD build (load 9-18)
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'dev/tui')
| -rw-r--r-- | dev/tui/tui.zig | 77 |
1 files changed, 14 insertions, 63 deletions
diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig index 5c1945e6..b20c15a0 100644 --- a/dev/tui/tui.zig +++ b/dev/tui/tui.zig @@ -130,7 +130,6 @@ const Msg = union(enum) { search_rows: pardes.Stream.Batch, /// A kind's job done on a worker (host_io.KindJob). kind_job: *host_io.KindJob, - files_changed, fs_ready, /// A replica's connection, handed over by the daemon (Peers). replica: daemon.Joining, @@ -771,6 +770,7 @@ pub fn runClient(init: std.process.Init, opts: pardes.Options, path: []const u8, var no_inbox: host_io.Inbox = .{ .io = io, .gpa = gpa, .lsp_allocator = start.allocs.lsp }; defer no_inbox.deinit(); var no_ptys: host_io.Ptys = .{ .queue = &no_inbox, .prompt_rcs = undefined }; + var no_watches: file_watch.Watches = .{ .io = io, .gpa = gpa, .queue = &no_inbox }; var sh: Shell = .{ .io = io, .gpa = gpa, @@ -780,7 +780,7 @@ pub fn runClient(init: std.process.Init, opts: pardes.Options, path: []const u8, .loop = &loop, .frame = &frame_arena, .paste_buf = &paste_buf, - .inotify_fd = -1, + .watches = &no_watches, .own = start.joined.view, .screen = &screen, .client = &c, @@ -957,7 +957,7 @@ const Own = struct { .loop = o.loop, .frame = &o.frame_arena, .paste_buf = o.paste_buf, - .inotify_fd = file_watch.init(false), + .watches = &l.watches, .fs = l.fs, .test_clock = host_io.testClock(), .peers = &l.peers, @@ -1000,15 +1000,6 @@ const Own = struct { sh.job_tasks.cancelAll(io); // Its worker may be waiting on the loop's queue for room. sh.core.stream.cancelTask(); - file_watch.stop(sh.inotify_fd); - if (sh.watch_task) |*t| { - t.cancel(io); - sh.watch_task = null; - } - if (sh.inotify_fd >= 0) { - _ = libc.close(sh.inotify_fd); - sh.inotify_fd = -1; - } while (loop.tryEvent() catch null) |ev| switch (ev) { .paste => |b| gpa.free(@constCast(b)), .lsp_done => |d| if (d.rows) |rows| sh.lsp_gpa.free(rows), @@ -1045,7 +1036,6 @@ const Own = struct { if (!screen.on) l.watch(); sh.threads_ok = true; - if (sh.inotify_fd >= 0) sh.watch_task = io.concurrent(watchFiles, .{ io, sh.inotify_fd, loop }) catch null; } /// Detached, the unit is its clients' frame: its output is paced to it @@ -1064,10 +1054,6 @@ const Own = struct { deliverNote(o.loop, n); } - pub fn watched(o: *Own) session_loop.Watched { - return .{ .fd = o.sh.inotify_fd, .table = &o.sh.watches }; - } - pub fn restoring(o: *Own, nc: *pardes.Pardes) void { const sh = &o.sh; const io = sh.io; @@ -1150,7 +1136,9 @@ const Shell = struct { own: u8 = 0, frame: *std.heap.ArenaAllocator, paste_buf: *std.Io.Writer.Allocating, - inotify_fd: c_int, + /// The session's file watches (runtime/session.zig's); a client's, + /// none. + watches: *file_watch.Watches, fs: ?*ninep_io.Listener = null, /// The session's ptys (runtime/session.zig's); a client's, an empty /// table over an empty queue. @@ -1161,8 +1149,6 @@ const Shell = struct { batch: host_io.Inbox.Batch = .{}, batch_at: usize = 0, queue_woken: std.atomic.Value(bool) = .init(false), - watches: file_watch.Table = @splat(null), - watch_task: ?std.Io.Future(void) = null, lsp_task: ?host_io.Lsp.Task = null, pipe_tasks: PipeTasks = .{}, job_tasks: PipeTasks = .{}, @@ -1259,10 +1245,10 @@ const Shell = struct { .tty_taken = PtyCalls.ttyTaken, .fg_name = PtyCalls.fgName, .kill_job = PtyCalls.killJob, - .write_file = writeFile, + .write_file = WatchCalls.writeFile, .write_dump = writeDump, - .watch_file = watchFile, - .watch_theme = watchTheme, + .watch_file = WatchCalls.watchFile, + .watch_theme = WatchCalls.watchTheme, .dump_themes = dumpThemes, .set_clipboard = setClipboard, .read_clipboard = readClipboard, @@ -1363,6 +1349,7 @@ const Shell = struct { } const PtyCalls = host_io.Ptys.Calls(Shell); + const WatchCalls = file_watch.Watches.Calls(Shell); fn upgradeAsked(ctx: ?*anyopaque, id: pardes.Pane.Id) void { const pane = id.index(); @@ -1722,7 +1709,6 @@ const Shell = struct { if (pasted.len > 0) s.feed(.{ .paste = pasted }); s.paste_buf.clearRetainingCapacity(); }, - .files_changed => s.check_files = true, .fs_ready => {}, .lsp_done => |d| { core.update(.{ .lsp_resp = .{ .id = d.id, .rows = d.rows } }); @@ -1785,8 +1771,7 @@ const Shell = struct { fn reloadWatched(s: *Shell) void { if (!s.check_files) return; s.check_files = false; - if (file_watch.reloadChanged(s.core, s.io, s.gpa, &s.watches)) - s.loop.postEvent(.files_changed) catch {}; + s.watches.reload(s.core); } /// The tty's own motions (its glide, a jump's trail) are under way. @@ -1994,6 +1979,7 @@ const Shell = struct { return; }, .eof => |e| s.ptys.eof(s.core, e), + .files_changed => s.check_files = true, else => m.deinit(s.gpa, s.lsp_gpa), } } @@ -2007,29 +1993,10 @@ const Shell = struct { } } - fn writeFile(ctx: ?*anyopaque, id: pardes.Pane.Id, path: []const u8, bytes: []const u8) void { - const pane = id.index(); - const s = of(ctx); - host_io.writeFile(s.core, &s.watches, pane, path, bytes); - } - fn writeDump(ctx: ?*anyopaque, bytes: []const u8) void { host_io.writeDump(of(ctx).core, bytes); } - fn watchFile(ctx: ?*anyopaque, id: pardes.Pane.Id, _: []const u8, on: bool, mode: pardes.WatchMode) void { - const pane = id.index(); - const s = of(ctx); - if (file_watch.applyEffect(s.core, s.io, s.inotify_fd, &s.watches, pane, on, mode)) - s.loop.postEvent(.files_changed) catch {}; - } - - fn watchTheme(ctx: ?*anyopaque, generation: u32, on: bool) void { - const s = of(ctx); - if (file_watch.applyThemeEffect(s.core, s.gpa, s.inotify_fd, &s.watches, generation, on)) - s.loop.postEvent(.files_changed) catch {}; - } - fn dumpThemes(ctx: ?*anyopaque, id: pardes.Pane.Id) void { const pane = id.index(); const s = of(ctx); @@ -2129,22 +2096,6 @@ fn lspStatusSink(ctx: ?*anyopaque, text: []const u8) void { if (!posted) s.lsp_gpa.free(copy); } -fn watchFiles(io: std.Io, fd: c_int, loop: *Loop) void { - if (comptime builtin.os.tag != .linux and builtin.os.tag != .freebsd) { - while (file_watch.wait(fd)) loop.postEvent(.files_changed) catch break; - return; - } - const file: std.Io.File = .{ .handle = fd, .flags = .{ .nonblocking = false } }; - // One buffer, read into directly: a Reader around it only added a second - // (and in a safe build, filled both as `undefined` on every start). - var buf: [4096]u8 = undefined; - while (true) { - const n = file.readStreaming(io, &.{&buf}) catch break; - if (n == 0) break; - loop.postEvent(.files_changed) catch break; - } -} - fn keepSignal(_: posix.SIG) callconv(.c) void {} /// A replica client's (`runClient`): a hangup is its end, whoever sent it. @@ -2836,7 +2787,7 @@ test "TTY queued results reject an old LSP request ID" { .loop = undefined, .frame = undefined, .paste_buf = undefined, - .inotify_fd = -1, + .watches = undefined, .peers = &no_peers, .ptys = undefined, }; @@ -2876,7 +2827,7 @@ test "TTY worker setup failures finish matching LSP and pipe requests" { .loop = undefined, .frame = undefined, .paste_buf = undefined, - .inotify_fd = -1, + .watches = undefined, .threads_ok = true, .peers = &no_peers, .ptys = undefined, |
