summaryrefslogtreecommitdiff
path: root/src/detached
diff options
context:
space:
mode:
Diffstat (limited to 'src/detached')
-rw-r--r--src/detached/server.zig42
1 files changed, 5 insertions, 37 deletions
diff --git a/src/detached/server.zig b/src/detached/server.zig
index de26db13..d8379793 100644
--- a/src/detached/server.zig
+++ b/src/detached/server.zig
@@ -587,24 +587,11 @@ pub const Session = struct {
fn writeFile(ctx: ?*anyopaque, pane: u8, path: []const u8, bytes: []const u8) void {
const s = of(ctx);
- filesystem.write(s.core, path, bytes) catch |err|
- return s.core.saveFailed(pane, path, err);
- if (s.core.panes[pane]) |pn| if (pn.file) |f| if (std.mem.eql(u8, f.path, path)) {
- if (s.watches[pane]) |*w| if (w.serial == pn.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 = of(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(of(ctx).core, bytes);
}
fn watchFile(ctx: ?*anyopaque, pane: u8, _: []const u8, on: bool, mode: pardes.WatchMode) void {
@@ -621,14 +608,7 @@ pub const Session = struct {
fn dumpThemes(ctx: ?*anyopaque, pane: u8) void {
const s = of(ctx);
- const config_dir = s.core.opts.config_dir orelse return;
- const out_dir = pardes.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 setClipboard(ctx: ?*anyopaque, text: []const u8) void {
@@ -761,20 +741,8 @@ pub const Session = struct {
fn harvest(s: *Session) void {
const now = monotonicMs();
- for (&s.retired_shells) |*shell| reapShell(&shell.pid, &shell.kill_at, now);
- for (&s.ptys) |*pty| if (pty.fd < 0) reapShell(&pty.pid, &pty.kill_at, now);
- }
-
- fn reapShell(pid: *posix.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;
- }
+ for (&s.retired_shells) |*shell| host_io.reapRetired(&shell.pid, &shell.kill_at, now);
+ for (&s.ptys) |*pty| if (pty.fd < 0) host_io.reapRetired(&pty.pid, &pty.kill_at, now);
}
fn inotify(s: *Session) c_int {