diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-01 20:50:11 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 20:50:11 -0300 |
| commit | 081e1b9ab9d3bb8afaae8ea040c7767cb6e4f863 (patch) | |
| tree | 8184d5f206b00c8e5e18445e1626e360b11ed65f /src/builtins.zig | |
| parent | 4bdeee602d1e642582ce91fdbd0da210797894e9 (diff) | |
| download | pardes-081e1b9ab9d3bb8afaae8ea040c7767cb6e4f863.tar.gz pardes-081e1b9ab9d3bb8afaae8ea040c7767cb6e4f863.zip | |
Undo after Get file or Edit's e puts the old name back with the old text and its clean state, so a Save or Putall after it writes nothing over the loaded file; a Get file that fails, or is asked about unsaved edits, renames nothing; Get file in a directory pane is refused with how to open it
ctl.getFile is the one load-under-a-name path: it reads first, then makes
one undo step (whose snapshot now keeps the name and its saved state),
renames and loads, and leaves the pane clean.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/builtins.zig')
| -rw-r--r-- | src/builtins.zig | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/builtins.zig b/src/builtins.zig index ed6ac467..129dd659 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -1142,21 +1142,21 @@ pub const Get = struct { pub fn run(c: Ctx) void { const ctl = @import("ninep/ctl.zig"); const f = if (c.pane.file) |*file| file else return c.p.reportFailure(c.id, "Get: only a file pane takes it"); + const typed = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); // A directory pane: the directory read again (Dir.zig), as acme's - // Get is in a directory window. - if (f.listing != null) return panes.Dir.show(c.p, c.id, c.id); + // Get is in a directory window; a file is a Look's from there. + if (f.listing != null) { + if (typed.len > 0) return c.p.reportFailure(c.id, "Get: a directory pane reads its directory; a Look at the file opens it"); + return panes.Dir.show(c.p, c.id, c.id); + } if (!panes.Output.fileTraits(f.output).saves) return c.p.reportFailure(c.id, "Get: only a file pane takes it"); if (ctl.getRefused(c.p, c.pane, "Get")) |said| return c.p.reportFailure(c.id, said); - const typed = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); - if (typed.len > 0) { - var home_buf: [4096]u8 = undefined; - const full = std.fs.path.resolvePosix(c.p.scratch.allocator(), &.{ Pardes.paneDir(c.pane), @import("fs.zig").expandHome(typed, &home_buf) }) catch return; - @import("ninep/pane.zig").nameBuffer(c.p, c.id, full, false) catch return c.p.reportFailure(c.id, "Get: invalid file name"); - } var failed: anyerror = error.Unexpected; - if (ctl.get(c.p, c.pane, &failed) != 0) { + var home_buf: [4096]u8 = undefined; + const path = if (typed.len == 0) c.pane.file.?.path else std.fs.path.resolvePosix(c.p.scratch.allocator(), &.{ Pardes.paneDir(c.pane), @import("fs.zig").expandHome(typed, &home_buf) }) catch return; + const errno = if (typed.len == 0) ctl.get(c.p, c.pane, &failed) else ctl.getFile(c.p, c.pane, path, &failed); + if (errno != 0) { var said: [320]u8 = undefined; - const path = c.pane.file.?.path; c.p.reportFailure(c.id, std.fmt.bufPrint(&said, "Get: {s}: {s}", .{ path[0..@min(path.len, 256)], if (failed == error.FileNotFound) "no such file" else "cannot be read" }) catch "Get: cannot be read"); } } |
