summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/Core.zig15
-rw-r--r--core/panes.zig15
-rw-r--r--core/views.zig16
3 files changed, 46 insertions, 0 deletions
diff --git a/core/Core.zig b/core/Core.zig
index 769d16cd..85087b11 100644
--- a/core/Core.zig
+++ b/core/Core.zig
@@ -89,6 +89,21 @@ const Pardes = @This();
/// 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" } } };
+ /// 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
+ /// view indexes (`live`, views.zig) keep their integers.
+ pub const Id = enum(u8) {
+ _,
+ /// The id of slot `k`, a slot the core holds.
+ pub fn at(k: usize) Id {
+ return @fromBackingInt(@intCast(k));
+ }
+ /// The slot, to index the core's views with.
+ pub fn index(id: Id) u8 {
+ return @backingInt(id);
+ }
+ };
screen_w: u16 = 0,
screen_h: u16 = 0,
diff --git a/core/panes.zig b/core/panes.zig
index cdc28dba..dd36839a 100644
--- a/core/panes.zig
+++ b/core/panes.zig
@@ -38,6 +38,21 @@ pub const Pane = struct {
// it there).
.alloc = .{ .{ "addon", "image" }, .{ "pdf", "image" }, .{ "terminal", "terminal" } },
};
+ /// A pane's slot in `Pardes.panes`, as it crosses the core's edge: an
+ /// entry's argument or answer, an event's, an effect's, a host call's.
+ /// A type of its own, so a view's slot (`View.Id`) is not taken for
+ /// it; the core's own loops and tables keep their integers.
+ pub const Id = enum(u8) {
+ _,
+ /// The id of slot `i`, a slot the core holds.
+ pub fn at(i: usize) Id {
+ return @fromBackingInt(@intCast(i));
+ }
+ /// The slot, to index the core's tables with.
+ pub fn index(id: Id) u8 {
+ return @backingInt(id);
+ }
+ };
/// The words that throw unsaved text away (builtins.zig warnModified).
pub const Discarding = enum { Exit, Restore, get, Del, Delcol };
diff --git a/core/views.zig b/core/views.zig
index 9d627a17..ee061964 100644
--- a/core/views.zig
+++ b/core/views.zig
@@ -925,3 +925,19 @@ test "a session's dump keeps its views: loaded, each where it was; revived for o
try testing.expectEqual(@as(i32, 30), one.panes[id].?.body.cur_row);
try testing.expectEqual(@as(?u8, 1), one.openView());
}
+
+test "a pane's id and a view's id are two types: neither is taken for the other, nor for an integer" {
+ // An enum coerces into nothing but itself (an enum literal into it, it
+ // into a union of it): two distinct enum types never stand for each
+ // other, so `p.toView(pane_id)` or `p.setMessage(view_id, ..)` does not
+ // compile. What is left to show is that they are two, and a byte each.
+ comptime {
+ std.debug.assert(Pane.Id != View.Id);
+ for (.{ Pane.Id, View.Id }) |T| {
+ const e = @typeInfo(T).@"enum";
+ std.debug.assert(e.tag_type == u8 and e.mode == .nonexhaustive and @sizeOf(T) == 1);
+ }
+ }
+ for (0..MAX_PANES) |i| try testing.expectEqual(i, Pane.Id.at(i).index());
+ for (0..max) |k| try testing.expectEqual(k, View.Id.at(k).index());
+}