summaryrefslogtreecommitdiff
path: root/src/Core.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/Core.zig')
-rw-r--r--src/Core.zig62
1 files changed, 36 insertions, 26 deletions
diff --git a/src/Core.zig b/src/Core.zig
index fa39f884..8d88fcbd 100644
--- a/src/Core.zig
+++ b/src/Core.zig
@@ -105,16 +105,12 @@ reserved_slots: [MAX_PANES]bool = @splat(false),
retired_panes: RetiredPanes = .{},
// layout: columns own x by weight; panes own y by vweight within a column.
ncol: usize = 0,
-col_weight: [MAX_COLS]u64 = @splat(column_weight_unit),
-// Zeroed, not undefined: a digest takes the whole of it, a release
-// build's heap leaves its unused slots whatever was there before, and
-// two replicas must agree on them (src/replica.zig).
-col_panes: [MAX_COLS][MAX_PANES]usize = @splat(@splat(0)),
-col_n: [MAX_COLS]usize = @splat(0),
+cols: [MAX_COLS]Column = @splat(.{}),
/// Each column's tag and the workspace's: Texts like a pane's tag, with
-/// no prefix, showing a default until someone edits them.
+/// no prefix, showing a default until someone edits them. Not the
+/// Column's: a view opened takes the live one's columns (views.open) but
+/// tags of its own.
col_tags: [MAX_COLS]Text = @splat(.{ .what = .column }),
-col_serial: [MAX_COLS]u32 = @splat(0),
next_column_serial: u32 = 1,
/// The finder column, where query panes stack with SearchPlace column
/// (Finder.zig).
@@ -609,11 +605,11 @@ fn initSession(gpa: std.mem.Allocator, opts: Options) !*Pardes {
_ = try p.newShell(2, "");
for (p.panes[0..3]) |slot| slot.?.greet = true;
p.ncol = 2;
- p.col_n[0] = 2;
- p.col_panes[0][0] = 0;
- p.col_panes[0][1] = 1;
- p.col_n[1] = 1;
- p.col_panes[1][0] = 2;
+ p.cols[0].n = 2;
+ p.cols[0].panes[0] = 0;
+ p.cols[0].panes[1] = 1;
+ p.cols[1].n = 1;
+ p.cols[1].panes[0] = 2;
},
.shell => {
_ = try p.newShell(0, "");
@@ -646,8 +642,8 @@ fn initSession(gpa: std.mem.Allocator, opts: Options) !*Pardes {
/// The layout every single-pane boot starts from.
fn oneColumn(p: *Pardes) void {
p.ncol = 1;
- p.col_n[0] = 1;
- p.col_panes[0][0] = 0;
+ p.cols[0].n = 1;
+ p.cols[0].panes[0] = 0;
}
/// The recent list's own allocator: it is kept best effort (a file not
@@ -2089,6 +2085,20 @@ pub const PendingWrite = struct { bytes: []u8, off: usize = 0 };
/// The session layouts `init` can put on screen. One name each, so choosing
/// between them reads as a choice instead of a chain of ifs over four options.
+/// A column (acme's Column, cols.c): its panes top to bottom, its share of
+/// the width and its serial. Its tag is the session's `col_tags`, and its
+/// place on screen (`col_x`, `col_w`) is worked out each sync, as a pane's
+/// rect is.
+pub const Column = struct {
+ // Zeroed, not undefined: a digest takes the whole of it, a release
+ // build's heap leaves its unused slots whatever was there before, and
+ // two replicas must agree on them (src/replica.zig).
+ panes: [MAX_PANES]usize = @splat(0),
+ n: usize = 0,
+ weight: u64 = column_weight_unit,
+ serial: u32 = 0,
+};
+
pub const Boot = enum {
/// the document named on the command line, or the pane explaining why not
document,
@@ -3564,13 +3574,13 @@ test "column tag first-cell execution keeps New local to the clicked column" {
layout.newScratchIn(p, 0, layout.activeColumn(p).?);
p.sync();
for (0..2) |column| {
- p.active = p.col_panes[1 - column][0];
+ p.active = p.cols[1 - column].panes[0];
p.presented();
- const before = p.col_n;
+ const before = p.cols;
p.update(.{ .mouse = .{ .button = .middle, .kind = .press, .col = p.col_x[column] + TAG_TEXT_INSET, .row = TOPBAR_H } });
p.update(.{ .mouse = .{ .button = .middle, .kind = .release, .col = p.col_x[column] + TAG_TEXT_INSET, .row = TOPBAR_H } });
- try std.testing.expectEqual(before[column] + 1, p.col_n[column]);
- try std.testing.expectEqual(before[1 - column], p.col_n[1 - column]);
+ try std.testing.expectEqual(before[column].n + 1, p.cols[column].n);
+ try std.testing.expectEqual(before[1 - column].n, p.cols[1 - column].n);
try std.testing.expectEqual(column, layout.findPane(p, p.active).?.col);
}
try std.testing.expectEqualStrings("untouched\n", p.panes[0].?.file.?.content);
@@ -3653,8 +3663,8 @@ test "argv naming nothing boots an errors pane rather than failing the launch" {
// One pane, filling the window, and it is an OUTPUT pane rather than the
// shell a bare `pardes` boots: the answer is the whole screen.
try std.testing.expectEqual(@as(u8, 1), p.ncol);
- try std.testing.expectEqual(@as(usize, 1), p.col_n[0]);
- try std.testing.expectEqual(@as(usize, 0), p.col_panes[0][0]);
+ try std.testing.expectEqual(@as(usize, 1), p.cols[0].n);
+ try std.testing.expectEqual(@as(usize, 0), p.cols[0].panes[0]);
try std.testing.expectEqual(@as(usize, 0), p.active);
for (p.panes[1..]) |slot| try std.testing.expect(slot == null);
const pane = p.panes[0].?;
@@ -3752,22 +3762,22 @@ test "the bare tty startup opens a text pane under the shell, unfocused" {
// One column, shell on top in raw mode, an empty text pane under it.
try std.testing.expectEqual(@as(usize, 1), p.ncol);
- try std.testing.expectEqual(@as(usize, 2), p.col_n[0]);
- const shell = p.panes[p.col_panes[0][0]].?;
- const scratch = p.panes[p.col_panes[0][1]].?;
+ try std.testing.expectEqual(@as(usize, 2), p.cols[0].n);
+ const shell = p.panes[p.cols[0].panes[0]].?;
+ const scratch = p.panes[p.cols[0].panes[1]].?;
try std.testing.expect(shell.isTerminal());
try std.testing.expectEqual(Text.Mode.tty, shell.body.mode);
try std.testing.expect(!scratch.isTerminal());
try std.testing.expectEqualStrings("", scratch.file.?.content);
// ...and the shell keeps the keyboard.
- try std.testing.expectEqual(p.col_panes[0][0], p.active);
+ try std.testing.expectEqual(p.cols[0].panes[0], p.active);
// Unnamed, it is the bare shell every test asks for.
const plain = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
defer plain.deinit();
try std.testing.expectEqual(Boot.tty_shell, plain.boot);
- try std.testing.expectEqual(@as(usize, 1), plain.col_n[0]);
+ try std.testing.expectEqual(@as(usize, 1), plain.cols[0].n);
}
test "tty output follows only from the bottom" {