diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-01 17:48:02 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 18:08:12 -0300 |
| commit | 8c74f9a8f199ea0c2d20cc524358d224ea192005 (patch) | |
| tree | d2a280eb296ad1dce02c9f8e3e8fad20a927edf8 /src/builtins.zig | |
| parent | afec162464d360cbbf475d3fb7457cda83ce918f (diff) | |
| download | pardes-8c74f9a8f199ea0c2d20cc524358d224ea192005.tar.gz pardes-8c74f9a8f199ea0c2d20cc524358d224ea192005.zip | |
Get reads a pane's file again, refusing unsaved edits once as Del does, and Get file loads that file into the pane; in a directory pane it reads the directory again. Load is Restore, as Put is Save; Abort's refusal says it is acme's debugging word
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/builtins.zig')
| -rw-r--r-- | src/builtins.zig | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/builtins.zig b/src/builtins.zig index 1172fa78..1d524514 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -1116,6 +1116,34 @@ pub const ClipReplace = struct { // ---- panes and columns ---- +/// acme's Get: the pane's file read again, its unsaved edits refused once +/// as Del refuses them. `Get file` loads that file into the pane instead, +/// the pane taking its name. +pub const Get = struct { + pub const takes_arg = true; + 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"); + // 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); + 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 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"); + } + } +}; + /// Write the pane's text to its file, or to the file its argument names. pub const Save = struct { pub const takes_arg = true; |
