summaryrefslogtreecommitdiff
path: root/src/builtins.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/builtins.zig')
-rw-r--r--src/builtins.zig43
1 files changed, 42 insertions, 1 deletions
diff --git a/src/builtins.zig b/src/builtins.zig
index 30a5a50f..146789b0 100644
--- a/src/builtins.zig
+++ b/src/builtins.zig
@@ -460,9 +460,38 @@ pub const Newcol = struct {
}
};
+/// Close the pane. `Del k` gives its rows to the open pane above it and
+/// `Del j` to the one below, each falling back to the other side.
pub const Del = struct {
+ pub const takes_arg = true;
pub fn run(c: Ctx) void {
- c.p.removePane(c.id) catch |err| c.p.reportError(c.id, "close", err);
+ const side = std.mem.trim(u8, c.arg orelse "", " \t\r\n");
+ const at = layout.findPane(c.p, c.id);
+ const above = if (at) |f| layout.expandedNeighbor(c.p, f.col, f.idx, .above) else null;
+ const below = if (at) |f| layout.expandedNeighbor(c.p, f.col, f.idx, .below) else null;
+ const to: ?usize = if (std.mem.eql(u8, side, "k"))
+ above orelse below
+ else if (std.mem.eql(u8, side, "j"))
+ below orelse above
+ else if (side.len > 0)
+ return c.p.reportError(c.id, "Del k|j", error.InvalidArgument)
+ else
+ null;
+ // Someone at the keyboard with a real choice to make is asked, on the
+ // pane's notice band; a click, a 9P write or a script closes it the
+ // way it always has. A folded pane gives back only its tag row, and a
+ // pane with a prompt open closes as it did rather than trade the
+ // prompt for a question.
+ if (side.len == 0 and c.p.can_ask and above != null and below != null and
+ !c.pane.collapsed and c.pane.prompt == .none)
+ {
+ c.pane.prompt = .del_side;
+ c.p.active = c.id;
+ // The question says Del already.
+ if (c.pane.msg_announcement) c.pane.msg_len = 0;
+ return;
+ }
+ c.p.removePane(c.id, to) catch |err| c.p.reportError(c.id, "close", err);
}
};
@@ -500,6 +529,18 @@ pub const Delcol = struct {
}
};
+pub const DelAbove = struct {
+ pub fn run(c: Ctx) void {
+ Del.run(.{ .p = c.p, .pane = c.pane, .id = c.id, .txt = c.txt, .arg = "k" });
+ }
+};
+
+pub const DelBelow = struct {
+ pub fn run(c: Ctx) void {
+ Del.run(.{ .p = c.p, .pane = c.pane, .id = c.id, .txt = c.txt, .arg = "j" });
+ }
+};
+
/// A shell in the calling pane's directory, raw from the first frame. On every
/// pane's tagline: the fast path from wherever you are to a prompt there.
pub const Tty = struct {