summaryrefslogtreecommitdiff
path: root/dev/tui/tui.zig
diff options
context:
space:
mode:
Diffstat (limited to 'dev/tui/tui.zig')
-rw-r--r--dev/tui/tui.zig77
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,