summaryrefslogtreecommitdiff
path: root/src/exec.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-29 16:50:04 -0300
committerGabriel Schneider <[email protected]>2026-10-01 00:12:16 -0300
commit16d5415c508fea0b5dc90dd2cc40866beecf216b (patch)
tree6e558181c1371fb2bc3ef805a64e28c269885795 /src/exec.zig
parent0f632dbd1069d9654d587ebac8e29955a9a31188 (diff)
downloadpardes-16d5415c508fea0b5dc90dd2cc40866beecf216b.tar.gz
pardes-16d5415c508fea0b5dc90dd2cc40866beecf216b.zip
acme's words run as pardes's or are refused, never as shell commands: Put saves
Put, Get, Delete, Snarf, Cut, Paste, Zerox, Sort, Putall, Load, ID and Send written to exec or tagexec each ran as a shell command that exited 127, the write answering 0 -- a Put that looked like a save. Put now runs Save and Delete a Del that does not ask; the rest are refused, EINVAL, invalid: acme's X is not a pardes builtin (with where pardes does it, where it does), in exec and ctl alike. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/exec.zig')
-rw-r--r--src/exec.zig37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/exec.zig b/src/exec.zig
index 06e5d375..87f6da40 100644
--- a/src/exec.zig
+++ b/src/exec.zig
@@ -811,9 +811,42 @@ pub fn namesBuiltin(txt: []const u8) bool {
return std.meta.stringToEnum(Builtin, cmd[0..end]) != null;
}
+/// acme's words, run by their pardes names (Put is Save; Delete is a Del
+/// that does not ask), or refused, never run as a shell command: a Put that
+/// exited 127 looked like a save that worked.
+pub const acme_words = [_]struct { acme: []const u8, pardes: ?[]const u8, hint: []const u8 = "" }{
+ .{ .acme = "Put", .pardes = "Save" },
+ .{ .acme = "Delete", .pardes = "Del" },
+ .{ .acme = "Get", .pardes = null, .hint = ": write get to the pane's ctl" },
+ .{ .acme = "Putall", .pardes = null, .hint = ": Save each pane" },
+ .{ .acme = "Snarf", .pardes = null, .hint = ": y yanks the selection" },
+ .{ .acme = "Cut", .pardes = null, .hint = ": d deletes the selection into a register" },
+ .{ .acme = "Paste", .pardes = null, .hint = ": p puts a register" },
+ .{ .acme = "Zerox", .pardes = null },
+ .{ .acme = "Sort", .pardes = null },
+ .{ .acme = "Load", .pardes = null, .hint = ": Restore loads a dump" },
+ .{ .acme = "ID", .pardes = null },
+ .{ .acme = "Send", .pardes = null },
+};
+
pub fn executeBuiltinLine(p: *Pardes, id: usize, txt: []const u8) bool {
- const cmd = commandText(txt);
- if (cmd.len == 0 or p.exec_depth >= max_exec_depth) return false;
+ const raw = commandText(txt);
+ if (raw.len == 0 or p.exec_depth >= max_exec_depth) return false;
+ const word_end = std.mem.indexOfAny(u8, raw, " \t") orelse raw.len;
+ var renamed: [1024 + 16]u8 = undefined;
+ const cmd = for (acme_words) |w| {
+ if (!std.mem.eql(u8, raw[0..word_end], w.acme)) continue;
+ const now = w.pardes orelse {
+ var said: [128]u8 = undefined;
+ p.reportFailure(id, std.fmt.bufPrint(&said, "invalid: acme's {s} is not a pardes builtin{s}", .{ w.acme, w.hint }) catch "invalid: an acme word pardes has not");
+ return true;
+ };
+ // Delete: Del, the text thrown away unasked.
+ if (std.mem.eql(u8, w.acme, "Delete")) if (p.panes[id]) |pane| if (pane.file) |f| {
+ pane.discard_warned = .{ .revision = f.revision, .by = .Del };
+ };
+ break std.fmt.bufPrint(&renamed, "{s}{s}", .{ now, raw[word_end..] }) catch raw;
+ } else raw;
// `Word arg`, or for a word that says so, `Word+arg` (`Tty+fish`).
const plus = std.mem.indexOfScalar(u8, cmd, '+');
var sp = std.mem.indexOfAny(u8, cmd, " \t");