diff options
Diffstat (limited to 'src/exec.zig')
| -rw-r--r-- | src/exec.zig | 37 |
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"); |
