diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-29 22:38:16 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 00:12:17 -0300 |
| commit | 6f42f51cd652e189408eace598f99ec25b9542f8 (patch) | |
| tree | 633d074c637cc25f3cb851d88414ff9e982e6fa6 /src/gui | |
| parent | 7e8e2655567cab1c28597f44d0aec79e46b0deb8 (diff) | |
| download | pardes-6f42f51cd652e189408eace598f99ec25b9542f8.tar.gz pardes-6f42f51cd652e189408eace598f99ec25b9542f8.zip | |
The hosts' Save, Dump and DumpThemes writes and their shell reaper are host_io's, once, where the tty, the gui and the detached session each had a copy
writeFile, writeDump and dumpThemes were byte-for-byte the same in tty.zig, gui.zig and detached/server.zig but for how each reaches its core, and the gui's and the session's reapers the same but for a pid <= 0 against == 0 (a pid is never negative there). Each vtable entry is now a line calling host_io's. ttyTaken, fgName, killJob and ptyResize stay each shell's: they are already one call to host_io each, and what differs is how a shell reaches its pty (an optional with a file, an optional with an fd, a bounds-checked array). macos.zig keeps its copies (no macOS build here to check it). No behaviour changes.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/gui')
| -rw-r--r-- | src/gui/gui.zig | 45 |
1 files changed, 6 insertions, 39 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 8b100cd8..8fd8d360 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -4060,9 +4060,9 @@ const Shell = struct { fn reap(s: *Shell) void { const now = shellClock(); - for (&s.retired_shells) |*child| reapShell(&child.pid, &child.kill_at, now); + for (&s.retired_shells) |*child| host_io.reapRetired(&child.pid, &child.kill_at, now); for (s.ptys) |*slot| if (slot.*) |*pt| if (pt.fd < 0) { - reapShell(&pt.pid, &pt.kill_at, now); + host_io.reapRetired(&pt.pid, &pt.kill_at, now); if (pt.pid == 0) slot.* = null; }; } @@ -4085,7 +4085,7 @@ const Shell = struct { _ = libc.close(pt.fd); pt.fd = -1; const now = shellClock(); - reapShell(&pt.pid, &pt.kill_at, now); + host_io.reapRetired(&pt.pid, &pt.kill_at, now); if (pt.pid == 0) { s.ptys[pane] = null; return; @@ -4662,25 +4662,11 @@ fn killJob(ctx: ?*anyopaque, pane: u8) bool { fn writeFile(ctx: ?*anyopaque, pane: u8, path: []const u8, bytes: []const u8) void { const s = shellOf(ctx); - filesystem.write(s.core, path, bytes) catch |err| - return s.core.saveFailed(pane, path, err); - if (s.core.panes[pane]) |pane_state| if (pane_state.file) |f| { - if (std.mem.eql(u8, f.path, path)) - if (s.watches[pane]) |*w| if (w.serial == pane_state.serial) switch (w.generation) { - .text => w.generation = .{ .text = std.hash.Wyhash.hash(0, bytes) }, - .pdf => {}, - }; - }; - var mbuf: [256]u8 = undefined; - s.core.setMessage(pane, message.stamp(&mbuf, "saved", path)); + host_io.writeFile(s.core, s.watches, pane, path, bytes); } fn writeDump(ctx: ?*anyopaque, bytes: []const u8) void { - const s = shellOf(ctx); - var pbuf: [1024:0]u8 = undefined; - const path = pardes.dump.outPath(&pbuf, s.core.settings.dump_dir.get()) orelse return s.core.dumpFailed(s.core.settings.dump_dir.get(), error.NoDumpDirectory); - filesystem.write(s.core, path, bytes) catch |err| return s.core.dumpFailed(path, err); - s.core.setLastDump(path); + host_io.writeDump(shellOf(ctx).core, bytes); } fn watchFile(ctx: ?*anyopaque, pane: u8, _: []const u8, on: bool, mode: pardes.WatchMode) void { @@ -4704,14 +4690,7 @@ fn watchTheme(ctx: ?*anyopaque, generation: u32, on: bool) void { fn dumpThemes(ctx: ?*anyopaque, pane: u8) void { const s = shellOf(ctx); - const config_dir = s.core.opts.config_dir orelse return; - const out_dir = config.User.dumpThemes(s.io, s.gpa, config_dir, pardes.themes) catch |err| { - s.core.reportError(pane, "dump themes", err); - return; - }; - defer s.gpa.free(out_dir); - var mbuf: [256]u8 = undefined; - s.core.setMessage(pane, message.stamp(&mbuf, "dumped themes", out_dir)); + host_io.dumpThemes(s.core, s.io, s.gpa, pane); } fn putClipboard(gpa: std.mem.Allocator, text: []const u8) void { @@ -4826,18 +4805,6 @@ fn shellClock() i64 { return @as(i64, ts.sec) * std.time.ms_per_s + @divTrunc(ts.nsec, std.time.ns_per_ms); } -fn reapShell(pid: *libc.pid_t, kill_at: *i64, now: i64) void { - if (pid.* <= 0) return; - const result = libc.waitpid(pid.*, null, libc.W.NOHANG); - if (result > 0 or (result < 0 and libc.errno(result) == .CHILD)) { - pid.* = 0; - kill_at.* = 0; - } else if (kill_at.* != 0 and now >= kill_at.*) { - _ = libc.kill(pid.*, libc.SIG.KILL); - kill_at.* = 0; - } -} - fn accumulateWheelDelta(pending: f32, raw_y: f32) f32 { if (!std.math.isFinite(raw_y)) return pending; const next = pending - raw_y; |
