diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/pardes.zig | 59 |
1 files changed, 18 insertions, 41 deletions
diff --git a/src/pardes.zig b/src/pardes.zig index f19d9b17..8f08ca06 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -2728,7 +2728,7 @@ test "Tab N draws every pane's tab N cells wide and clicks count past it; bare T try std.testing.expect(p.executeBuiltinLine(0, "Tab 0")); try std.testing.expectEqual(@as(u16, 8), config.tab_now); // The ctl read's tab column, and a Dump's settings. - const ctl_text = pardes_ctlfs_ctlText(p, pane); + const ctl_text = @import("ninep/testing.zig").rd(p, ctlfs.Node.of(pane.serial, .ctl), 0, 4096).bytes; try std.testing.expect(std.mem.indexOf(u8, ctl_text, " 8 ") != null); try dump.dumpState(p); const restored = try dump.restore(p, p.dump_out.?, "/tmp/pardes.dump.zon"); @@ -2737,11 +2737,6 @@ test "Tab N draws every pane's tab N cells wide and clicks count past it; bare T try std.testing.expectEqual(@as(u16, 8), config.tab_now); } -fn pardes_ctlfs_ctlText(p: *Pardes, pane: *Pane) []const u8 { - const th = @import("ninep/testing.zig"); - return th.rd(p, ctlfs.Node.of(pane.serial, .ctl), 0, 4096).bytes; -} - test "tabbed file aligns syntax cursor and mouse at the nearest insertion gap" { const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .cols = 60, .rows = 12 }); @@ -5220,21 +5215,19 @@ pub const Pardes = struct { return f(p.host.ctx, @intCast(id)); } - fn hostWriteFile(p: *Pardes, pane: u8, path: []const u8, bytes: []const u8) void { - if (p.host.vtable.write_file) |f| return f(p.host.ctx, pane, path, bytes); - // The in-process filesystem reports the same way a real host does, so - // an OOM here leaves the pane dirty rather than looking saved. - if (!p.fallback.writeFile(path, bytes)) p.saveFailed(pane, path, error.OutOfMemory); - } - /// Writes `bytes` to `path` for pane `id`, its directories made first: /// the pane after it, if it is still the one `serial` names and the /// write did not fail. A failed write changes nothing: its file goes /// back to the saved revision `was`, dirty as it was. fn writeChecked(p: *Pardes, id: u8, serial: u32, path: []const u8, bytes: []const u8, was: u32) ?*Pane { const failures = p.fs.failures; - makeParents(path); - p.hostWriteFile(id, path, bytes); + // A Save makes the directories its file goes in, and any above them, + // first: one rule, for the pane's own name and `Save path` alike. A + // directory it cannot make leaves the write to fail and say why. + if (comptime hosted) if (filesystem.localPath(path)) |local| filesystem.makeDirs(std.fs.path.dirname(local) orelse "/"); + // The in-process filesystem reports the same way a real host does, + // so an OOM there leaves the pane dirty rather than looking saved. + if (p.host.vtable.write_file) |f| f(p.host.ctx, id, path, bytes) else if (!p.fallback.writeFile(path, bytes)) p.saveFailed(id, path, error.OutOfMemory); const pane = p.panes[id] orelse return null; if (pane.serial != serial) return null; if (p.fs.failures == failures) return pane; @@ -5324,15 +5317,6 @@ pub const Pardes = struct { return Shell.missingInterpreter(Shell.find(bin, &buf) orelse return null, out); } - /// A Save makes the directories its file goes in, and any above them, - /// first: one rule, for the pane's own name and `Save path` alike. A - /// directory it cannot make leaves the write to fail and say why. - fn makeParents(path: []const u8) void { - if (comptime !hosted) return; - const local = filesystem.localPath(path) orelse return; - filesystem.makeDirs(std.fs.path.dirname(local) orelse "/"); - } - /// The directory a write of `path` that failed with `err` went into: /// what is there (a directory when it is no local path), whether it is /// missing, and whether that is because one above refuses (EACCES). @@ -5391,13 +5375,6 @@ pub const Pardes = struct { p.noteLateFailure(p.active); } - /// The path a watch is about: a real file's, or a PDF's. - fn watchPath(p: *const Pardes, id: u8) ?[]const u8 { - const pane = p.panes[id] orelse return null; - if (pane.file) |f| return if (f.output == null) f.path else null; - return pane.pdfPath(); - } - pub fn fsPayload(p: *const Pardes, r: ctlfs.Reply) []const u8 { return switch (r.payload) { .none => &.{}, @@ -5529,9 +5506,11 @@ pub const Pardes = struct { } else ctlfs.events.noteLogAs(p, .save, pane, w.path); } }, - .watch => |w| if (v.watch_file) |f| - f(p.host.ctx, w.pane, p.watchPath(w.pane) orelse "", w.on, w.mode) - else { + .watch => |w| if (v.watch_file) |f| { + // What a watch is about: a real file, or a PDF. + const path: []const u8 = if (p.panes[w.pane]) |pane| (if (pane.file) |file| (if (file.output == null) file.path else "") else pane.pdfPath() orelse "") else ""; + f(p.host.ctx, w.pane, path, w.on, w.mode); + } else { p.fallback.watched[w.pane] = w.on; }, .theme_file => |t| if (v.watch_theme) |f| f(p.host.ctx, t.generation, t.on), @@ -6966,7 +6945,11 @@ pub const Pardes = struct { // The finder's last pane takes the column with it. const finder_gone = if (emptied) |c| p.finder.emptied(p, c) else false; if (p.active != id) return; - p.active = gainer orelse beside orelse p.anyPane() orelse return p.quitEmpty(); + // No pane left: the session is over. + p.active = gainer orelse beside orelse p.anyPane() orelse { + p.quit = true; + return p.emit(.quit); + }; if (emptied) |c| if (!finder_gone and !p.header_focus) tagline.enterHeader(p, c); } @@ -6996,12 +6979,6 @@ pub const Pardes = struct { if (p.panes[p.active] == null) p.active = beside orelse p.anyPane() orelse return tagline.enterHeader(p, null); } - /// No pane is left: the session is over. - fn quitEmpty(p: *Pardes) void { - p.quit = true; - p.emit(.quit); - } - /// The pane Last should fall back to when the jumplist has nothing: the /// one below in this column, wrapping to the top, and any other live pane /// failing that. A pane that opened beside this one and was never focused |
