summaryrefslogtreecommitdiff
path: root/core/Core.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/Core.zig')
-rw-r--r--core/Core.zig87
1 files changed, 78 insertions, 9 deletions
diff --git a/core/Core.zig b/core/Core.zig
index 4c8aa2eb..835eb86c 100644
--- a/core/Core.zig
+++ b/core/Core.zig
@@ -87,7 +87,19 @@ const Pardes = @This();
/// One client's view of the session (views.zig): its screen and layout,
/// its focus, its pointer and gestures, its jumps, its key prefixes.
pub const View = struct {
- pub const replica = .{ .len = .{ .{ "leader_keys", "leader_n" }, .{ "col_x", "ncol" }, .{ "col_w", "ncol" } } };
+ pub const replica = .{
+ .len = .{ .{ "leader_keys", "leader_n" }, .{ "cols", "ncol" }, .{ "col_x", "ncol" }, .{ "col_w", "ncol" } },
+ // What its keyboard is on: a pane there; window mode's outline and
+ // a kind's press and hover, slots; its screen, a grid a frontend
+ // sizes (walk.zig `.index`).
+ .index = .{ .{ "active", Pardes, "focusPanes" }, .{ "window_pick", Pardes, "panes" }, .{ "kind_grab", Pardes, "panes" }, .{ "kind_hover", Pardes, "panes" }, .{ "screen_w", "grids" }, .{ "screen_h", "grids" } },
+ // Its geometry, read back as the session holds it (a view opened
+ // and not laid out yet has none, on a join's client too, whose
+ // kinds are told its views as the session's are): on its screen,
+ // a pane's rect and a column's `col_x` with its width (walk.zig
+ // `.within`).
+ .within = .{ .{ "rects", "onScreen" }, .{ "col_w", "columnOnScreen" } },
+ };
/// A view's slot in `Pardes.views`, as it crosses the core's edge: an
/// entry's argument or answer, the wire's welcome. A type of its own,
/// so a pane's slot (`Pane.Id`) is not taken for it; the core's own
@@ -202,6 +214,28 @@ pub const View = struct {
pastes: u32 = 0,
links: u32 = 0,
link: pardes.Effect.Buf(256) = .{},
+
+ /// A side of a grid a frontend sizes: a cell at least (a zero is
+ /// refused, not clamped, as the wire refuses one: abi/wire.zig
+ /// `getCols`), past no display's (a frame is as many cells as it
+ /// holds, Surface.cells: a damaged image's asked 111 GB).
+ pub fn grids(_: *const View, n: usize) bool {
+ return n >= 1 and n <= max_grid;
+ }
+ pub const max_grid = 4096;
+
+ /// Pane slot `id`'s rect on the screen, where the layout pass puts
+ /// every one (a frame is the screen's cells: one past it, drawn, is a
+ /// cell outside the frame).
+ pub fn onScreen(v: *const View, id: usize) bool {
+ const r = v.rects[id];
+ return @as(u32, r.x) + r.w <= v.screen_w and @as(u32, r.y) + r.h <= v.screen_h;
+ }
+
+ /// Column `c` on the screen: its left edge and its width.
+ pub fn columnOnScreen(v: *const View, c: usize) bool {
+ return @as(u32, v.col_x[c]) + v.col_w[c] <= v.screen_w;
+ }
};
gpa: std.mem.Allocator,
@@ -475,6 +509,11 @@ pub const replica = .{
"in_head", "in_len",
// The views no frontend here draws (views.zig).
"undrawn",
+ // A step's own, set and put back within it (a key's replay across
+ // the ranges, normal.replaySels; a word's run, exec.zig): as
+ // `init` makes them between any two steps.
+ "multi_first", "multi_stop", "multi_index",
+ "multi_count", "exec_depth", "exec_column",
// How this process was started, and the last dump it made for
// its host to write: a session loaded elsewhere has its own.
"opts", "dump_out", "dump_export",
@@ -487,8 +526,38 @@ pub const replica = .{
// server's own part of `fs` says so in fs.Namespace.)
.authority = .{ "host", "store", "recent", "db", "fallback" },
.len = .{ .{ "look_src", "n_look_src" }, .{ "session_dir", "session_dir_len" }, .{ "session_home", "session_home_len" }, .{ "session_shell", "session_shell_len" } },
+ // The live view is an open one; a ThemeFile's pane a slot (walk.zig
+ // `.index`).
+ .index = .{ .{ "live", "openViews" }, .{ "theme_file_pane", "panes" } },
+ // A pane another build's dump could not give: out of every layout.
+ .left_out = "dropMissing",
};
+/// What an index into the session names (walk.zig `.index`): an open view.
+pub fn openViews(p: *const Pardes, k: usize) bool {
+ return k < Views.max and p.views[k] != null;
+}
+
+/// A pane there.
+pub fn openPanes(p: *const Pardes, id: usize) bool {
+ return id < MAX_PANES and p.panes[id] != null;
+}
+
+/// What a view's keyboard may be on: a pane there, or any slot in a window
+/// with none (the last column's Delcol leaves one, layout.zig `delColumn`).
+pub fn focusPanes(p: *const Pardes, id: usize) bool {
+ if (id >= MAX_PANES) return false;
+ if (p.panes[id] != null) return true;
+ return for (p.panes) |slot| {
+ if (slot != null) break false;
+ } else true;
+}
+
+/// The panes a view's columns list that are not there (another build's
+/// dump left them out: walk.zig `left_out`) taken out of them, and its
+/// keyboard on one that is.
+pub const dropMissing = pardes.dump.dropMissing;
+
/// The message row's entry points, called from everywhere as
/// `p.setMessage(...)`; they live with the rest of it in Messages.zig.
pub const setStatus = Messages.setStatus;
@@ -1684,7 +1753,7 @@ fn updateInner(p: *Pardes, ev: Event) void {
v.cell_pixels.w = @max(1, sz.cell_pixels.w);
v.cell_pixels.h = @max(1, sz.cell_pixels.h);
layout.compute(p);
- p.resize_count += 1;
+ p.resize_count +|= 1;
},
.output => |o| {
const pane = p.panes[o.pane.index()] orelse return;
@@ -1923,7 +1992,7 @@ pub fn sync(p: *Pardes) void {
// had any; a folded pane shows its first line only. Its prefix
// is made once, on the stack: this runs on every event, and not
// every event may take from the scratch arena.
- var wrap_room: [32 * 1024]u8 = undefined;
+ var wrap_room: [Pane.prefix_room]u8 = undefined;
var wrap_fba = std.heap.FixedBufferAllocator.init(&wrap_room);
const wa = wrap_fba.allocator();
const prefix: ?[]const u8 = tagline.prefixIn(p, wa, pane) catch null;
@@ -2217,9 +2286,9 @@ pub const PendingWrite = struct { bytes: []u8, off: usize = 0 };
/// 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 (core/replica.zig).
+ /// Its panes, as far as `n` says (what a digest, a dump and a copy take),
+ /// each a pane there (walk.zig `.index`).
+ pub const replica = .{ .len = .{.{ "panes", "n" }}, .index = .{.{ "panes", Pardes, "openPanes" }} };
panes: [MAX_PANES]usize = @splat(0),
n: usize = 0,
weight: u64 = column_weight_unit,
@@ -3871,11 +3940,11 @@ test "raw terminal cursor follows its active row only while that row is visible"
try std.testing.expectEqual(rect.x + config.GUTTER + 3, live.x);
try std.testing.expectEqual(body_y + 2, live.y);
- pane.scrollBy(-1);
+ pane.scrollBy(p.settings.tab, -1);
const scrolled = (try p.render(frame.allocator())).cursor orelse return error.MissingCursor;
try std.testing.expectEqual(live.x, scrolled.x);
try std.testing.expectEqual(live.y + 1, scrolled.y);
- pane.scrollBy(-@as(i32, pane.rows));
+ pane.scrollBy(p.settings.tab, -@as(i32, pane.rows));
try std.testing.expect((try p.render(frame.allocator())).cursor == null);
pane.followOutput();
const returned = (try p.render(frame.allocator())).cursor orelse return error.MissingCursor;
@@ -3929,7 +3998,7 @@ test "tty output follows only from the bottom" {
try std.testing.expect(bottom > 0);
// Scrolled back, the reader stays put however much the shell prints.
- sp.scrollBy(-10);
+ sp.scrollBy(p.settings.tab, -10);
p.sync();
const parked = sp.termTop();
try std.testing.expect(parked < bottom);