summaryrefslogtreecommitdiff
path: root/src/builtins.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/builtins.zig')
-rw-r--r--src/builtins.zig28
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;