summaryrefslogtreecommitdiff
path: root/dev/gui
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-20 04:01:55 -0300
committerGabriel Schneider <[email protected]>2026-11-20 04:07:22 -0300
commit6e8735895d04c0073eb28cc1a2f431a2ba587e9d (patch)
tree9641fb6bfaf29b9c2286e0feff1a4d6d9035d2c2 /dev/gui
parent47649a2fe6884b660e57f8f7564c9a62128970e0 (diff)
parent680cfe1fa5a15be3770d310153258ba9ded13dd8 (diff)
downloadpardes-6e8735895d04c0073eb28cc1a2f431a2ba587e9d.tar.gz
pardes-6e8735895d04c0073eb28cc1a2f431a2ba587e9d.zip
integration: a session's file watches and its language servers' client once, on the attach that is always a client: pardes-services-2b (file_watch.Watches owned by the session loop, both frontends' readers deleted; the language client through the session's one queue, the terminal's own copy and its blocking post deleted) and pardes-merge29; one conflict, a doc comment in runtime/session.zig where both sides rewrote the frontend calls' list (the attach's words for note kept, the watched() line dropped: the watches' change deleted that call); tui core-test 856/1007 (151 skipped), shell-test 1047/1050, the window builds; the coordinator's gate in the ledger (reorg/merge30)
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'dev/gui')
-rw-r--r--dev/gui/gui.zig135
1 files changed, 13 insertions, 122 deletions
diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig
index 2aaa8bcc..ab33abe9 100644
--- a/dev/gui/gui.zig
+++ b/dev/gui/gui.zig
@@ -382,32 +382,6 @@ fn sdlWake(_: ?*anyopaque) void {
const PipeTasks = selection_pipe.Tasks;
const output_capacity = Queue.output_capacity;
-fn stopPipe() ![2]c_int {
- var fds: [2]c_int = undefined;
- if (libc.pipe(&fds) != 0) return error.PipeFailed;
- errdefer for (fds) |fd| {
- _ = libc.close(fd);
- };
- for (fds) |fd| if (libc.fcntl(fd, libc.F.SETFD, @as(c_int, 1)) < 0) return error.PipeFailed;
- return fds;
-}
-
-fn watchThread(fd: c_int, stop: c_int, q: *Queue) void {
- while (true) {
- var fds = [_]libc.pollfd{
- .{ .fd = stop, .events = libc.POLL.IN, .revents = 0 },
- .{ .fd = fd, .events = libc.POLL.IN, .revents = 0 },
- };
- if (libc.poll(&fds, fds.len, -1) < 0) {
- if (libc.errno(-1) == .INTR) continue;
- return;
- }
- if (fds[0].revents != 0) return;
- if ((fds[1].revents & (libc.POLL.ERR | libc.POLL.HUP | libc.POLL.NVAL)) != 0) return;
- if (fds[1].revents != 0 and file_watch.drain(fd)) q.push(.files_changed);
- }
-}
-
const Gui = struct {
addon_gpu: ?SketchGpu = null,
addon_hash: [pardes.MAX_PANES]u64 = @splat(0),
@@ -1018,10 +992,6 @@ const Own = struct {
test_mode: bool,
detached: bool,
pipe_tasks: PipeTasks = .{},
- inotify_fd: c_int = -1,
- watch_reader: ?std.Thread = null,
- watch_stop: [2]c_int = .{ -1, -1 },
- watches: file_watch.Table = @splat(null),
shell: Shell = undefined,
const Session = session_loop.Loop(Own);
@@ -1046,7 +1016,6 @@ const Own = struct {
observeGuiFont(g, core);
syncTaglineFont(g, core);
l.inbox.wake_fn = sdlWake;
- o.inotify_fd = file_watch.init(true);
o.shell = .{
.core = core,
.gui = g,
@@ -1056,8 +1025,7 @@ const Own = struct {
.ptys = &l.ptys,
.queue = &l.inbox,
.pipe_tasks = &o.pipe_tasks,
- .inotify_fd = o.inotify_fd,
- .watches = &o.watches,
+ .watches = &l.watches,
.fs = l.fs,
.test_mode = o.test_mode,
.test_clock = if (o.test_mode) host_io.testClock() else null,
@@ -1080,33 +1048,15 @@ const Own = struct {
const io = l.io;
o.shell.fs = null;
host_io.setExitWake(null, null);
- pardes.lsp.setStatusSink(null, null);
pardes.Kind.drawer = null;
o.shell.job_tasks.cancelAll(io);
- if (o.inotify_fd >= 0) {
- if (o.watch_reader) |thread| {
- _ = host_io.writeFd(o.watch_stop[1], "x");
- thread.join();
- }
- for (o.watch_stop) |fd| if (fd >= 0) {
- _ = libc.close(fd);
- };
- file_watch.stop(o.inotify_fd);
- _ = libc.close(o.inotify_fd);
- o.inotify_fd = -1;
- }
o.pipe_tasks.cancelAll(io);
- if (l.inbox.lsp_task) |*task| task.future.cancel(io);
// Its worker may be waiting on the queue for room.
l.core.stream.cancelTask();
o.g.hit_core = null;
}
pub fn start(o: *Own, l: *Session) !void {
- if (o.inotify_fd >= 0) {
- o.watch_stop = try stopPipe();
- o.watch_reader = try std.Thread.spawn(.{}, watchThread, .{ o.inotify_fd, o.watch_stop[0], &l.inbox });
- }
if (l.fs) |f| try f.watch(&l.inbox, wakeFs);
_ = c.SDL_StartTextInput(o.g.window);
@@ -1115,7 +1065,6 @@ const Own = struct {
if (o.test_mode) setStdinRaw() catch {};
o.shell.threads_ok = true;
- pardes.lsp.setStatusSink(&l.inbox, Queue.lspStatus);
host_io.setExitWake(&l.inbox, Queue.wakeForExit);
if (o.detached) {
o.shell.closeTheWindow();
@@ -1134,13 +1083,8 @@ const Own = struct {
deliverNote(&o.shell, n);
}
- pub fn watched(o: *Own) session_loop.Watched {
- return .{ .fd = o.inotify_fd, .table = &o.watches };
- }
-
pub fn restoring(o: *Own, nc: *pardes.Pardes) void {
o.pipe_tasks.cancelAll(o.shell.io);
- o.shell.queue.discardCompletions();
// One view, the window's (host_io.restoreCore).
o.shell.gview = 0;
o.g.cells.clearImages();
@@ -1472,7 +1416,7 @@ fn clientSession(init: std.process.Init, g: *Gui, opts_in: pardes.Options, test_
defer queue.deinit();
var ptys: host_io.Ptys = .{ .queue = &queue, .prompt_rcs = undefined };
var pipe_tasks: PipeTasks = .{};
- var watches: file_watch.Table = @splat(null);
+ var no_watches: file_watch.Watches = .{ .io = io, .gpa = gpa, .queue = &queue };
var no_peers: replica.Peers = .{};
var shell: Shell = .{
.core = start.r.core(),
@@ -1483,8 +1427,7 @@ fn clientSession(init: std.process.Init, g: *Gui, opts_in: pardes.Options, test_
.ptys = &ptys,
.queue = &queue,
.pipe_tasks = &pipe_tasks,
- .inotify_fd = -1,
- .watches = &watches,
+ .watches = &no_watches,
.test_mode = test_mode,
.client = &window,
.peers = &no_peers,
@@ -2410,8 +2353,9 @@ const Shell = struct {
batch: Queue.Batch = .{},
pipe_tasks: *PipeTasks,
job_tasks: PipeTasks = .{},
- inotify_fd: c_int,
- watches: *file_watch.Table,
+ /// The session's file watches (runtime/session.zig's); a client's,
+ /// none.
+ watches: *file_watch.Watches,
threads_ok: bool = false,
test_mode: bool = false,
feed: StdinFeed = .{},
@@ -2588,10 +2532,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,
@@ -2605,6 +2549,7 @@ const Shell = struct {
};
const PtyCalls = host_io.Ptys.Calls(Shell);
+ const WatchCalls = file_watch.Watches.Calls(Shell);
/// The command panes' exits, told once their output is in (host_io).
fn takeExits(s: *Shell) void {
@@ -2635,15 +2580,7 @@ const Shell = struct {
for (msgs.slice()) |m| switch (m) {
.output => |o| s.ptys.output(s.core, o),
.eof => |e| s.ptys.eof(s.core, e),
- .lsp => |l| {
- s.core.update(.{ .lsp_resp = .{ .id = l.id, .rows = l.rows } });
- if (l.rows) |rows| s.lsp_allocator.free(rows);
- },
- .lsp_status => |text| {
- var mbuf: [256]u8 = undefined;
- s.core.setStatus(.at(s.core.view().active), message.stamp(&mbuf, "lsp", text));
- s.lsp_allocator.free(text);
- },
+ .lsp, .lsp_status => s.queue.landLsp(s.core, m),
.pipe => |response_value| {
var response = response_value;
s.core.update(.{ .pipe_resp = .{
@@ -2671,8 +2608,7 @@ const Shell = struct {
.fs_ready => {},
.adopted => |a| s.ptys.adoptions.adoptShell(s.core, a.pid, a.fd),
};
- if (check_files and file_watch.reloadChanged(s.core, s.io, s.gpa, s.watches))
- s.queue.push(.files_changed);
+ if (check_files) s.watches.reload(s.core);
}
};
@@ -3192,35 +3128,10 @@ fn deliverNote(ctx: *anyopaque, note: daemon.Note) void {
}
}
-fn writeFile(ctx: ?*anyopaque, id: pardes.Pane.Id, path: []const u8, bytes: []const u8) void {
- const pane = id.index();
- const s = shellOf(ctx);
- host_io.writeFile(s.core, s.watches, pane, path, bytes);
-}
-
fn writeDump(ctx: ?*anyopaque, bytes: []const u8) void {
host_io.writeDump(shellOf(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 = shellOf(ctx);
- if (file_watch.applyEffect(s.core, s.io, s.inotify_fd, s.watches, pane, on, mode))
- s.queue.push(.files_changed);
-}
-
-fn watchTheme(ctx: ?*anyopaque, generation: u32, on: bool) void {
- const s = shellOf(ctx);
- if (file_watch.applyThemeEffect(
- s.core,
- s.gpa,
- s.inotify_fd,
- s.watches,
- generation,
- on,
- )) s.queue.push(.files_changed);
-}
-
fn dumpThemes(ctx: ?*anyopaque, id: pardes.Pane.Id) void {
const pane = id.index();
const s = shellOf(ctx);
@@ -6017,25 +5928,6 @@ test "installed Nerd Symbols fallback covers Yazi directory icons" {
try std.testing.expect(atlas.glyphForCodepoint(0xe5ff).glyph != 0);
}
-test "GUI PTY file watcher stops and joins without closing its watched descriptor" {
- if (!file_watch.supported) return error.SkipZigTest;
- const gpa = std.testing.allocator;
- var queue: Queue = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa };
- defer queue.deinit();
- const fd = file_watch.init(true);
- if (fd < 0) return error.WatchInitFailed;
- defer _ = libc.close(fd);
- const stop = try stopPipe();
- defer for (stop) |pipe_fd| {
- _ = libc.close(pipe_fd);
- };
- const thread = try std.Thread.spawn(.{}, watchThread, .{ fd, stop[0], &queue });
- _ = host_io.writeFd(stop[1], "x");
- thread.join();
- try std.testing.expect(libc.fcntl(fd, libc.F.GETFD) >= 0);
- try std.testing.expectEqual(@as(usize, 0), queue.take().len);
-}
-
test "GUI completion failure survives backlog and leaves the document unchanged" {
const gpa = std.testing.allocator;
const core = try pardes.Pardes.init(gpa, .{ .tty_only = true });
@@ -7785,9 +7677,8 @@ test "a detached GUI authority follows terminal directory changes with no window
var ptys: host_io.Ptys = .{ .queue = &queue, .prompt_rcs = &rcs, .gens = @splat(1) };
defer ptys.deinit();
var pipes: PipeTasks = .{};
- var watches: file_watch.Table = @splat(null);
var no_peers: replica.Peers = .{};
- var shell: Shell = .{ .core = core, .io = io, .gpa = gpa, .lsp_allocator = gpa, .ptys = &ptys, .queue = &queue, .pipe_tasks = &pipes, .inotify_fd = -1, .watches = &watches, .peers = &no_peers };
+ var shell: Shell = .{ .core = core, .io = io, .gpa = gpa, .lsp_allocator = gpa, .ptys = &ptys, .queue = &queue, .pipe_tasks = &pipes, .watches = undefined, .peers = &no_peers };
const child = try host_io.forkShell(null, 0, &rcs, "/bin/sh", start, 24, 80);
ptys.slots[0] = .{ .fd = child.file.handle, .pid = child.pid };
try std.testing.expect(host_io.writeFd(child.file.handle, "cd child\n"));