summaryrefslogtreecommitdiff
path: root/src/exec.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/exec.zig')
-rw-r--r--src/exec.zig145
1 files changed, 15 insertions, 130 deletions
diff --git a/src/exec.zig b/src/exec.zig
index de31624a..4706d11a 100644
--- a/src/exec.zig
+++ b/src/exec.zig
@@ -467,34 +467,6 @@ fn kindHost(z: [:0]const u8) ?std.Io.File.Kind {
return stat.kind;
}
-/// With `BootShell replace`, a doc landing in `col` closes a lone pristine
-/// shell there, the boot's placeholder, and absorbVWeight hands its space to
-/// the doc. With `keep`, the default, the shell stays like any other pane.
-pub fn evictLonePristineTty(p: *Pardes, col: usize, keep_id: usize) void {
- if (p.settings.boot_shell == .keep) return;
- var n_tty: usize = 0;
- var tty_id: usize = 0;
- for (0..p.col_n[col]) |k| {
- const cid = p.col_panes[col][k];
- if (p.panes[cid]) |ct| if (ct.isTerminal()) {
- n_tty += 1;
- tty_id = cid;
- };
- }
- if (n_tty != 1) return;
- const tt = p.panes[tty_id] orelse return;
- // No typing, cursor on the first prompt line, no scrollback: this is
- // the throwaway boot placeholder a document may replace.
- if (tt.ovl != null or panes.terminal.gridCursor(tt).y != 0 or
- panes.terminal.scrollbar(tt).total > tt.rows) return;
- p.deinitPane(tt) catch |err| return p.reportError(tty_id, "close", err);
- layout.compute(p); // a just-stacked doc has no rect yet; absorb snaps to rows
- _ = layout.absorbVWeight(p, tty_id, null);
- layout.removePane(p, tty_id);
- p.panes[tty_id] = null;
- if (p.active == tty_id) p.active = keep_id;
-}
-
// ---- REPLs ----
//
// A terminal is bound as a language's REPL by `Repl python` (builtins.zig).
@@ -1151,9 +1123,9 @@ pub fn applySettingBuiltin(p: *Pardes, setting: config.Runtime.Setting, arg: ?[]
/// `scratch` is New's, `fs` 9P's pane/new, `errors` a +Errors pane.
pub const NewPane = enum { scratch, fs, shell, doc, command, errors };
-/// Put new pane `id` in the layout: every new pane comes through here, by
-/// the `Placement` setting, and every one but a command pane takes the
-/// keyboard. `from` is the pane that asked, `origin` the text it asked
+/// Put new pane `id` in the layout: every new pane comes through here, as
+/// acme's makenewwindow places it, and every one but a command pane takes
+/// the keyboard. `from` is the pane that asked, `origin` the text it asked
/// from: null when a column tag, the workspace tag or 9P asked (acme's
/// t->w == nil).
pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPane) void {
@@ -1172,21 +1144,18 @@ pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPan
layout.compute(p);
const before = p.rects;
const before_min = layout.minima(p);
- switch (p.settings.placement) {
- .acme => switch (kind) {
- // New: the bottom half of the last pane in its own column
- // (look.c:921-923, et->col).
- .scratch => layout.acmePlace(p, p.exec_column orelse columnOf(p, from), null, id),
- // +Errors, a command's output: the last column (util.c:94-98);
- // a command run from a column's tag, that column. The finder's
- // is never the last column for them.
- .command => layout.acmePlace(p, p.exec_column orelse p.ncol - 1, null, id),
- .errors => layout.acmePlace(p, away orelse p.ncol - 1, null, id),
- // makenewwindow(nil) for 9P's new (acme.c:877), else (t).
- .fs => layout.acmePlace(p, acmeColumn(p, from), null, id),
- .shell, .doc => layout.acmePlace(p, acmeColumn(p, from), asked, id),
- },
- .pardes => pardesPlace(p, from, id, kind),
+ switch (kind) {
+ // New: the bottom half of the last pane in its own column
+ // (look.c:921-923, et->col).
+ .scratch => layout.acmePlace(p, p.exec_column orelse columnOf(p, from), null, id),
+ // +Errors, a command's output: the last column (util.c:94-98); a
+ // command run from a column's tag, that column. The finder's is
+ // never the last column for them.
+ .command => layout.acmePlace(p, p.exec_column orelse p.ncol - 1, null, id),
+ .errors => layout.acmePlace(p, away orelse p.ncol - 1, null, id),
+ // makenewwindow(nil) for 9P's new (acme.c:877), else (t).
+ .fs => layout.acmePlace(p, acmeColumn(p, from), null, id),
+ .shell, .doc => layout.acmePlace(p, acmeColumn(p, from), asked, id),
}
// No pane is made shorter than its tag and two rows: where the place
// chosen has not the room, the column's tallest pane gives it, and
@@ -1274,90 +1243,6 @@ fn columnOf(p: *Pardes, id: usize) usize {
return if (layout.findPane(p, id)) |f| f.col else p.ncol - 1;
}
-/// The placements pardes had before it took acme's: an empty column whose
-/// tag asked, or has the keyboard, is filled; a scratch goes under the
-/// asking pane, a shell under it or the nearest pane with room, a document
-/// beside the last one read or in a column of its own, and a command pane
-/// at the foot of the last column.
-fn pardesPlace(p: *Pardes, from: usize, id: usize, kind: NewPane) void {
- const empty = if (p.exec_column orelse if (p.header_focus) p.header_column else null) |c|
- (if (c < p.ncol and p.col_n[c] == 0) c else null)
- else
- null;
- if (empty) |c| {
- layout.insert(p, c, 0, id);
- p.panes[id].?.vweight = 1;
- return;
- }
- const nt = p.panes[id].?;
- switch (kind) {
- .scratch, .fs => if (layout.findPane(p, from)) |sf| {
- layout.insert(p, sf.col, layout.groupEnd(p, sf.col, sf.idx), id);
- layout.splitBelow(p, from, nt);
- } else atFoot(p, id),
- .shell => belowParent(p, from, id),
- .doc, .errors => pardesDoc(p, from, id),
- .command => {
- const rc = p.exec_column orelse p.ncol - 1;
- if (p.col_n[rc] > 0) belowParent(p, p.col_panes[rc][p.col_n[rc] - 1], id) else layout.insert(p, rc, 0, id);
- },
- }
-}
-
-/// Where a pane goes when the one it would go under is in no column (Delcol
-/// took them all, or it was never placed): the foot of the active column,
-/// else of the last.
-fn atFoot(p: *Pardes, id: usize) void {
- const c = p.activeColumn() orelse p.ncol - 1;
- layout.insert(p, c, p.col_n[c], id);
- if (p.col_n[c] == 1) p.panes[id].?.vweight = 1;
-}
-
-fn belowParent(p: *Pardes, from: usize, id: usize) void {
- const parent = layout.splitParent(p, from);
- const f = layout.findPane(p, parent) orelse return atFoot(p, id);
- layout.insert(p, f.col, layout.groupEnd(p, f.col, f.idx), id);
- layout.splitBelow(p, parent, p.panes[id].?);
-}
-
-fn pardesDoc(p: *Pardes, from_id: usize, free: usize) void {
- const nt = p.panes[free].?;
- const doc = if (nt.file) |f| panes.Output.fileTraits(f.output).doc else true; // an image is a doc
- var src_id: ?usize = null;
- if (p.panes[from_id]) |src| if (if (src.file) |f| panes.Output.fileTraits(f.output).doc else src.image != null or src.hasPdf()) {
- src_id = from_id;
- };
- if (doc and src_id == null) {
- var n = p.njumps;
- while (n > 0) : (n -= 1) {
- const j = p.jumps[n - 1];
- const pp = p.panes[j.pane] orelse continue;
- if (pp.serial != j.serial) continue;
- if (if (pp.file) |f| panes.Output.fileTraits(f.output).doc else pp.image != null or pp.hasPdf()) {
- src_id = j.pane;
- break;
- }
- }
- }
- if (doc and src_id == null) for (p.panes, 0..) |sl, i| {
- if (sl) |pp| if (i != free and (if (pp.file) |f| panes.Output.fileTraits(f.output).doc else pp.image != null or pp.hasPdf())) {
- src_id = i;
- break;
- };
- };
- if (!doc) if (layout.findPane(p, from_id)) |sf| {
- layout.insert(p, sf.col, layout.groupEnd(p, sf.col, sf.idx), free);
- layout.splitBelow(p, from_id, nt); // NOT splitParent: no bystander pays
- return;
- };
- if (src_id == null and doc and p.ncol < MAX_COLS and
- layout.columnFitsHalves(p, from_id, 100) and layout.splitColumn(p, from_id, free, true))
- return;
- // Without room for a first-document column, split the Look origin
- // just like Term. Never displace (or evict) a top-left bystander.
- belowParent(p, src_id orelse from_id, free);
-}
-
test "the acme chords act once per selection, not once on the primary" {
const gpa = std.testing.allocator;
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 });