summaryrefslogtreecommitdiff
path: root/src/pardes.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/pardes.zig')
-rw-r--r--src/pardes.zig359
1 files changed, 16 insertions, 343 deletions
diff --git a/src/pardes.zig b/src/pardes.zig
index 4e10aa00..9e6a2d7f 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -173,7 +173,7 @@ pub fn topbarPaneBorderPixels(cell_h: u32, tagline_h: u32) u32 {
pub fn taglineOriginCol(p: *const Pardes, col: u16, row: u16) f32 {
if (row < p.topBarHeight()) return 0;
- if (row < p.topBarHeight() + p.columnBarHeight()) {
+ if (row < p.topBarHeight() + layout.columnBarHeight(p)) {
for (p.col_x[0..p.ncol], p.col_w[0..p.ncol]) |x, w|
if (col >= x and col - x < w) return @floatFromInt(x);
}
@@ -190,7 +190,7 @@ pub fn gridColAt(p: ?*const Pardes, x: f32, row: u16, body_w: f32, tagline_w: f3
const body = @max(body_w, 1);
const tag = @max(tagline_w, 1);
if (row < (if (p) |core| core.topBarHeight() else TOPBAR_H)) return colFromSpan(x, tag);
- if (p) |core| if (row < core.topBarHeight() + core.columnBarHeight()) {
+ if (p) |core| if (row < core.topBarHeight() + layout.columnBarHeight(core)) {
for (core.col_x[0..core.ncol], core.col_w[0..core.ncol]) |origin, width| {
if (width == 0) continue;
const left = @as(f32, @floatFromInt(origin)) * body;
@@ -551,7 +551,7 @@ test "TreeContext tag style preserves message rows and its opt-out survives rest
// right aligned a cell short of that edge.
try std.testing.expectEqual(r.x + r.w, band.viewport.x + band.viewport.w);
try std.testing.expect(band.viewport.w < r.w - config.GUTTER);
- try std.testing.expectEqualStrings("!", band.cells[p.tagCapacity(band.viewport.w) - 2].grapheme());
+ try std.testing.expectEqualStrings("!", band.cells[layout.tagCapacity(p, band.viewport.w) - 2].grapheme());
pane.msg_len = 0;
p.leader_on = true;
p.sync();
@@ -772,7 +772,7 @@ test "a frame no one watches is not drawn, and is drawn once someone does" {
test "an empty column shows its theme's empty_col under its tag: acme's white, else the border" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 20 });
defer p.deinit();
- p.newColumn(0);
+ layout.newColumn(p, 0);
tagline.exitHeader(p);
inline for (.{ "acme", "dark" }) |name| {
try std.testing.expect(p.executeBuiltinLine(0, "Theme " ++ name));
@@ -787,31 +787,6 @@ test "an empty column shows its theme's empty_col under its tag: acme's white, e
}
}
-test "dragging a column's only pane to another leaves that column in place, empty" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 32 });
- defer p.deinit();
- p.newColumn(0);
- p.newScratchIn(0, p.activeColumn().?);
- const moved = p.active;
- p.sync();
- const weights = p.col_weight;
- const tag_serial = p.col_serial[1];
- layout.movePane(p, moved, p.col_x[0] + 4, p.rects[0].y + p.rects[0].h / 2);
- p.sync();
- // acme's coldragwin: colclose then coladd (cols.c:516-517); the column
- // left behind keeps its place, width and tag.
- try std.testing.expectEqual(@as(usize, 2), p.ncol);
- try std.testing.expectEqual(@as(usize, 0), p.col_n[1]);
- try std.testing.expectEqual(tag_serial, p.col_serial[1]);
- try std.testing.expectEqualDeep(weights, p.col_weight);
- try std.testing.expectEqual(@as(usize, 2), p.col_n[0]);
- // ...and a pane dragged into the empty column takes it whole.
- layout.movePane(p, moved, p.col_x[1] + 4, p.screen_h / 2);
- p.sync();
- try std.testing.expectEqualSlices(usize, &.{moved}, p.col_panes[1][0..p.col_n[1]]);
- try std.testing.expectEqual(@as(usize, 1), p.col_n[0]);
-}
-
test "unknown Exec from a document runs as a command pane in its directory, typed into no terminal" {
const gpa = std.testing.allocator;
const p = try Pardes.init(gpa, .{});
@@ -1865,8 +1840,8 @@ test "column tag first-cell execution keeps New local to the clicked column" {
const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 20, .tty_only = true });
defer p.deinit();
_ = try p.setTestFile("untouched\n");
- p.newColumn(0);
- p.newScratchIn(0, p.activeColumn().?);
+ layout.newColumn(p, 0);
+ layout.newScratchIn(p, 0, layout.activeColumn(p).?);
p.sync();
for (0..2) |column| {
p.active = p.col_panes[1 - column][0];
@@ -1881,14 +1856,6 @@ test "column tag first-cell execution keeps New local to the clicked column" {
try std.testing.expectEqualStrings("untouched\n", p.panes[0].?.file.?.content);
}
-test "tiny screens keep pane space before adding a column tag" {
- const p = try Pardes.init(std.testing.allocator, .{ .cols = 8, .rows = 2, .tty_only = true });
- defer p.deinit();
- try std.testing.expectEqual(@as(u16, 0), p.columnBarHeight());
- try std.testing.expectEqual(TOPBAR_H, p.rects[0].y);
- _ = try p.render(p.scratch.allocator());
-}
-
test "a screen too short for the column row releases a column tag's focus without losing its commands" {
const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12, .tty_only = true });
defer p.deinit();
@@ -1902,7 +1869,7 @@ test "a screen too short for the column row releases a column tag's focus withou
try std.testing.expect(p.header_focus and p.header_column != null);
p.update(.{ .resize = .{ .cols = 60, .rows = 2 } });
- try std.testing.expectEqual(@as(u16, 0), p.columnBarHeight());
+ try std.testing.expectEqual(@as(u16, 0), layout.columnBarHeight(p));
try std.testing.expectEqual(TOPBAR_H, p.rects[0].y);
try std.testing.expect(!p.header_focus and p.header_column == null);
p.update(.{ .resize = .{ .cols = 60, .rows = 12 } });
@@ -1916,104 +1883,6 @@ pub const newer_build_words = "a newer pardes is installed: Upgrade (SPC s U) mo
pub const PendingWrite = struct { bytes: []u8, off: usize = 0 };
-test "a new column takes width only from the column that created it" {
- const p = try Pardes.init(std.testing.allocator, .{ .cols = 124, .rows = 24 });
- defer p.deinit();
-
- _ = try p.newShell(1, "");
- try std.testing.expect(layout.splitColumn(p, 0, 1, false));
- _ = try p.newShell(2, "");
- try std.testing.expect(layout.splitColumn(p, 0, 2, true));
- p.sync();
-
- const left_before = p.rects[2];
- const right_before = p.rects[1];
- _ = try p.newShell(3, "");
- try std.testing.expect(layout.splitColumn(p, 0, 3, false));
- p.sync();
-
- try std.testing.expectEqual(left_before.x, p.rects[2].x);
- try std.testing.expectEqual(left_before.w, p.rects[2].w);
- try std.testing.expectEqual(right_before.x, p.rects[1].x);
- try std.testing.expectEqual(right_before.w, p.rects[1].w);
- try std.testing.expectEqual(@as(u16, 16), p.rects[0].w);
- try std.testing.expectEqual(@as(u16, 15), p.rects[3].w);
-
- const narrow = try Pardes.init(std.testing.allocator, .{ .cols = config.MINW * 2 - 1, .rows = 10 });
- defer narrow.deinit();
- try std.testing.expect(!layout.splitColumn(narrow, 0, 1, false));
- try std.testing.expectEqual(@as(usize, 1), narrow.ncol);
-
- const sequential = try Pardes.init(std.testing.allocator, .{ .cols = config.MINW * 2, .rows = 10 });
- defer sequential.deinit();
- _ = try sequential.newShell(1, "");
- try std.testing.expect(layout.splitColumn(sequential, 0, 1, false));
- _ = try sequential.newShell(2, "");
- try std.testing.expect(!layout.splitColumn(sequential, 0, 2, false));
- try std.testing.expectEqual(@as(usize, 2), sequential.ncol);
-
- const coarse = try Pardes.init(std.testing.allocator, .{ .cols = 22, .rows = 10 });
- defer coarse.deinit();
- coarse.col_weight[0] = 3;
- _ = try coarse.newShell(1, "");
- try std.testing.expect(layout.splitColumn(coarse, 0, 1, false));
- coarse.sync();
- try std.testing.expectEqual(@as(u16, 11), coarse.col_w[0]);
- try std.testing.expectEqual(@as(u16, 11), coarse.col_w[1]);
-
- const extreme = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 20 });
- defer extreme.deinit();
- _ = try extreme.newShell(1, "");
- try std.testing.expect(layout.splitColumn(extreme, 0, 1, false));
- _ = try extreme.newShell(2, "");
- layout.insert(extreme, 0, 1, 2);
- extreme.col_weight[0] = std.math.maxInt(u64) / 2 + 2; // odd and cannot double
- extreme.col_weight[1] = 1;
- layout.compute(extreme);
- const panes_before = extreme.col_panes;
- const counts_before = extreme.col_n;
- const weights_before = extreme.col_weight;
- const source_vweight = extreme.panes[0].?.vweight;
- const sibling_vweight = extreme.panes[2].?.vweight;
- try std.testing.expect(!layout.splitColumn(extreme, 0, 0, false));
- try std.testing.expectEqual(panes_before, extreme.col_panes);
- try std.testing.expectEqual(counts_before, extreme.col_n);
- try std.testing.expectEqual(weights_before, extreme.col_weight);
- try std.testing.expectEqual(source_vweight, extreme.panes[0].?.vweight);
- try std.testing.expectEqual(sibling_vweight, extreme.panes[2].?.vweight);
-}
-
-test "Newcol refuses an unsplittable restored weight before spawning" {
- const p = try Pardes.init(std.testing.allocator, .{ .cols = 200, .rows = 20 });
- defer p.deinit();
-
- for (1..4) |id| {
- _ = try p.newShell(id, "");
- try std.testing.expect(layout.splitColumn(p, id - 1, id, false));
- }
- const restored_cap = std.math.maxInt(u64) / 6;
- for (0..4) |column| p.col_weight[column] = restored_cap;
- p.col_weight[3] -= 1;
- for ([_]usize{ 3, 2, 1 }) |id| {
- const pane = p.panes[id].?;
- try panes.deinitPane(p, pane);
- layout.removePane(p, id);
- layout.dropColumn(p, id);
- p.panes[id] = null;
- }
- while (p.nextEffect()) |_| {}
-
- try std.testing.expect(p.col_weight[0] > std.math.maxInt(u64) / 2);
- try std.testing.expect(p.col_weight[0] % 2 == 1);
- try std.testing.expect(!layout.canSplitCol(p, layout.findPane(p, 0).?.col));
- const panes_before = p.panes;
- const serial_before = p.next_serial;
- try std.testing.expect(p.executeBuiltinLine(0, "Newcol"));
- try std.testing.expectEqual(panes_before, p.panes);
- try std.testing.expectEqual(serial_before, p.next_serial);
- try std.testing.expect(p.nextEffect() == null);
-}
-
test "screen resize keeps its previous storage until allocation succeeds" {
var failing: std.testing.FailingAllocator = .init(std.testing.allocator, .{});
const p = try Pardes.init(failing.allocator(), .{ .cols = 80, .rows = 24, .tty_only = true });
@@ -2036,39 +1905,6 @@ test "screen resize keeps its previous storage until allocation succeeds" {
try std.testing.expectEqual(@as(usize, 81 * 25), resized.cells.len);
}
-test "repeated non-dyadic column splits preserve every unrelated boundary" {
- const p = try Pardes.init(std.testing.allocator, .{ .cols = 979, .rows = 20 });
- defer p.deinit();
-
- _ = try p.newShell(1, "");
- try std.testing.expect(layout.splitColumn(p, 0, 1, false));
- p.sync();
-
- const handle = p.col_x[0] + p.col_w[0] - 1;
- const untouched = p.col_weight;
- p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = TOPBAR_H + 1 } });
- p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = handle, .row = TOPBAR_H + 1 } });
- try std.testing.expectEqual(untouched, p.col_weight);
-
- p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = TOPBAR_H + 1 } });
- p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = 417, .row = TOPBAR_H + 1 } });
- p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = 417, .row = TOPBAR_H + 1 } });
- p.sync();
- try std.testing.expectEqual(@as(u16, 418), p.rects[0].w);
-
- _ = try p.newShell(2, "");
- try std.testing.expect(layout.splitColumn(p, 1, 2, false));
- p.sync();
- const left_before = p.rects[0];
- const middle_before = p.rects[1];
-
- _ = try p.newShell(3, "");
- try std.testing.expect(layout.splitColumn(p, 2, 3, false));
- p.sync();
- try std.testing.expectEqual(left_before, p.rects[0]);
- try std.testing.expectEqual(middle_before, p.rects[1]);
-}
-
pub const Rect = layout.Rect;
/// The session layouts `init` can put on screen. One name each, so choosing
@@ -2539,6 +2375,14 @@ pub const Pardes = struct {
/// `p.executeBuiltinLine(...)`; it lives with the rest of exec in exec.zig.
pub const executeBuiltinLine = exec.executeBuiltinLine;
+ /// Geometry, called from everywhere as `p.bodyTop(pane, r)` and the rest
+ /// (setActiveColumn and tagTop by Store.zig and Handover.zig); it lives with the
+ /// columns in layout.zig.
+ pub const topBarHeight = layout.topBarHeight;
+ pub const bodyTop = layout.bodyTop;
+ pub const tagTop = layout.tagTop;
+ pub const setActiveColumn = layout.setActiveColumn;
+
/// Pane slots, called from everywhere as `p.freeSlot()` and the rest
/// (emitSpawn and installPane by dump.zig); they live with the panes
/// in panes.zig.
@@ -2926,68 +2770,6 @@ pub const Pardes = struct {
return r;
}
- /// The workspace tag's height: one row while the setting keeps it, as
- /// acme's row tag is, zero once a native shell takes its commands over.
- /// Layout and hit testing read this rather than the constant, the way
- /// they read `columnBarHeight`.
- pub fn topBarHeight(p: *const Pardes) u16 {
- if (!p.settings.workspace_tag) return 0;
- return TOPBAR_H;
- }
-
- /// The column tags' height: one row, as acme's (cols.c:244, colresize,
- /// gives a column tag one font height); a newline in one is a space
- /// (tagline.flattenHeaders).
- pub fn columnBarHeight(p: *const Pardes) u16 {
- if (p.screen_h < 3) return 0;
- return COLBAR_H;
- }
-
- /// Newcol: an empty column right of the calling pane's, the keyboard
- /// on its tag, for the next pane made to fill.
- pub fn newColumn(p: *Pardes, from_id: usize) void {
- // An empty window (Delcol took the last column): its first column.
- if (layout.firstColumn(p)) |c| return tagline.enterHeader(p, c);
- const keyboard_col = p.keyboardColumn(from_id) orelse return;
- // Asked from the finder: the new column goes left of it, so the
- // finder stays at the edge as wide.
- const in_finder = p.finder.column(p) == keyboard_col;
- const before_finder = in_finder and keyboard_col == 0;
- const col = if (in_finder and keyboard_col > 0) keyboard_col - 1 else keyboard_col;
- // A trial: laying it out gives it a serial (layout.compute), which a
- // refusal takes back. Every other column has its own already, so
- // the counter as it is now is the trial's to return to.
- for (0..p.ncol) |k| _ = layout.columnSerial(p, k);
- const unspent = p.next_column_serial;
- const before_min = layout.minima(p);
- const before = p.rects;
- // Said, not silently nothing: "no space" is 9ns's word for ENOSPC.
- const c = layout.insertColumnUnannounced(p, col, before_finder) orelse {
- var said: [96]u8 = undefined;
- return p.reportFailure(from_id, if (p.ncol >= MAX_COLS)
- std.fmt.bufPrint(&said, "Newcol: no space for a column: {d} max", .{MAX_COLS}) catch "Newcol: no space for a column"
- else
- "Newcol: no space for a column: this one is too narrow to split");
- };
- if (!layout.keepColumn(p, c, &before, &before_min)) {
- p.next_column_serial = unspent;
- layout.compute(p);
- return p.reportFailure(from_id, "Newcol: no space for a column: the panes' tags would not fit");
- }
- // Kept: now it has a serial, and the log hears of it.
- layout.noteColumn(p, "newcol", layout.columnSerial(p, c));
- tagline.enterHeader(p, c);
- }
-
- pub fn setActiveColumn(p: *Pardes, c: usize) void {
- if (c < p.ncol) p.active_column = layout.columnSerial(p, c);
- }
-
- /// The active column, while it is still there.
- pub fn activeColumn(p: *const Pardes) ?usize {
- return layout.columnBySerial(p, p.active_column);
- }
-
/// DECSET 1004: a program that asked is told `CSI I` when its pane
/// takes the keyboard (the active pane, its body, the window focused)
/// and `CSI O` when it gives it up, to another pane, a tag or header,
@@ -3007,27 +2789,6 @@ pub const Pardes = struct {
p.focus_told = want;
}
- pub fn noteTyped(p: *Pardes) void {
- if (p.header_focus) {
- if (p.header_column) |c| p.setActiveColumn(c);
- } else if (layout.findPane(p, p.active)) |f| p.setActiveColumn(f.col);
- }
-
- /// New, run from column `c`'s tag.
- pub fn newScratchIn(p: *Pardes, from_id: usize, c: usize) void {
- p.exec_column = c;
- defer p.exec_column = null;
- p.newScratchBelow(from_id);
- }
-
- /// The column a command acts on: the one whose tag it came from, else
- /// the one whose tag has the keyboard, else `id`'s.
- pub fn keyboardColumn(p: *Pardes, id: usize) ?usize {
- if (p.exec_column) |c| return c;
- if (p.header_focus) if (p.header_column) |c| return c;
- return if (layout.findPane(p, id)) |f| f.col else null;
- }
-
pub fn emitWrite(p: *Pardes, id: usize, bytes: []const u8) void {
var off: usize = 0;
// Anything already parked for this pane owns the stream's position, so
@@ -3926,63 +3687,6 @@ pub const Pardes = struct {
p.setMessage(p.active, std.fmt.bufPrint(&buf, "WindowOpacity: {s}", .{reason[0..@min(reason.len, 240)]}) catch "WindowOpacity: compositor rejected the request");
}
- /// Delcol: close column `col` and every pane in it.
- pub fn removeColumn(p: *Pardes, col: usize) !void {
- if (col >= p.ncol) return;
- const had_focus = p.keyboardColumn(p.active) == col;
- const beside = if (had_focus) p.besideColumn(col, if (p.header_focus) null else p.rects[p.active]) else null;
- var ids: [MAX_PANES]usize = undefined;
- var parents: [MAX_PANES]*Pane = undefined;
- const count = p.col_n[col];
- for (0..count) |i| {
- ids[i] = p.col_panes[col][i];
- parents[i] = p.panes[ids[i]].?;
- }
- try panes.detachCwds(p, parents[0..count]);
- for (ids[0..count], parents[0..count]) |closed, pane| {
- // Kept for Panes; its column goes, so it comes back as a new pane.
- if (p.store.keep(p, closed)) |k| p.store.close(p, k, null);
- panes.retirePane(p, pane);
- layout.removePane(p, closed);
- p.panes[closed] = null;
- }
- layout.dropColumn(p, col);
- // The last column gone, the window stays, empty but for the
- // workspace tag, as acme's does; Newcol starts again from there.
- if (p.panes[p.active] == null) p.active = beside orelse panes.anyPane(p) orelse return tagline.enterHeader(p, null);
- }
-
- /// The pane that takes over the keyboard from column `col`: in the
- /// column layout.dropColumn gives the width to, the one level with the
- /// middle of `r` (of the screen without one). Asked while rects hold.
- pub fn besideColumn(p: *const Pardes, col: usize, r: ?Rect) ?usize {
- if (p.ncol < 2) return null;
- const next = if (col > 0) col - 1 else col + 1;
- const mid = if (r) |at| at.y + at.h / 2 else p.screen_h / 2;
- var pick: ?usize = null;
- for (p.col_panes[next][0..p.col_n[next]]) |k| {
- if (p.panes[k] == null) continue;
- pick = k;
- if (p.rects[k].y +| p.rects[k].h > mid) break;
- }
- return pick;
- }
-
- /// The rows pane `id`'s tag takes at its width, wrapped as `sync` wraps
- /// it: what a placement must leave it above its body rows.
- pub fn wantedTagRows(p: *Pardes, id: usize) u16 {
- const pane = p.panes[id] orelse return BOX_H;
- if (pane.collapsed or !pane.tag_expanded) return BOX_H;
- if (p.rects[id].w == 0) return pane.tag_rows; // never laid out
- var wrap_room: [32 * 1024]u8 = undefined;
- var wrap_fba = std.heap.FixedBufferAllocator.init(&wrap_room);
- const wa = wrap_fba.allocator();
- const prefix = tagline.prefixIn(p, wa, pane) catch return pane.tag_rows;
- const whole = std.mem.concat(wa, u8, &.{ prefix, tagline.curTail(pane) }) catch return pane.tag_rows;
- const shown = tagline.wrapTag(wa, whole, tagline.tagWidth(p, id)) catch return pane.tag_rows;
- return @intCast(@max(BOX_H, @min(shown.rows(), MAX_TAG_ROWS)));
- }
-
/// Recompute geometry, push grid-size changes to each emulator and pty,
/// fire deferred greetings.
pub fn sync(p: *Pardes) void {
@@ -3997,7 +3701,7 @@ pub const Pardes = struct {
// A file opened or closed this step: the kept list follows.
p.saveRecent();
tagline.flattenHeaders(p);
- if (p.header_column != null and p.columnBarHeight() == 0) {
+ if (p.header_column != null and layout.columnBarHeight(p) == 0) {
tagline.exitHeader(p);
}
panes.reapPanes(p);
@@ -4299,37 +4003,6 @@ pub const Pardes = struct {
return p.haptic;
}
- /// A frontend's tag hit, if what it names is still there: resolved on
- /// the place it carries (Layer.Place), not on this process's frame.
- pub fn reprojectTagHit(p: *const Pardes, tag_hit: TagHit) ?TagHit {
- if (tag_hit.kind == .pane) {
- if (tag_hit.id >= p.panes.len) return null;
- const pane = p.panes[tag_hit.id] orelse return null;
- if (pane.serial != tag_hit.serial) return null;
- }
- if (tag_hit.kind == .column and (tag_hit.id >= p.ncol or p.col_serial[tag_hit.id] != tag_hit.serial)) return null;
- return Layer.tagAgain(tag_hit);
- }
-
- /// The pane's first body row: under the tag when it is on top, over it
- /// when it is at the bottom. Notice bands do NOT move it -- they are an
- /// overlay, drawn over the top rows rather than taking them.
- pub fn bodyTop(p: *const Pardes, pane: *const Pane, r: Rect) u16 {
- return if (p.settings.tag_bottom) r.y else r.y + pane.tag_rows;
- }
-
- /// The tag's first row: the pane's top, or its last rows with Tagbottom.
- pub fn tagTop(p: *const Pardes, pane: *const Pane, r: Rect) u16 {
- return if (p.settings.tag_bottom) r.y + r.h -| pane.tag_rows else r.y;
- }
-
- pub fn tagCapacity(p: *const Pardes, physical_width: u16) u16 {
- const layer: Layer = .{ .kind = .pane, .viewport = .{ .x = 0, .y = 0, .w = physical_width, .h = 1 } };
- return layer.capacity(p.row_metrics);
- }
-
- // ---- render: build the canonical surface (draw.zig) ----
-
pub const render = draw.render;
pub fn appendImagePlace(p: *Pardes, place: ImagePlace) bool {