summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/9p_io.zig2
-rw-r--r--src/Dir.zig4
-rw-r--r--src/File.zig12
-rw-r--r--src/Messages.zig2
-rw-r--r--src/Presentation.zig6
-rw-r--r--src/animation.zig11
-rw-r--r--src/builtins.zig22
-rw-r--r--src/detached/client.zig2
-rw-r--r--src/detached/server.zig4
-rw-r--r--src/detached/wire.zig82
-rw-r--r--src/diff.zig4
-rw-r--r--src/draw.zig4
-rw-r--r--src/dump.zig4
-rw-r--r--src/edit_cmd.zig2
-rw-r--r--src/esp32p4.zig34
-rw-r--r--src/esp32p4/app.zig6
-rw-r--r--src/esp32p4_9p.zig2
-rw-r--r--src/fonts.zig2
-rw-r--r--src/gui/Post.zig19
-rw-r--r--src/gui/gui.zig32
-rw-r--r--src/host_io.zig20
-rw-r--r--src/linux/v9fs.zig6
-rw-r--r--src/look.zig2
-rw-r--r--src/macos.zig96
-rw-r--r--src/main.zig2
-rw-r--r--src/mini.zig10
-rw-r--r--src/mouse.zig18
-rw-r--r--src/ninep/addr.zig6
-rw-r--r--src/ninep/cols.zig54
-rw-r--r--src/ninep/ctl.zig168
-rw-r--r--src/ninep/events.zig30
-rw-r--r--src/ninep/pane.zig8
-rw-r--r--src/ninep/pty.zig5
-rw-r--r--src/ninep/screen.zig4
-rw-r--r--src/ninep/testing.zig4
-rw-r--r--src/ninep/tree.zig120
-rw-r--r--src/pager.zig4
-rw-r--r--src/pardes.zig10
-rw-r--r--src/pdf_view.zig2
-rw-r--r--src/syntax.zig82
-rw-r--r--src/terminal.zig2
-rw-r--r--src/web.zig32
42 files changed, 471 insertions, 470 deletions
diff --git a/src/9p_io.zig b/src/9p_io.zig
index 27d79b93..446c24de 100644
--- a/src/9p_io.zig
+++ b/src/9p_io.zig
@@ -1015,7 +1015,7 @@ pub fn sweepDeadSockets(io: std.Io, dir: [:0]const u8) void {
i += 1 + name.len;
const pid = deadSocketPid(name).?;
if (pid == libc.getpid()) continue;
- if (std.posix.errno(std.c.kill(pid, @enumFromInt(0))) != .SRCH) continue;
+ if (std.posix.errno(std.c.kill(pid, @fromBackingInt(@intCast(0)))) != .SRCH) continue;
var path_buf: [sun_path_len:0]u8 = undefined;
const path = std.fmt.bufPrintSentinel(&path_buf, "{s}/{s}", .{ dir, name }, 0) catch continue;
const facts = statNoFollow(path) orelse continue;
diff --git a/src/Dir.zig b/src/Dir.zig
index 36895bda..b994bc06 100644
--- a/src/Dir.zig
+++ b/src/Dir.zig
@@ -463,10 +463,10 @@ test "over 9P a directory pane is a text pane whose name ends in /, its body the
defer s.p.deinit();
const p = s.p;
var line_buf: [4200]u8 = undefined;
- _ = th.wr(p, @intFromEnum(tree.TopFile.look), try std.fmt.bufPrint(&line_buf, "{s}\n", .{s.dir}));
+ _ = th.wr(p, @backingInt(tree.TopFile.look), try std.fmt.bufPrint(&line_buf, "{s}\n", .{s.dir}));
p.sync();
const pane = p.panes[p.active].?;
- const index = th.rd(p, @intFromEnum(tree.TopFile.index), 0, 8192).bytes;
+ const index = th.rd(p, @backingInt(tree.TopFile.index), 0, 8192).bytes;
try testing.expect(std.mem.indexOf(u8, index, try std.fmt.bufPrint(&line_buf, "{d} text 0 {s}/ ", .{ pane.serial, s.dir })) != null);
try testing.expectEqualStrings(".dot sub/ top.txt\n", th.rd(p, tree.Node.of(pane.serial, .body), 0, 4096).bytes);
var fields = std.mem.tokenizeScalar(u8, th.rd(p, tree.Node.of(pane.serial, .ctl), 0, 4096).bytes, ' ');
diff --git a/src/File.zig b/src/File.zig
index c42e39ec..59b04e3f 100644
--- a/src/File.zig
+++ b/src/File.zig
@@ -251,7 +251,7 @@ pub fn dumpPane(
fn dumpLocationRows(arena: std.mem.Allocator, rows: []const locations.Row) ![]const dump.LocationRow {
const saved = try arena.alloc(dump.LocationRow, rows.len);
for (rows, saved) |row, *out| out.* = .{
- .kind = @enumFromInt(@intFromEnum(row.kind)),
+ .kind = @fromBackingInt(@intCast(@backingInt(row.kind))),
.declaration = row.declaration,
.mark_occurrence = row.mark_occurrence,
.source_column = row.source_column,
@@ -336,10 +336,10 @@ fn restoreOutputLocationRows(gpa: std.mem.Allocator, content: []const u8, saved:
const colors = try dump.decodeBytes(gpa, row.colors_b64);
errdefer gpa.free(colors);
if (colors.len != 0 and colors.len != code_len) return error.InvalidLocationRows;
- for (colors) |color| if (color > @intFromEnum(syntax.Syn.comment)) return error.InvalidLocationRows;
+ for (colors) |color| if (color > @backingInt(syntax.Syn.comment)) return error.InvalidLocationRows;
const path = try gpa.dupe(u8, row.path);
out.* = .{
- .kind = @enumFromInt(@intFromEnum(row.kind)),
+ .kind = @fromBackingInt(@intCast(@backingInt(row.kind))),
.declaration = row.declaration,
.mark_occurrence = row.mark_occurrence,
.source_column = row.source_column,
@@ -1028,7 +1028,7 @@ pub fn restore(p: *Pardes, id: usize, src: dump.Pane) !*Pane {
const colors = try dump.decodeBytes(p.gpa, saved.mini_colors_b64);
errdefer p.gpa.free(colors);
if (colors.len != content.len or colors.len > Mini.max_output_bytes) return error.InvalidMini;
- for (colors) |color| if (color > @intFromEnum(syntax.Syn.comment)) return error.InvalidMini;
+ for (colors) |color| if (color > @backingInt(syntax.Syn.comment)) return error.InvalidMini;
mini = .{ .source = source, .colors = colors };
} else if (saved.mini_colors_b64.len > 0) return error.InvalidMini;
@@ -1984,7 +1984,7 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes.
if (if (tint != null and hs + c == 0)
SynStyle{ .fg = tint.?.fg, .bold = true }
else
- synStyle(p, @enumFromInt(highlights[hidx] & syntax.syn_bits))) |ss|
+ synStyle(p, @fromBackingInt(@intCast(highlights[hidx] & syntax.syn_bits)))) |ss|
{
var fill: usize = 0;
while (fill < cells and prefix_width + screen_c + fill < tw) : (fill += 1) {
@@ -2189,7 +2189,7 @@ pub fn recolorDiffOutput(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, t
// green is the tint's to say now: its code takes the page's ink.
const paint: ?SynStyle = if (tint != null and prefix)
.{ .fg = tint.?.fg, .bold = true }
- else if (synStyle(p, @enumFromInt(style & syntax.syn_bits))) |ss|
+ else if (synStyle(p, @fromBackingInt(@intCast(style & syntax.syn_bits)))) |ss|
ss
else if (tint != null)
.{ .fg = ink, .bold = false }
diff --git a/src/Messages.zig b/src/Messages.zig
index b67a8402..6d064c93 100644
--- a/src/Messages.zig
+++ b/src/Messages.zig
@@ -721,7 +721,7 @@ test "with no frontend attached a message goes once it has lingered, on the cloc
// line above it with it.
p.unattended = true;
// A read served meanwhile changes nothing; the session's loop expires.
- _ = p.serveFs(.{ .tag = 1, .op = .read, .node = @intFromEnum(ctlfs.TopFile.index), .size = 64 });
+ _ = p.serveFs(.{ .tag = 1, .op = .read, .node = @backingInt(ctlfs.TopFile.index), .size = 64 });
try std.testing.expect(pane.msg_len > 0);
expireUnattended(p);
try std.testing.expectEqual(@as(u16, 0), pane.msg_len);
diff --git a/src/Presentation.zig b/src/Presentation.zig
index 5cec73e0..2a75b66d 100644
--- a/src/Presentation.zig
+++ b/src/Presentation.zig
@@ -226,7 +226,7 @@ fn stamp(p: *const Pardes, track: Track) Track {
switch (track.effect) {
.slide, .zoom, .vertical => {
const motion = animation.Motion.of(p.settings.motion);
- stamped.motion = @intFromEnum(p.settings.motion) + 1;
+ stamped.motion = @backingInt(p.settings.motion) + 1;
stamped.frame_count = @intFromFloat(@max(2, @round(@as(f32, @floatFromInt(track.effect.frames())) * motion.span)));
},
else => {},
@@ -741,7 +741,7 @@ test "a pane past its mark never takes a neighbour's click" {
// Bouncy, at its peak: pane 0 slides right to 0..40 and swings past it,
// over the neighbour at 40..80.
var presentation: Presentation = .{};
- var track: Track = .{ .serial = 7, .effect = .slide, .motion = @intFromEnum(animation.Motion.Flavour.bouncy) + 1, .frame_count = 20, .from = .{ .x = -40, .y = 0, .w = 40, .h = 20 }, .to = .{ .x = 0, .y = 0, .w = 40, .h = 20 } };
+ var track: Track = .{ .serial = 7, .effect = .slide, .motion = @backingInt(animation.Motion.Flavour.bouncy) + 1, .frame_count = 20, .from = .{ .x = -40, .y = 0, .w = 40, .h = 20 }, .to = .{ .x = 0, .y = 0, .w = 40, .h = 20 } };
var peak: u16 = 0;
var furthest: f32 = -1e9;
while (track.frame < track.frames()) : (track.frame += 1) {
@@ -807,7 +807,7 @@ test "presentation snapshots own compact body and tag rows across later edits" {
}
test "a move retargeted mid-way carries its speed into the new one" {
- const smooth = @intFromEnum(animation.Motion.Flavour.smooth) + 1;
+ const smooth = @backingInt(animation.Motion.Flavour.smooth) + 1;
const first: Track = .{ .serial = 1, .phase = .moving, .effect = .slide, .motion = smooth, .frame = 4, .frame_count = 14, .from = .{ .x = 0, .y = 1, .w = 40, .h = 20 }, .to = .{ .x = 40, .y = 1, .w = 40, .h = 20 } };
const was = first.velocity();
try std.testing.expect(was.x > 0.5);
diff --git a/src/animation.zig b/src/animation.zig
index 19f7ce0b..547b9201 100644
--- a/src/animation.zig
+++ b/src/animation.zig
@@ -897,7 +897,7 @@ test "each flavour is its own motion: off lands at once, bouncy overshoots, play
last = now;
}
try std.testing.expect(t < 1600 * ms);
- settle[@intFromEnum(flavour)] = t;
+ settle[@backingInt(flavour)] = t;
switch (flavour) {
.crisp, .smooth => try std.testing.expect(peak <= 1.0005 and low >= 0),
// Clearly past the mark, not a hint of it.
@@ -909,8 +909,8 @@ test "each flavour is its own motion: off lands at once, bouncy overshoots, play
// Smooth takes twice crisp's time and more: a character, not a tuning.
// Yet as the default a pane's arrival (a slide's 12 frames, scaled) is
// inside ยง8.1's 220 ms, and a lift is still before 300 ms.
- try std.testing.expect(settle[@intFromEnum(Motion.Flavour.smooth)] > 2 * settle[@intFromEnum(Motion.Flavour.crisp)]);
- try std.testing.expect(settle[@intFromEnum(Motion.Flavour.smooth)] <= 300 * ms);
+ try std.testing.expect(settle[@backingInt(Motion.Flavour.smooth)] > 2 * settle[@backingInt(Motion.Flavour.crisp)]);
+ try std.testing.expect(settle[@backingInt(Motion.Flavour.smooth)] <= 300 * ms);
try std.testing.expect(@round(@as(f32, 12) * Motion.of(.smooth).span) * frame_ms <= 220);
// A fixed-length move lands exactly on its mark, whatever the flavour.
for (std.enums.values(Motion.Flavour)) |flavour| try std.testing.expectEqual(@as(f32, 1), Motion.of(flavour).ease(1));
@@ -920,7 +920,7 @@ test "a flavour's stretched pane lands exactly on its box, and a click finds the
const from: Box = .{ .x = 0, .y = 2, .w = 30, .h = 10 };
const to: Box = .{ .x = 37.3, .y = 2, .w = 30, .h = 10 };
for (std.enums.values(Motion.Flavour)) |flavour| {
- var track: Track = .{ .effect = .slide, .motion = @intFromEnum(flavour) + 1, .frame_count = 20, .from = from, .to = to };
+ var track: Track = .{ .effect = .slide, .motion = @backingInt(flavour) + 1, .frame_count = 20, .from = from, .to = to };
track.frame = track.frames() - 1;
const landed = track.presented();
// Bit for bit: no stretch or float residue once it lands.
@@ -929,7 +929,7 @@ test "a flavour's stretched pane lands exactly on its box, and a click finds the
// Playful at its most stretched: the pane is drawn wider than its box,
// and the drawn place of a cell maps back to that cell (the pointer
// inverts the same box: target + (x - shown.x) / shown.w * target.w).
- var track: Track = .{ .effect = .slide, .motion = @intFromEnum(Motion.Flavour.playful) + 1, .frame_count = 20, .from = from, .to = to };
+ var track: Track = .{ .effect = .slide, .motion = @backingInt(Motion.Flavour.playful) + 1, .frame_count = 20, .from = from, .to = to };
var most: u16 = 0;
var widest: f32 = 0;
while (track.frame < track.frames()) : (track.frame += 1) {
@@ -1309,4 +1309,3 @@ test "retarget starts at the currently displayed value" {
for (0..transition_steps) |_| tween.advance();
try std.testing.expectEqual(third, tween.displayed);
}
-
diff --git a/src/builtins.zig b/src/builtins.zig
index d9cef8c9..83966228 100644
--- a/src/builtins.zig
+++ b/src/builtins.zig
@@ -199,7 +199,7 @@ pub const registry = struct {
pub fn takesArg(b: Builtin()) bool {
inline for (manualBuiltinList(), 0..) |T, i|
- if (@intFromEnum(b) == i) return @hasDecl(T, "takes_arg") and T.takes_arg;
+ if (@backingInt(b) == i) return @hasDecl(T, "takes_arg") and T.takes_arg;
// Every setting takes its value, and a switch flips when bare.
return true;
}
@@ -210,7 +210,7 @@ pub const registry = struct {
/// may be in (`Dump+2024.zon` is a name, not Dump's argument).
pub fn plusArg(b: Builtin()) bool {
inline for (manualBuiltinList(), 0..) |T, i|
- if (@intFromEnum(b) == i) return @hasDecl(T, "plus_arg") and T.plus_arg;
+ if (@backingInt(b) == i) return @hasDecl(T, "plus_arg") and T.plus_arg;
return false;
}
@@ -223,15 +223,15 @@ pub const registry = struct {
/// pane it is refused (exec.runBuiltinFrom), as Repl and Edit are.
pub fn needs(b: Builtin()) ?PaneKind {
inline for (manualBuiltinList(), 0..) |T, i|
- if (@intFromEnum(b) == i) return if (@hasDecl(T, "needs")) T.needs else null;
+ if (@backingInt(b) == i) return if (@hasDecl(T, "needs")) T.needs else null;
return null;
}
pub fn requiresArg(b: Builtin()) bool {
inline for (manualBuiltinList(), 0..) |T, i|
- if (@intFromEnum(b) == i) return @hasDecl(T, "requires_arg") and T.requires_arg;
+ if (@backingInt(b) == i) return @hasDecl(T, "requires_arg") and T.requires_arg;
inline for (comptime settingList(), manualBuiltinCount()..) |setting, i|
- if (@intFromEnum(b) == i) return switch (setting.action) {
+ if (@backingInt(b) == i) return switch (setting.action) {
// a switch flips bare, a choice steps, and DumpDir and Shell bare
// are the default
.toggle, .transition, .scene, .dump_dir, .choice, .lift, .shader_animation, .motion, .shell => false,
@@ -244,15 +244,15 @@ pub const registry = struct {
pub fn scope(b: Builtin()) Scope {
inline for (manualBuiltinList(), 0..) |T, i|
- if (@intFromEnum(b) == i) return if (@hasDecl(T, "scope")) T.scope else .pane;
+ if (@backingInt(b) == i) return if (@hasDecl(T, "scope")) T.scope else .pane;
return .session; // a setting
}
pub fn outputTraits(b: Builtin()) ?OutputTraits {
inline for (manualBuiltinList(), 0..) |T, i|
- if (@intFromEnum(b) == i) return if (@hasDecl(T, "output")) T.output else null;
+ if (@backingInt(b) == i) return if (@hasDecl(T, "output")) T.output else null;
inline for (comptime settingList(), manualBuiltinCount()..) |_, i|
- if (@intFromEnum(b) == i) return null;
+ if (@backingInt(b) == i) return null;
unreachable;
}
@@ -260,15 +260,15 @@ pub const registry = struct {
/// The ones that own that row themselves declare `quiet` and do not.
pub fn announces(b: Builtin()) bool {
inline for (manualBuiltinList(), 0..) |T, i|
- if (@intFromEnum(b) == i) return !(@hasDecl(T, "quiet") and T.quiet);
+ if (@backingInt(b) == i) return !(@hasDecl(T, "quiet") and T.quiet);
return true; // a setting builtin changes something invisible; say so
}
pub fn dispatch(b: Builtin(), c: Ctx) void {
inline for (manualBuiltinList(), 0..) |T, i|
- if (@intFromEnum(b) == i) return T.run(c);
+ if (@backingInt(b) == i) return T.run(c);
inline for (comptime settingList(), manualBuiltinCount()..) |setting, i|
- if (@intFromEnum(b) == i) return exec.applySettingBuiltin(c.p, setting, c.arg);
+ if (@backingInt(b) == i) return exec.applySettingBuiltin(c.p, setting, c.arg);
unreachable;
}
};
diff --git a/src/detached/client.zig b/src/detached/client.zig
index cf1842d9..60950208 100644
--- a/src/detached/client.zig
+++ b/src/detached/client.zig
@@ -1209,7 +1209,7 @@ test "detached session: a frontend is never asked to fork, write, or watch" {
}
const named = for (allowed) |ok| {
const want = std.meta.stringToEnum(wire.ServerTag, ok).?;
- if (@intFromEnum(want) == tag) break true;
+ if (@backingInt(want) == tag) break true;
} else false;
if (!named) {
std.debug.print("tag 0x{x:0>2} is decodable by a frontend and is not one of the nine\n", .{tag});
diff --git a/src/detached/server.zig b/src/detached/server.zig
index 79d1189a..41bc054f 100644
--- a/src/detached/server.zig
+++ b/src/detached/server.zig
@@ -1049,7 +1049,7 @@ pub const Session = struct {
}
fn apply(s: *Session, c: *Client, slot: u8, tag: u8, payload: []const u8) wire.Error!void {
- if (tag == @intFromEnum(wire.ClientTag.hello)) {
+ if (tag == @backingInt(wire.ClientTag.hello)) {
if (c.attached) return error.BadValue;
const claimed = try wire.helloVersion(payload);
if (claimed != wire.version) {
@@ -1124,7 +1124,7 @@ pub const Session = struct {
if (entry.scene == null) break true;
} else false;
const compiled = s.shaders.sync(s.gpa, s.io, s.core, if (files) s.inotify() else s.inotify_fd, &s.watches, .{ .ctx = &s.mailbox, .call = wakeForExit });
- const key = @as(u64, s.shaders.revision) << 8 | @intFromEnum(s.core.settings.shader_animation);
+ const key = @as(u64, s.shaders.revision) << 8 | @backingInt(s.core.settings.shader_animation);
var chain: wire.Post = .{ .animation = s.core.settings.shader_animation, .len = s.core.settings.post.len };
_ = s.shaders.view(&s.core.settings.post, &chain.passes);
for (&s.clients) |*c| {
diff --git a/src/detached/wire.zig b/src/detached/wire.zig
index f1b7a1b3..d57a28be 100644
--- a/src/detached/wire.zig
+++ b/src/detached/wire.zig
@@ -569,13 +569,13 @@ pub fn framed(buf: []const u8) Error!?Framed {
fn putColor(w: *Writer, c: pardes.Color) Error!void {
switch (c) {
- .default => try w.putByte(@intFromEnum(ColorTag.default)),
+ .default => try w.putByte(@backingInt(ColorTag.default)),
.index => |i| {
- try w.putByte(@intFromEnum(ColorTag.index));
+ try w.putByte(@backingInt(ColorTag.index));
try w.putByte(i);
},
.rgb => |v| {
- try w.putByte(@intFromEnum(ColorTag.rgb));
+ try w.putByte(@backingInt(ColorTag.rgb));
try w.putBytes(&v);
},
}
@@ -606,7 +606,7 @@ const Ul = @FieldType(pardes.CellStyle, "ul");
/// the `inline else`, exactly as `clientTag` keeps the machine-local reports.
fn putUl(w: *Writer, u: Ul) Error!void {
try w.putByte(switch (u) {
- inline else => |t| @intFromEnum(@field(UlTag, @tagName(t))),
+ inline else => |t| @backingInt(@field(UlTag, @tagName(t))),
});
}
@@ -618,7 +618,7 @@ fn getUl(r: *Reader) Error!Ul {
fn putFont(w: *Writer, f: pardes.FontRole) Error!void {
try w.putByte(switch (f) {
- inline else => |t| @intFromEnum(@field(FontTag, @tagName(t))),
+ inline else => |t| @backingInt(@field(FontTag, @tagName(t))),
});
}
@@ -795,12 +795,12 @@ pub fn encodeFrameLayers(out: []u8, cols: u16, rows: u16, cursor: ?Cursor, point
std.debug.assert(cells.len == @as(usize, cols) * @as(usize, rows));
const full = prev.len != cells.len;
var w: Writer = .init(out);
- const at = try beginMessage(&w, @intFromEnum(ServerTag.frame));
+ const at = try beginMessage(&w, @backingInt(ServerTag.frame));
const header: FrameHeader = if (pointer_shape == .link)
(if (full) .full_link else .diff_link)
else
(if (full) .full else .diff);
- try w.putByte(@intFromEnum(header));
+ try w.putByte(@backingInt(header));
try w.putU16(cols);
try w.putU16(rows);
try putCursor(&w, cursor, cols, rows);
@@ -837,7 +837,7 @@ pub fn encodeFrameLayers(out: []u8, cols: u16, rows: u16, cursor: ?Cursor, point
for (tags) |layer| {
if (layer.rows == 0) continue;
if (layer.cells.len != @as(usize, layer.cols) * layer.rows) return error.BadValue;
- try w.putByte(@intFromEnum(layer.kind));
+ try w.putByte(@backingInt(layer.kind));
try w.putU16(layer.id);
try w.putU32(layer.serial);
try w.putU16(layer.viewport.x);
@@ -852,7 +852,7 @@ pub fn encodeFrameLayers(out: []u8, cols: u16, rows: u16, cursor: ?Cursor, point
}
try w.putU16(@intCast(regions.len));
for (regions) |region| {
- try w.putByte(@intFromEnum(region.kind));
+ try w.putByte(@backingInt(region.kind));
try w.putByte(region.owner);
try w.putU32(region.serial);
try w.putU16(region.rect.x);
@@ -1003,7 +1003,7 @@ fn getBodyHit(r: *Reader) Error!?pardes.Mouse.BodyHit {
fn putTagHit(w: *Writer, hit: ?pardes.TagHit) Error!void {
try w.putBool(hit != null);
if (hit) |h| {
- try w.putByte(@intFromEnum(h.kind));
+ try w.putByte(@backingInt(h.kind));
try w.putU16(h.id);
try w.putU32(h.serial);
try w.putU16(h.col);
@@ -1030,7 +1030,7 @@ fn getTagHit(r: *Reader) Error!?pardes.TagHit {
pub fn encodeClient(out: []u8, msg: ClientMsg) Error![]const u8 {
var w: Writer = .init(out);
- const at = try beginMessage(&w, @intFromEnum(clientTag(msg)));
+ const at = try beginMessage(&w, @backingInt(clientTag(msg)));
switch (msg) {
.hello => |h| {
try w.putU16(h.version);
@@ -1048,10 +1048,10 @@ pub fn encodeClient(out: []u8, msg: ClientMsg) Error![]const u8 {
},
.mouse => |m| {
try w.putByte(switch (m.button) {
- inline else => |t| @intFromEnum(@field(ButtonTag, @tagName(t))),
+ inline else => |t| @backingInt(@field(ButtonTag, @tagName(t))),
});
try w.putByte(switch (m.kind) {
- inline else => |t| @intFromEnum(@field(KindTag, @tagName(t))),
+ inline else => |t| @backingInt(@field(KindTag, @tagName(t))),
});
try w.putU16(m.col);
try w.putU16(m.row);
@@ -1164,7 +1164,7 @@ fn serverTag(msg: ServerMsg) ServerTag {
/// payload is a walk of two grids rather than a value (see `encodeFrame`).
pub fn encodeServer(out: []u8, msg: ServerMsg) Error![]const u8 {
var w: Writer = .init(out);
- const at = try beginMessage(&w, @intFromEnum(serverTag(msg)));
+ const at = try beginMessage(&w, @backingInt(serverTag(msg)));
switch (msg) {
.welcome => |v| {
try w.putU16(v.version);
@@ -1172,7 +1172,7 @@ pub fn encodeServer(out: []u8, msg: ServerMsg) Error![]const u8 {
try w.putU16(v.cols);
try w.putU16(v.rows);
},
- .refuse => |why| try w.putByte(@intFromEnum(why)),
+ .refuse => |why| try w.putByte(@backingInt(why)),
// A frame's runs are not a value this union can hold; the server calls
// encodeFrame directly and this arm exists so the switch stays
// exhaustive over ServerMsg.
@@ -1182,11 +1182,11 @@ pub fn encodeServer(out: []u8, msg: ServerMsg) Error![]const u8 {
.read_clipboard => {},
.open_link => |u| try w.putSlice16(u),
.post => |p| {
- try w.putByte(@intFromEnum(p.animation));
+ try w.putByte(@backingInt(p.animation));
try w.putByte(p.len);
for (p.list()) |pass| {
// 0 a file, else a bundled scene and one.
- try w.putByte(if (pass.scene) |scene| @as(u8, @intFromEnum(scene)) + 1 else 0);
+ try w.putByte(if (pass.scene) |scene| @as(u8, @backingInt(scene)) + 1 else 0);
try w.putByte(pass.level);
try w.putByte(@intFromBool(pass.animated));
try w.putU32(pass.revision);
@@ -1341,9 +1341,9 @@ test "detached wire: every Event variant round-trips" {
// The tag space is the protocol's own, so assert the numbers themselves:
// a renumbering here breaks every deployed frontend and must be a diff
// somebody reads, not a silent change.
- try testing.expectEqual(@as(u8, 0x01), @intFromEnum(ClientTag.hello));
- try testing.expectEqual(@as(u8, 0x10), @intFromEnum(ClientTag.key));
- try testing.expectEqual(@as(u8, 0x1d), @intFromEnum(ClientTag.pointer_leave));
+ try testing.expectEqual(@as(u8, 0x01), @backingInt(ClientTag.hello));
+ try testing.expectEqual(@as(u8, 0x10), @backingInt(ClientTag.key));
+ try testing.expectEqual(@as(u8, 0x1d), @backingInt(ClientTag.pointer_leave));
{
const got = try roundClient(&buf, .{ .hello = .{ .cols = 80, .rows = 24 } });
@@ -1506,7 +1506,7 @@ test "detached wire: a session is never told to do a frontend's remembering" {
}
const named = for (allowed) |ok| {
const want = std.meta.stringToEnum(ClientTag, ok).?;
- if (@intFromEnum(want) == tag) break true;
+ if (@backingInt(want) == tag) break true;
} else false;
if (!named) {
std.debug.print("tag 0x{x:0>2} is decodable by a session and is not something a human did\n", .{tag});
@@ -1752,8 +1752,8 @@ test "detached wire: a truncated frame is refused at every length" {
for (0..header_len + 1) |cut|
try testing.expectEqual(@as(?Framed, null), try framed(copy[0..cut]));
// A payload with bytes LEFT OVER is refused too: it is not this message.
- try testing.expectError(error.Trailing, decodeClient(@intFromEnum(ClientTag.pointer_leave), "x"));
- try testing.expectError(error.Trailing, decodeServer(@intFromEnum(ServerTag.quit), "x"));
+ try testing.expectError(error.Trailing, decodeClient(@backingInt(ClientTag.pointer_leave), "x"));
+ try testing.expectError(error.Trailing, decodeServer(@backingInt(ServerTag.quit), "x"));
}
test "detached wire: an unknown tag is refused, never guessed" {
@@ -1765,9 +1765,9 @@ test "detached wire: an unknown tag is refused, never guessed" {
}
// A tag NESTED in a payload gets the same treatment: a color, an
// underline style, a mouse button, a refusal reason.
- try testing.expectError(error.BadTag, decodeServer(@intFromEnum(ServerTag.refuse), &.{0x7f}));
+ try testing.expectError(error.BadTag, decodeServer(@backingInt(ServerTag.refuse), &.{0x7f}));
try testing.expectError(error.BadTag, decodeClient(
- @intFromEnum(ClientTag.mouse),
+ @backingInt(ClientTag.mouse),
&.{ 0xff, 0x00, 0, 0, 0, 0, 0 },
));
}
@@ -1775,7 +1775,7 @@ test "detached wire: an unknown tag is refused, never guessed" {
test "detached wire: an over-long length prefix is refused before it is believed" {
// The prefix a hostile or corrupt peer sends to make the receiver allocate
// or index by it. `framed` must refuse rather than wait for 4 GiB.
- var head: [header_len]u8 = .{ @intFromEnum(ClientTag.paste), 0, 0, 0, 0 };
+ var head: [header_len]u8 = .{ @backingInt(ClientTag.paste), 0, 0, 0, 0 };
std.mem.writeInt(u32, head[1..5], max_payload + 1, .little);
try testing.expectError(error.Overlong, framed(&head));
std.mem.writeInt(u32, head[1..5], std.math.maxInt(u32), .little);
@@ -1789,10 +1789,10 @@ test "detached wire: an over-long length prefix is refused before it is believed
var paste: [8]u8 = undefined;
std.mem.writeInt(u32, paste[0..4], 4096, .little);
@memcpy(paste[4..8], "abcd");
- try testing.expectError(error.Truncated, decodeClient(@intFromEnum(ClientTag.paste), &paste));
+ try testing.expectError(error.Truncated, decodeClient(@backingInt(ClientTag.paste), &paste));
// ...and past the cap, which is refused rather than read.
std.mem.writeInt(u32, paste[0..4], max_payload + 1, .little);
- try testing.expectError(error.Overlong, decodeClient(@intFromEnum(ClientTag.paste), &paste));
+ try testing.expectError(error.Overlong, decodeClient(@backingInt(ClientTag.paste), &paste));
}
test "detached wire: a frame that lies about its runs cannot walk out of the grid" {
@@ -1837,13 +1837,13 @@ test "detached wire: a frame that lies about its runs cannot walk out of the gri
// it is used to bound the walk.
var head: [frame_head]u8 = undefined;
var w: Writer = .init(&head);
- try w.putByte(@intFromEnum(FrameKind.diff));
+ try w.putByte(@backingInt(FrameKind.diff));
try w.putU16(cols);
try w.putU16(rows);
try putCursor(&w, null, cols, rows);
try w.putU32(0); // no body layers
try w.putU32(9);
- try testing.expectError(error.Overlong, decodeServer(@intFromEnum(ServerTag.frame), w.written()));
+ try testing.expectError(error.Overlong, decodeServer(@backingInt(ServerTag.frame), w.written()));
// ...and a grid of the wrong size is the receiver's own bug, not a frame
// it should paint half of.
@@ -1885,7 +1885,7 @@ test "detached wire: a cursor outside the grid is refused, not painted" {
var head: [frame_head]u8 = undefined;
for ([_][2]u16{ .{ cols, 0 }, .{ 0, rows }, .{ 0xffff, 0xffff } }) |xy| {
var w: Writer = .init(&head);
- try w.putByte(@intFromEnum(FrameKind.diff));
+ try w.putByte(@backingInt(FrameKind.diff));
try w.putU16(cols);
try w.putU16(rows);
// Written by hand: `putCursor` now refuses this too, which is the
@@ -1897,19 +1897,19 @@ test "detached wire: a cursor outside the grid is refused, not painted" {
try w.putU32(0);
try testing.expectError(
error.BadValue,
- decodeServer(@intFromEnum(ServerTag.frame), w.written()),
+ decodeServer(@backingInt(ServerTag.frame), w.written()),
);
}
// The last cell IS in the grid, and a frame carrying it decodes.
{
var w: Writer = .init(&head);
- try w.putByte(@intFromEnum(FrameKind.diff));
+ try w.putByte(@backingInt(FrameKind.diff));
try w.putU16(cols);
try w.putU16(rows);
try putCursor(&w, .{ .x = cols - 1, .y = rows - 1, .bar = true }, cols, rows);
try w.putU32(0); // no body layers
try w.putU32(0);
- const got = (try decodeServer(@intFromEnum(ServerTag.frame), w.written())).frame;
+ const got = (try decodeServer(@backingInt(ServerTag.frame), w.written())).frame;
try testing.expectEqual(@as(u16, cols - 1), got.cursor.?.x);
try testing.expectEqual(@as(u16, rows - 1), got.cursor.?.y);
}
@@ -1933,25 +1933,25 @@ test "detached wire: values a field cannot mean are refused" {
// A bool is 0 or 1. `2` used to be "true" in every hand-written codec that
// ever silently accepted a corrupt stream.
try testing.expectError(error.BadValue, decodeClient(
- @intFromEnum(ClientTag.key),
+ @backingInt(ClientTag.key),
&.{ 'a', 0, 0, 0, 0, 0, 2, 0, 0 },
));
// A codepoint past Unicode's last: @intCast into Key.cp's u21 would panic.
try testing.expectError(error.BadValue, decodeClient(
- @intFromEnum(ClientTag.key),
+ @backingInt(ClientTag.key),
&.{ 0x00, 0x00, 0x11, 0x00, 0, 0, 0, 0, 0 },
));
// A pane the core cannot index. `pdf_scroll` reads its pane byte before the
// f32 that follows, so a one-byte payload reaches the check this is about
// rather than tripping `Truncated` first.
try testing.expectError(error.BadValue, decodeClient(
- @intFromEnum(ClientTag.pdf_scroll),
+ @backingInt(ClientTag.pdf_scroll),
&.{pardes.MAX_PANES},
));
// A zero-column grid would collapse a shared session; an over-wide one is
// past what this protocol carries.
try testing.expectError(error.BadValue, decodeClient(
- @intFromEnum(ClientTag.hello),
+ @backingInt(ClientTag.hello),
&.{ 1, 0, 0, 0, 24, 0 },
));
{
@@ -1959,15 +1959,15 @@ test "detached wire: values a field cannot mean are refused" {
std.mem.writeInt(u16, hello[0..2], version, .little);
std.mem.writeInt(u16, hello[2..4], max_cols + 1, .little);
std.mem.writeInt(u16, hello[4..6], 24, .little);
- try testing.expectError(error.BadValue, decodeClient(@intFromEnum(ClientTag.hello), &hello));
+ try testing.expectError(error.BadValue, decodeClient(@backingInt(ClientTag.hello), &hello));
}
// A NaN scroll distance. `pinch` multiplies into a zoom the pane keeps.
{
var pinch: [4]u8 = undefined;
std.mem.writeInt(u32, &pinch, @bitCast(std.math.nan(f32)), .little);
- try testing.expectError(error.BadValue, decodeClient(@intFromEnum(ClientTag.pinch), &pinch));
+ try testing.expectError(error.BadValue, decodeClient(@backingInt(ClientTag.pinch), &pinch));
std.mem.writeInt(u32, &pinch, @bitCast(std.math.inf(f32)), .little);
- try testing.expectError(error.BadValue, decodeClient(@intFromEnum(ClientTag.touch_scroll), &pinch));
+ try testing.expectError(error.BadValue, decodeClient(@backingInt(ClientTag.touch_scroll), &pinch));
}
// A cell with the reserved attribute bit set, and one with an impossible
// grapheme length. Both are bytes this protocol has no meaning for.
diff --git a/src/diff.zig b/src/diff.zig
index 362695d5..842a6b41 100644
--- a/src/diff.zig
+++ b/src/diff.zig
@@ -163,8 +163,8 @@ pub const Walk = struct {
};
const meta_words = [_][]const u8{
- "index ", "new file mode ", "deleted file mode ", "old mode ", "new mode ",
- "similarity index ", "rename from ", "rename to ", "copy from ", "copy to ",
+ "index ", "new file mode ", "deleted file mode ", "old mode ", "new mode ",
+ "similarity index ", "rename from ", "rename to ", "copy from ", "copy to ",
"Binary files ", "dissimilarity ",
};
diff --git a/src/draw.zig b/src/draw.zig
index e6420ed4..22a8dc2a 100644
--- a/src/draw.zig
+++ b/src/draw.zig
@@ -564,7 +564,7 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
.accent = chrome.box,
.sel_fg = p.theme().sel_fg,
.sel_bg = p.theme().sel_bg,
- .lift_style = @intFromEnum(liftStyle(p)),
+ .lift_style = @backingInt(liftStyle(p)),
.rule_px = p.theme().rule_px orelse 2,
.grip_border = boxBorder(p),
.grip_focus_ring = chrome.box,
@@ -1167,7 +1167,7 @@ fn renderHeaderLayer(p: *Pardes, arena: std.mem.Allocator, layer: *pardes.Layer,
const start = modal.lineStartOffset(text, index + top);
const end = start + shown.len;
if (mine and swept.lo < swept.hi and swept.hi > start and swept.lo < end) {
- const button = @intFromEnum(sweep.button);
+ const button = @backingInt(sweep.button);
var col = panes.File.rawDisplayCol(shown, @max(swept.lo, start) - start) -| scroll;
const stop = panes.File.rawDisplayCol(shown, @min(swept.hi, end) - start) -| scroll;
while (col < stop and col < columns) : (col += 1) {
diff --git a/src/dump.zig b/src/dump.zig
index 545d09ec..76a6de85 100644
--- a/src/dump.zig
+++ b/src/dump.zig
@@ -1100,7 +1100,7 @@ test "a restored session's column and workspace tags take more than one selectio
try std.testing.expect(restored.col_tags[0].reserveSels());
try std.testing.expect(restored.global_tag.reserveSels());
try std.testing.expect(restored.fs.started != 0);
- const stat = th.call(restored, .{ .tag = 1, .op = .getattr, .node = @intFromEnum(pardes.ctlfs.TopFile.index) });
+ const stat = th.call(restored, .{ .tag = 1, .op = .getattr, .node = @backingInt(pardes.ctlfs.TopFile.index) });
try std.testing.expect(stat.reply.attr.mtime != 0);
}
@@ -1146,7 +1146,7 @@ test "a pane restored with unsaved text is asked about by Exit, Restore, Del and
const node = if (std.mem.eql(u8, word, "Del") or std.mem.eql(u8, word, "get"))
ctlfs.Node.of(restored.panes[id].?.serial, .ctl)
else
- @intFromEnum(ctlfs.TopFile.ctl);
+ @backingInt(ctlfs.TopFile.ctl);
const line = if (std.mem.eql(u8, word, "Restore")) try std.fmt.bufPrint(&restore_line, "Restore {s}/d.zon\n", .{dir}) else if (std.mem.eql(u8, word, "Exit")) "Exit\n" else if (std.mem.eql(u8, word, "Del")) "Del\n" else "get\n";
const answer = th.wr(restored, node, line);
try std.testing.expectEqual(ctlfs.Status.err, answer.reply.status);
diff --git a/src/edit_cmd.zig b/src/edit_cmd.zig
index d3377e09..447ea66b 100644
--- a/src/edit_cmd.zig
+++ b/src/edit_cmd.zig
@@ -495,7 +495,7 @@ test "Edit , | sort runs off the loop, through the session's shell in the file's
try testing.expectEqualStrings(@import("ninep/ctl.zig").e_after_edit, after.reply.ename);
try testing.expect(p.pipe.edit_run == null and !th.logHas(p, "before"));
}
- try testing.expectEqual(tree.E.INVAL, th.wr(p, @intFromEnum(tree.TopFile.exec), "Msg before\nEdit , | sort\n").errno());
+ try testing.expectEqual(tree.E.INVAL, th.wr(p, @backingInt(tree.TopFile.exec), "Msg before\nEdit , | sort\n").errno());
}
test "the held write asked again is parked again, then answered once, and a flush stops the Edit" {
diff --git a/src/esp32p4.zig b/src/esp32p4.zig
index ed18efd9..683d19e1 100644
--- a/src/esp32p4.zig
+++ b/src/esp32p4.zig
@@ -134,19 +134,19 @@ pub const GpioFn = *const fn (ctx: ?*anyopaque, pin: u16, was: *u8, now: *u8) ca
var host_alloc: Allocator = undefined;
fn hostAlloc(_: *anyopaque, len: usize, alignment: std.mem.Alignment, _: usize) ?[*]u8 {
- return host_alloc.alloc(host_alloc.ctx, len, @intFromEnum(alignment));
+ return host_alloc.alloc(host_alloc.ctx, len, @backingInt(alignment));
}
fn hostResize(_: *anyopaque, mem: []u8, alignment: std.mem.Alignment, new_len: usize, _: usize) bool {
- return host_alloc.resize(host_alloc.ctx, mem.ptr, mem.len, @intFromEnum(alignment), new_len);
+ return host_alloc.resize(host_alloc.ctx, mem.ptr, mem.len, @backingInt(alignment), new_len);
}
fn hostRemap(_: *anyopaque, mem: []u8, alignment: std.mem.Alignment, new_len: usize, _: usize) ?[*]u8 {
- return if (host_alloc.resize(host_alloc.ctx, mem.ptr, mem.len, @intFromEnum(alignment), new_len)) mem.ptr else null;
+ return if (host_alloc.resize(host_alloc.ctx, mem.ptr, mem.len, @backingInt(alignment), new_len)) mem.ptr else null;
}
fn hostFree(_: *anyopaque, mem: []u8, alignment: std.mem.Alignment, _: usize) void {
- host_alloc.free(host_alloc.ctx, mem.ptr, mem.len, @intFromEnum(alignment));
+ host_alloc.free(host_alloc.ctx, mem.ptr, mem.len, @backingInt(alignment));
}
const host_vtable: std.mem.Allocator.VTable = .{
@@ -447,19 +447,21 @@ fn apply(c: *pardes.Pardes, ev: vaxis.Event) void {
else => null,
};
if (button) |b| {
- c.update(.{ .mouse = .{
- .button = b,
- .kind = switch (m.type) {
- .press => .press,
- .release => .release,
- .motion => .motion,
- .drag => .drag,
+ c.update(.{
+ .mouse = .{
+ .button = b,
+ .kind = switch (m.type) {
+ .press => .press,
+ .release => .release,
+ .motion => .motion,
+ .drag => .drag,
+ },
+ // Before the first cell (a drag past the edge): the edge.
+ .col = @intCast(@max(0, m.col)),
+ .row = @intCast(@max(0, m.row)),
+ .ctrl = m.mods.ctrl,
},
- // Before the first cell (a drag past the edge): the edge.
- .col = @intCast(@max(0, m.col)),
- .row = @intCast(@max(0, m.row)),
- .ctrl = m.mods.ctrl,
- } });
+ });
dirty = true;
}
},
diff --git a/src/esp32p4/app.zig b/src/esp32p4/app.zig
index 4ee131ec..800e7597 100644
--- a/src/esp32p4/app.zig
+++ b/src/esp32p4/app.zig
@@ -235,17 +235,17 @@ var gpa_heap: heapmod.Heap = undefined;
fn cAlloc(_: ?*anyopaque, len: usize, log2_align: u8) callconv(.c) ?[*]u8 {
const a = gpa_heap.allocator();
- return a.vtable.alloc(a.ptr, len, @enumFromInt(log2_align), @returnAddress());
+ return a.vtable.alloc(a.ptr, len, @fromBackingInt(@intCast(log2_align)), @returnAddress());
}
fn cResize(_: ?*anyopaque, ptr: [*]u8, len: usize, log2_align: u8, new_len: usize) callconv(.c) bool {
const a = gpa_heap.allocator();
- return a.vtable.resize(a.ptr, ptr[0..len], @enumFromInt(log2_align), new_len, @returnAddress());
+ return a.vtable.resize(a.ptr, ptr[0..len], @fromBackingInt(@intCast(log2_align)), new_len, @returnAddress());
}
fn cFree(_: ?*anyopaque, ptr: [*]u8, len: usize, log2_align: u8) callconv(.c) void {
const a = gpa_heap.allocator();
- a.vtable.free(a.ptr, ptr[0..len], @enumFromInt(log2_align), @returnAddress());
+ a.vtable.free(a.ptr, ptr[0..len], @fromBackingInt(@intCast(log2_align)), @returnAddress());
}
const editor_allocator: Allocator = .{
diff --git a/src/esp32p4_9p.zig b/src/esp32p4_9p.zig
index cd59b9df..5fcab85b 100644
--- a/src/esp32p4_9p.zig
+++ b/src/esp32p4_9p.zig
@@ -103,7 +103,7 @@ fn die(msg: []const u8) noreturn {
.{ .rerror = .{ .ename = msg[0..@min(msg.len, ninep.errmax)] } },
ninep.notag,
&buf,
- // unreachable: the message is cut to errmax and buf is sized to it
+ // unreachable: the message is cut to errmax and buf is sized to it
) catch unreachable;
uart.write(bytes);
while (true) {}
diff --git a/src/fonts.zig b/src/fonts.zig
index 098bf36f..88cde63a 100644
--- a/src/fonts.zig
+++ b/src/fonts.zig
@@ -324,7 +324,7 @@ fn sfntBase(head: []const u8) ?usize {
fn scratchFont(buf: *[64:0]u8, ext: []const u8) [:0]const u8 {
return std.fmt.bufPrintSentinel(buf, "/tmp/pardes-fonts-test-{d}{s}", .{
@as(u32, @intCast(libc.getpid())), ext,
- // unreachable: 23 bytes, a u32 pid (10) and a short extension fit 64
+ // unreachable: 23 bytes, a u32 pid (10) and a short extension fit 64
}, 0) catch unreachable;
}
diff --git a/src/gui/Post.zig b/src/gui/Post.zig
index 8d0e14d9..17e8d7e9 100644
--- a/src/gui/Post.zig
+++ b/src/gui/Post.zig
@@ -623,15 +623,15 @@ test "the uniform block is ghostty's, offset for offset, and the prefix names it
try std.testing.expectEqual(@offsetOf(GhosttyUniforms, "selection_background_color"), @offsetOf(Uniforms, "selection_foreground_color"));
// The prefix's block, member by member, in ghostty's GLSL names and types.
const glsl = [_]struct { []const u8, []const u8 }{
- .{ "vec3", "iResolution" }, .{ "float", "iTime" }, .{ "float", "iTimeDelta" },
- .{ "float", "iFrameRate" }, .{ "int", "iFrame" }, .{ "float", "iChannelTime[4]" },
- .{ "vec3", "iChannelResolution[4]" }, .{ "vec4", "iMouse" }, .{ "vec4", "iDate" },
- .{ "float", "iSampleRate" }, .{ "vec4", "iCurrentCursor" }, .{ "vec4", "iPreviousCursor" },
- .{ "vec4", "iCurrentCursorColor" }, .{ "vec4", "iPreviousCursorColor" }, .{ "int", "iCurrentCursorStyle" },
- .{ "int", "iPreviousCursorStyle" }, .{ "int", "iCursorVisible" }, .{ "float", "iTimeCursorChange" },
- .{ "float", "iTimeFocus" }, .{ "int", "iFocus" }, .{ "vec3", "iPalette[256]" },
- .{ "vec3", "iBackgroundColor" }, .{ "vec3", "iForegroundColor" }, .{ "vec3", "iCursorColor" },
- .{ "vec3", "iCursorText" }, .{ "vec3", "iSelectionForegroundColor" }, .{ "vec3", "iSelectionBackgroundColor" },
+ .{ "vec3", "iResolution" }, .{ "float", "iTime" }, .{ "float", "iTimeDelta" },
+ .{ "float", "iFrameRate" }, .{ "int", "iFrame" }, .{ "float", "iChannelTime[4]" },
+ .{ "vec3", "iChannelResolution[4]" }, .{ "vec4", "iMouse" }, .{ "vec4", "iDate" },
+ .{ "float", "iSampleRate" }, .{ "vec4", "iCurrentCursor" }, .{ "vec4", "iPreviousCursor" },
+ .{ "vec4", "iCurrentCursorColor" }, .{ "vec4", "iPreviousCursorColor" }, .{ "int", "iCurrentCursorStyle" },
+ .{ "int", "iPreviousCursorStyle" }, .{ "int", "iCursorVisible" }, .{ "float", "iTimeCursorChange" },
+ .{ "float", "iTimeFocus" }, .{ "int", "iFocus" }, .{ "vec3", "iPalette[256]" },
+ .{ "vec3", "iBackgroundColor" }, .{ "vec3", "iForegroundColor" }, .{ "vec3", "iCursorColor" },
+ .{ "vec3", "iCursorText" }, .{ "vec3", "iSelectionForegroundColor" }, .{ "vec3", "iSelectionBackgroundColor" },
};
try std.testing.expectEqual(ours.field_names.len, glsl.len);
// Its three blocks (Globals, Palette, Colors) read as one, in order.
@@ -673,7 +673,6 @@ test "a moved cursor becomes the previous one, stamped with the time of the move
try std.testing.expectEqual([4]f32{ 1.0 / 255.0, 2.0 / 255.0, 3.0 / 255.0, 1 }, post.uniforms.selection_foreground_color);
}
-
test "a still pass asks for no idle frames; one that reads the clock does" {
var post: Post = .{};
const fake: *Pipeline = @ptrFromInt(0x1000);
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index b8687fd3..f0dd0682 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -1888,7 +1888,6 @@ const Gui = struct {
sel_glow: SelGlow = .{},
hover_glow: SelGlow = .{},
/// G14: the cells last drawn and when each last changed.
-
/// The cursor's blink (blinkNow): when the frame drawn last arrived,
/// a redraw owed for an edge, and this frame's cursor mode and alpha.
frame_arrival_ns: u64 = 0,
@@ -2291,7 +2290,7 @@ fn setTransitionFields(
instance.present_y0 = presented[1];
instance.present_x1 = presented[2];
instance.present_y1 = presented[3];
- instance.effect = @intFromEnum(active.effect);
+ instance.effect = @backingInt(active.effect);
instance.progress_bits = @bitCast(active.amount());
instance.serial = active.serial;
instance.cell_coord = cell_coord;
@@ -3356,8 +3355,8 @@ fn setStdinRaw() !void {
term.lflag.ICANON = false;
term.lflag.IEXTEN = false;
term.lflag.ISIG = false;
- term.cc[@intFromEnum(posix.V.MIN)] = 1;
- term.cc[@intFromEnum(posix.V.TIME)] = 0;
+ term.cc[@backingInt(posix.V.MIN)] = 1;
+ term.cc[@backingInt(posix.V.TIME)] = 0;
try posix.tcsetattr(0, .NOW, term);
}
@@ -5484,7 +5483,6 @@ test "a notch scrolls the core at once and the picture glides after it, a wrappe
try std.testing.expect(!g.glide.pending and !g.glide.moving());
}
-
fn resetScroll(g: *Gui) void {
g.scroll_pane = null;
g.scroll_delta = 0;
@@ -5519,13 +5517,15 @@ fn stepScroll(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void {
const down = left > 0;
left += if (down) -1 else 1;
const was = pane.scroll();
- core.update(.{ .mouse = .{
- .button = if (down) .wheel_down else .wheel_up,
- .kind = .press,
- .col = g.scroll_col,
- .row = g.scroll_row,
- .shift = true, // pardes's own scroll, never a program's wheel
- } });
+ core.update(.{
+ .mouse = .{
+ .button = if (down) .wheel_down else .wheel_up,
+ .kind = .press,
+ .col = g.scroll_col,
+ .row = g.scroll_row,
+ .shift = true, // pardes's own scroll, never a program's wheel
+ },
+ });
if (pane.scroll() == was) {
resetScroll(g);
return;
@@ -7251,7 +7251,7 @@ test "a rising pane past its mark stays inside its box" {
var g: Gui = undefined;
g.cell_w = 10;
g.cell_h = 20;
- var track: pardes.animation.Track = .{ .serial = 3, .phase = .opening, .effect = .vertical, .motion = @intFromEnum(pardes.animation.Motion.Flavour.bouncy) + 1, .frame_count = 20, .from = .{ .x = 0, .y = 10, .w = 40, .h = 10 }, .to = .{ .x = 0, .y = 0, .w = 40, .h = 10 } };
+ var track: pardes.animation.Track = .{ .serial = 3, .phase = .opening, .effect = .vertical, .motion = @backingInt(pardes.animation.Motion.Flavour.bouncy) + 1, .frame_count = 20, .from = .{ .x = 0, .y = 10, .w = 40, .h = 10 }, .to = .{ .x = 0, .y = 0, .w = 40, .h = 10 } };
var peak: u16 = 0;
var highest: f32 = 1e9;
while (track.frame < track.frames()) : (track.frame += 1) {
@@ -8788,7 +8788,6 @@ fn addPattern(g: *Gui, gpa: std.mem.Allocator, x0: f32, y0: f32, x1: f32, y1: f3
instance.effect |= checker_bit;
}
-
/// How a lift of 0 to 1 stands off the page: the shadow's blur and offset
/// in cell heights, and its darkest, where it leaves the caster's edge.
/// Within ยง8.2's budget: sigma 0.4-0.8 cell, at most 30% darker at the edge.
@@ -8926,7 +8925,6 @@ fn clipToBodies(g: *Gui, gpa: std.mem.Allocator, first: usize, bodies: []const [
};
}
-
/// Like shadowCeiling for a light colour laid over at `a` (sRGB blend, as
/// the decor pipeline blends a colour that is not black): the largest `a`
/// that keeps text and page apart by min(their contrast, 4.5).
@@ -10099,7 +10097,7 @@ test "decor is read from the regions, each pane's in its own group" {
try std.testing.expect(tracked.decor_count >= 4);
try std.testing.expectEqual(still, groups.items[0].decor_count + tracked.decor_count);
for (g.decor.items[tracked.decor_start..][0..tracked.decor_count]) |item|
- try std.testing.expectEqual(@as(u32, @intFromEnum(pardes.animation.Transition.slide)), item.effect);
+ try std.testing.expectEqual(@as(u32, @backingInt(pardes.animation.Transition.slide)), item.effect);
// Cursors stand still while panes move.
try std.testing.expectEqual(@as(u32, 0), groups.items[groups.ink].decor_count);
}
@@ -10468,7 +10466,7 @@ fn appendCursorGlide(g: *Gui, surface: *const pardes.Surface, builder: *OverlayB
fn appendWorkspacePet(g: *Gui, core: ?*const pardes.Pardes, surface: *const pardes.Surface, builder: *OverlayBuilder) void {
const p = core orelse return;
- const kind: pet.Kind = @enumFromInt(@intFromEnum(p.settings.pet));
+ const kind: pet.Kind = @fromBackingInt(@intCast(@backingInt(p.settings.pet)));
if (kind == .off or surface.rows == 0 or surface.cols == 0) {
g.pet_state = .{};
return;
diff --git a/src/host_io.zig b/src/host_io.zig
index d789a77d..bef88172 100644
--- a/src/host_io.zig
+++ b/src/host_io.zig
@@ -572,7 +572,7 @@ pub const Shell = struct {
const name = std.mem.sliceTo(@as([*:0]const u8, @ptrCast(&ent.name)), 0);
const pid = rcPid(name) orelse continue;
if (pid == std.c.getpid()) continue;
- if (std.posix.errno(std.c.kill(pid, @enumFromInt(0))) != .SRCH) continue;
+ if (std.posix.errno(std.c.kill(pid, @fromBackingInt(@intCast(0)))) != .SRCH) continue;
if (name.len >= 64 or n == dead.len) continue;
@memcpy(dead[n][0..name.len], name);
dead_len[n] = name.len;
@@ -1236,8 +1236,8 @@ pub fn resetChildSignals() void {
const default: posix.Sigaction = .{ .handler = .{ .handler = posix.SIG.DFL }, .mask = posix.sigemptyset(), .flags = 0 };
var sig: u8 = 1;
while (sig < 65) : (sig += 1) {
- if (sig == @intFromEnum(posix.SIG.KILL) or sig == @intFromEnum(posix.SIG.STOP)) continue;
- _ = std.c.sigaction(@enumFromInt(sig), &default, null);
+ if (sig == @backingInt(posix.SIG.KILL) or sig == @backingInt(posix.SIG.STOP)) continue;
+ _ = std.c.sigaction(@fromBackingInt(@intCast(sig)), &default, null);
}
const none = posix.sigemptyset();
posix.sigprocmask(posix.SIG.SETMASK, &none, null);
@@ -1620,13 +1620,13 @@ pub fn forkShell(
if (pid == 0) {
resetChildSignals();
if (cwd_z) |path| if (chdir(path.ptr) != 0) {
- const why = [_]u8{ 'c', @truncate(@intFromEnum(libc.errno(@as(c_int, -1)))) };
+ const why = [_]u8{ 'c', @truncate(@backingInt(libc.errno(@as(c_int, -1)))) };
_ = libc.write(told[1], &why, why.len);
_exit(126);
};
if (envp) |env| _ = execve(spawn.path, &spawn.argv, env);
_ = execv(spawn.path, &spawn.argv);
- const why = [_]u8{ 'x', @truncate(@intFromEnum(libc.errno(@as(c_int, -1)))) };
+ const why = [_]u8{ 'x', @truncate(@backingInt(libc.errno(@as(c_int, -1)))) };
_ = libc.write(told[1], &why, why.len);
_exit(127);
}
@@ -1643,7 +1643,7 @@ pub fn forkShell(
if (failed) |why| {
_ = libc.close(master);
_ = libc.waitpid(pid, null, 0);
- const e: libc.E = @enumFromInt(why[1]);
+ const e: libc.E = @fromBackingInt(@intCast(why[1]));
if (why[0] == 'c') return if (e == .NOENT or e == .NOTDIR) error.FileNotFound else error.AccessDenied;
return switch (e) {
// Itself, or its script's interpreter: told apart by whether it
@@ -2167,7 +2167,7 @@ pub fn reapExited(pid: libc.pid_t) ?struct { status: ?u8 } {
if (got != pid) return .{ .status = null };
const s: u32 = @bitCast(status);
if (libc.W.IFEXITED(s)) return .{ .status = @truncate(libc.W.EXITSTATUS(s)) };
- if (libc.W.IFSIGNALED(s)) return .{ .status = @truncate(128 + @as(u32, @intFromEnum(libc.W.TERMSIG(s)))) };
+ if (libc.W.IFSIGNALED(s)) return .{ .status = @truncate(128 + @as(u32, @backingInt(libc.W.TERMSIG(s)))) };
return .{ .status = null };
}
@@ -2194,7 +2194,7 @@ pub fn exitStatus(pid: libc.pid_t, wait_ms: u32) ?u8 {
if (got == pid) {
const s: u32 = @bitCast(status);
if (libc.W.IFEXITED(s)) return @truncate(libc.W.EXITSTATUS(s));
- if (libc.W.IFSIGNALED(s)) return @truncate(128 + @as(u32, @intFromEnum(libc.W.TERMSIG(s))));
+ if (libc.W.IFSIGNALED(s)) return @truncate(128 + @as(u32, @backingInt(libc.W.TERMSIG(s))));
return null;
}
if (got < 0 or waited >= wait_ms) return null;
@@ -2722,8 +2722,8 @@ test "a retired shell that ignores the hangup is killed and reaped, not left a z
retireShell(pid);
// A zombie still answers kill(pid, 0); only a reaped pid is gone.
var waited: i64 = 0;
- while (libc.kill(pid, @enumFromInt(0)) == 0 and waited < 2000) : (waited += 10) sleepMs(10);
- try std.testing.expect(libc.kill(pid, @enumFromInt(0)) != 0);
+ while (libc.kill(pid, @fromBackingInt(@intCast(0))) == 0 and waited < 2000) : (waited += 10) sleepMs(10);
+ try std.testing.expect(libc.kill(pid, @fromBackingInt(@intCast(0))) != 0);
try std.testing.expect(waited >= 90); // it did ignore the hangup
}
diff --git a/src/linux/v9fs.zig b/src/linux/v9fs.zig
index 15945e7b..0d1e2e33 100644
--- a/src/linux/v9fs.zig
+++ b/src/linux/v9fs.zig
@@ -89,7 +89,7 @@ var sudo_pid: std.atomic.Value(c_int) = .init(-1);
fn forwardSignal(sig: std.posix.SIG) callconv(.c) void {
const pid = sudo_pid.load(.monotonic);
- if (pid > 0) _ = kill(pid, @intCast(@intFromEnum(sig)));
+ if (pid > 0) _ = kill(pid, @intCast(@backingInt(sig)));
}
fn launch(arena: std.mem.Allocator, args: []const [:0]const u8) !u8 {
@@ -123,8 +123,8 @@ fn launch(arena: std.mem.Allocator, args: []const [:0]const u8) !u8 {
const default: std.posix.Sigaction = .{ .handler = .{ .handler = std.posix.SIG.DFL }, .mask = std.posix.sigemptyset(), .flags = 0 };
var sig: u8 = 1;
while (sig < 65) : (sig += 1) {
- if (sig == @intFromEnum(std.posix.SIG.KILL) or sig == @intFromEnum(std.posix.SIG.STOP)) continue;
- _ = std.c.sigaction(@enumFromInt(sig), &default, null);
+ if (sig == @backingInt(std.posix.SIG.KILL) or sig == @backingInt(std.posix.SIG.STOP)) continue;
+ _ = std.c.sigaction(@fromBackingInt(@intCast(sig)), &default, null);
}
const none = std.posix.sigemptyset();
std.posix.sigprocmask(std.posix.SIG.SETMASK, &none, null);
diff --git a/src/look.zig b/src/look.zig
index f9c470cf..f4fbe52e 100644
--- a/src/look.zig
+++ b/src/look.zig
@@ -2555,7 +2555,7 @@ test "every entry point to Look takes one expansion: a diff line and a file:12:5
const line = modal.lineSlice(case.text, case.row);
// A diff line written whole; a place, as a script writes it.
const written = if (std.mem.eql(u8, case.name, "change.diff")) line else line[case.sweep[0] .. case.sweep[1] + 1];
- _ = th.wr(p, @intFromEnum(pardes.ctlfs.TopFile.look), written);
+ _ = th.wr(p, @backingInt(pardes.ctlfs.TopFile.look), written);
},
.event_write_back => {
const body = pane.file.?.content;
diff --git a/src/macos.zig b/src/macos.zig
index 37db0abd..21af41ae 100644
--- a/src/macos.zig
+++ b/src/macos.zig
@@ -1717,18 +1717,20 @@ fn mouseWithHit(button_arg: c_int, kind_arg: c_int, col: u16, row: u16, mods: u3
3 => .drag,
else => return,
};
- st.core.update(.{ .mouse = .{
- .body_hit = hit,
- .tag_hit = tag_hit,
- .button = button,
- .kind = kind,
- .col = col,
- .row = row,
- .ctrl = mods & 1 != 0,
- // Option-click is B2 and Cmd-click B3 (mouse.emulateButton).
- .alt = mods & 2 != 0,
- .super = mods & 8 != 0,
- } });
+ st.core.update(.{
+ .mouse = .{
+ .body_hit = hit,
+ .tag_hit = tag_hit,
+ .button = button,
+ .kind = kind,
+ .col = col,
+ .row = row,
+ .ctrl = mods & 1 != 0,
+ // Option-click is B2 and Cmd-click B3 (mouse.emulateButton).
+ .alt = mods & 2 != 0,
+ .super = mods & 8 != 0,
+ },
+ });
}
export fn pardes_pointer_leave() void {
@@ -2156,7 +2158,7 @@ export fn pardes_tag_layer_value(index: u32, field: u32) u32 {
const layer = &st.core.surface.tag_layers[index];
return switch (field) {
0 => layer.cols,
- 1 => @intFromEnum(layer.kind),
+ 1 => @backingInt(layer.kind),
2 => layer.id,
3 => layer.serial,
4 => layer.viewport.x,
@@ -2238,7 +2240,7 @@ export fn pardes_pointer_shape() u32 {
pardes.turn.wake();
defer pardes.turn.rest();
const st = &(state orelse return 0);
- return @intFromEnum(st.core.surface.pointer_shape);
+ return @backingInt(st.core.surface.pointer_shape);
}
export fn pardes_cursor_y() i32 {
@@ -2646,7 +2648,7 @@ fn encodeAttrs(style: pardes.CellStyle) u16 {
attrs |= @as(u16, @intFromBool(style.reverse)) << 4;
attrs |= @as(u16, @intFromBool(style.invisible)) << 5;
attrs |= @as(u16, @intFromBool(style.strikethrough)) << 6;
- attrs |= @as(u16, @intFromEnum(style.ul)) << 8;
+ attrs |= @as(u16, @backingInt(style.ul)) << 8;
return attrs;
}
@@ -2896,21 +2898,21 @@ test "pardes.h matches the Zig boundary" {
try expectEqual(@as(u8, c.PARDES_CELL_HOVER), cell_flag_hover);
try expectEqual(@as(u16, c.PARDES_TOPBAR_H), pardes.TOPBAR_H);
try expectEqual(@as(u32, c.PARDES_SCENE_CRT), scene_flag_crt);
- try expectEqual(@as(u8, c.PARDES_PANEL_OPENING), @intFromEnum(animation.Phase.opening));
- try expectEqual(@as(u8, c.PARDES_PANEL_MOVING), @intFromEnum(animation.Phase.moving));
- try expectEqual(@as(u8, c.PARDES_PANEL_CLOSING), @intFromEnum(animation.Phase.closing));
- try expectEqual(@as(u8, c.PARDES_PANEL_OFF), @intFromEnum(animation.Transition.off));
- try expectEqual(@as(u8, c.PARDES_PANEL_SLIDE), @intFromEnum(animation.Transition.slide));
- try expectEqual(@as(u8, c.PARDES_PANEL_ZOOM), @intFromEnum(animation.Transition.zoom));
- try expectEqual(@as(u8, c.PARDES_PANEL_DISSOLVE), @intFromEnum(animation.Transition.dissolve));
- try expectEqual(@as(u8, c.PARDES_PANEL_ASCII), @intFromEnum(animation.Transition.ascii));
- try expectEqual(@as(u8, c.PARDES_PANEL_VERTICAL), @intFromEnum(animation.Transition.vertical));
- try expectEqual(@as(u8, c.PARDES_PANEL_EDGES), @intFromEnum(animation.Transition.edges));
- try expectEqual(@as(u8, c.PARDES_PANEL_FALL), @intFromEnum(animation.Transition.fall));
- try expectEqual(@as(u8, c.PARDES_PANEL_WAVE), @intFromEnum(animation.Transition.wave));
- try expectEqual(@as(u8, c.PARDES_PANEL_CURTAIN), @intFromEnum(animation.Transition.curtain));
- try expectEqual(@as(u8, c.PARDES_PANEL_SCRAMBLE), @intFromEnum(animation.Transition.scramble));
- try expectEqual(@as(u8, c.PARDES_PANEL_TYPEWRITER), @intFromEnum(animation.Transition.typewriter));
+ try expectEqual(@as(u8, c.PARDES_PANEL_OPENING), @backingInt(animation.Phase.opening));
+ try expectEqual(@as(u8, c.PARDES_PANEL_MOVING), @backingInt(animation.Phase.moving));
+ try expectEqual(@as(u8, c.PARDES_PANEL_CLOSING), @backingInt(animation.Phase.closing));
+ try expectEqual(@as(u8, c.PARDES_PANEL_OFF), @backingInt(animation.Transition.off));
+ try expectEqual(@as(u8, c.PARDES_PANEL_SLIDE), @backingInt(animation.Transition.slide));
+ try expectEqual(@as(u8, c.PARDES_PANEL_ZOOM), @backingInt(animation.Transition.zoom));
+ try expectEqual(@as(u8, c.PARDES_PANEL_DISSOLVE), @backingInt(animation.Transition.dissolve));
+ try expectEqual(@as(u8, c.PARDES_PANEL_ASCII), @backingInt(animation.Transition.ascii));
+ try expectEqual(@as(u8, c.PARDES_PANEL_VERTICAL), @backingInt(animation.Transition.vertical));
+ try expectEqual(@as(u8, c.PARDES_PANEL_EDGES), @backingInt(animation.Transition.edges));
+ try expectEqual(@as(u8, c.PARDES_PANEL_FALL), @backingInt(animation.Transition.fall));
+ try expectEqual(@as(u8, c.PARDES_PANEL_WAVE), @backingInt(animation.Transition.wave));
+ try expectEqual(@as(u8, c.PARDES_PANEL_CURTAIN), @backingInt(animation.Transition.curtain));
+ try expectEqual(@as(u8, c.PARDES_PANEL_SCRAMBLE), @backingInt(animation.Transition.scramble));
+ try expectEqual(@as(u8, c.PARDES_PANEL_TYPEWRITER), @backingInt(animation.Transition.typewriter));
try expectEqual(@as(u21, c.PARDES_KEY_ENTER), pardes.Key.enter);
try expectEqual(@as(u21, c.PARDES_KEY_ESCAPE), pardes.Key.escape);
@@ -2926,24 +2928,24 @@ test "pardes.h matches the Zig boundary" {
try expectEqual(@as(u21, c.PARDES_KEY_PAGE_DOWN), pardes.Key.page_down);
try expectEqual(@as(u21, c.PARDES_KEY_DELETE), pardes.Key.delete);
- try expectEqual(c.PARDES_MOUSE_LEFT, @intFromEnum(pardes.Mouse.Button.left));
- try expectEqual(c.PARDES_MOUSE_MIDDLE, @intFromEnum(pardes.Mouse.Button.middle));
- try expectEqual(c.PARDES_MOUSE_RIGHT, @intFromEnum(pardes.Mouse.Button.right));
- try expectEqual(c.PARDES_MOUSE_WHEEL_UP, @intFromEnum(pardes.Mouse.Button.wheel_up));
- try expectEqual(c.PARDES_MOUSE_WHEEL_DOWN, @intFromEnum(pardes.Mouse.Button.wheel_down));
- try expectEqual(c.PARDES_MOUSE_WHEEL_LEFT, @intFromEnum(pardes.Mouse.Button.wheel_left));
- try expectEqual(c.PARDES_MOUSE_WHEEL_RIGHT, @intFromEnum(pardes.Mouse.Button.wheel_right));
- try expectEqual(c.PARDES_MOUSE_NONE, @intFromEnum(pardes.Mouse.Button.none));
- try expectEqual(c.PARDES_MOUSE_BACK, @intFromEnum(pardes.Mouse.Button.back));
- try expectEqual(c.PARDES_MOUSE_FORWARD, @intFromEnum(pardes.Mouse.Button.forward));
- try expectEqual(c.PARDES_MOUSE_PRESS, @intFromEnum(pardes.Mouse.Kind.press));
- try expectEqual(c.PARDES_MOUSE_RELEASE, @intFromEnum(pardes.Mouse.Kind.release));
- try expectEqual(c.PARDES_MOUSE_MOTION, @intFromEnum(pardes.Mouse.Kind.motion));
- try expectEqual(c.PARDES_MOUSE_DRAG, @intFromEnum(pardes.Mouse.Kind.drag));
+ try expectEqual(c.PARDES_MOUSE_LEFT, @backingInt(pardes.Mouse.Button.left));
+ try expectEqual(c.PARDES_MOUSE_MIDDLE, @backingInt(pardes.Mouse.Button.middle));
+ try expectEqual(c.PARDES_MOUSE_RIGHT, @backingInt(pardes.Mouse.Button.right));
+ try expectEqual(c.PARDES_MOUSE_WHEEL_UP, @backingInt(pardes.Mouse.Button.wheel_up));
+ try expectEqual(c.PARDES_MOUSE_WHEEL_DOWN, @backingInt(pardes.Mouse.Button.wheel_down));
+ try expectEqual(c.PARDES_MOUSE_WHEEL_LEFT, @backingInt(pardes.Mouse.Button.wheel_left));
+ try expectEqual(c.PARDES_MOUSE_WHEEL_RIGHT, @backingInt(pardes.Mouse.Button.wheel_right));
+ try expectEqual(c.PARDES_MOUSE_NONE, @backingInt(pardes.Mouse.Button.none));
+ try expectEqual(c.PARDES_MOUSE_BACK, @backingInt(pardes.Mouse.Button.back));
+ try expectEqual(c.PARDES_MOUSE_FORWARD, @backingInt(pardes.Mouse.Button.forward));
+ try expectEqual(c.PARDES_MOUSE_PRESS, @backingInt(pardes.Mouse.Kind.press));
+ try expectEqual(c.PARDES_MOUSE_RELEASE, @backingInt(pardes.Mouse.Kind.release));
+ try expectEqual(c.PARDES_MOUSE_MOTION, @backingInt(pardes.Mouse.Kind.motion));
+ try expectEqual(c.PARDES_MOUSE_DRAG, @backingInt(pardes.Mouse.Kind.drag));
- try expectEqual(c.PARDES_HAPTIC_NONE, @intFromEnum(pardes.Haptic.none));
- try expectEqual(c.PARDES_HAPTIC_EXEC, @intFromEnum(pardes.Haptic.exec));
- try expectEqual(c.PARDES_HAPTIC_LOOK, @intFromEnum(pardes.Haptic.look));
+ try expectEqual(c.PARDES_HAPTIC_NONE, @backingInt(pardes.Haptic.none));
+ try expectEqual(c.PARDES_HAPTIC_EXEC, @backingInt(pardes.Haptic.exec));
+ try expectEqual(c.PARDES_HAPTIC_LOOK, @backingInt(pardes.Haptic.look));
try expectEqual(@as(u16, c.PARDES_ATTR_BOLD), encodeAttrs(.{ .bold = true }));
try expectEqual(@as(u16, c.PARDES_ATTR_DIM), encodeAttrs(.{ .dim = true }));
diff --git a/src/main.zig b/src/main.zig
index e3bae75f..64614daa 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -499,7 +499,7 @@ fn nativeMain(init: std.process.Init) !void {
if (!outside) {
const owner = std.mem.span(std.c.getenv("PARDES_PID") orelse break :forwarding);
const pid = std.fmt.parseInt(std.c.pid_t, owner, 10) catch break :forwarding;
- if (pid <= 0 or std.c.kill(pid, @enumFromInt(0)) != 0) break :forwarding;
+ if (pid <= 0 or std.c.kill(pid, @fromBackingInt(@intCast(0))) != 0) break :forwarding;
}
// Can I reach it? That is the other two, and it is a separate answer.
diff --git a/src/mini.zig b/src/mini.zig
index 8af64201..ce291c99 100644
--- a/src/mini.zig
+++ b/src/mini.zig
@@ -130,7 +130,7 @@ pub fn generate(gpa: std.mem.Allocator, source: []const u8, styles: []const u8)
if (source.len > max_input_bytes) return error.MiniTooLarge;
if (!std.unicode.utf8ValidateSlice(source)) return error.InvalidUtf8;
if (styles.len != 0 and styles.len != source.len) return error.InvalidMiniColors;
- for (styles) |color| if (color > @intFromEnum(syntax.Syn.comment)) return error.InvalidMiniColors;
+ for (styles) |color| if (color > @backingInt(syntax.Syn.comment)) return error.InvalidMiniColors;
const len = try render(null, source, styles);
const content = try gpa.alloc(u8, len);
errdefer gpa.free(content);
@@ -248,17 +248,17 @@ test "Mini chooses highlighted dots over plain ink with stable color ties" {
const gpa = std.testing.allocator;
const source = "xx\nxx\nxx\nxx\n";
var styles: [source.len]u8 = @splat(0);
- styles[0] = @intFromEnum(syntax.Syn.keyword);
+ styles[0] = @backingInt(syntax.Syn.keyword);
const rare = try generate(gpa, source, &styles);
defer rare.deinit(gpa);
try std.testing.expectEqualStrings("โฃฟ\n", rare.content);
try std.testing.expectEqualSlices(u8, &.{ 1, 1, 1, 0 }, rare.colors);
- styles[0] = @intFromEnum(syntax.Syn.string);
- styles[1] = @intFromEnum(syntax.Syn.number);
+ styles[0] = @backingInt(syntax.Syn.string);
+ styles[1] = @backingInt(syntax.Syn.number);
const tied = try generate(gpa, source, &styles);
defer tied.deinit(gpa);
try std.testing.expectEqualSlices(u8, &.{ 2, 2, 2, 0 }, tied.colors);
- styles[3] = @intFromEnum(syntax.Syn.number);
+ styles[3] = @backingInt(syntax.Syn.number);
const majority = try generate(gpa, source, &styles);
defer majority.deinit(gpa);
try std.testing.expectEqualSlices(u8, &.{ 3, 3, 3, 0 }, majority.colors);
diff --git a/src/mouse.zig b/src/mouse.zig
index 536a4fdb..43323f9a 100644
--- a/src/mouse.zig
+++ b/src/mouse.zig
@@ -379,7 +379,7 @@ fn programMouse(p: *Pardes, m: Mouse) bool {
.none => null,
else => return false,
};
- const bit: u3 = if (button) |b| @as(u3, 1) << @intCast(@intFromEnum(b)) else 0;
+ const bit: u3 = if (button) |b| @as(u3, 1) << @intCast(@backingInt(b)) else 0;
const at = p.presentation.pointer(p.screen_w, p.screen_h, @min(m.col, p.screen_w -| 1), @min(m.row, p.screen_h -| 1));
var mods: panes.terminal.MouseMods = .{ .shift = m.shift, .alt = m.alt, .ctrl = m.ctrl };
var buf: [64]u8 = undefined;
@@ -701,7 +701,7 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
// look; the rest of the gesture is inert
if (p.drag == .select and p.drag.select.button == config.look_button) {
if (p.panes[p.drag.select.id]) |t| {
- t.sel[@intFromEnum(config.look_button)].state = .none;
+ t.sel[@backingInt(config.look_button)].state = .none;
if (comptime pdf_enabled)
panes.Pdf.pointerCancel(t, p.drag.select.pdf);
}
@@ -812,7 +812,7 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
// an execute or look drag cancels it (textselect23's mask)
if (p.drag == .select) {
if (p.panes[p.drag.select.id]) |t| {
- t.sel[@intFromEnum(p.drag.select.button)].state = .none;
+ t.sel[@backingInt(p.drag.select.button)].state = .none;
if (comptime pdf_enabled)
panes.Pdf.pointerCancel(t, p.drag.select.pdf);
}
@@ -833,8 +833,8 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
pane.scrollBy(if (m.button == config.look_button) local else -local);
} else if (edit.pointerTextSelection(p, id, mcol, mrow, m.body_hit, p.pointer_tag_hit)) |pointed| {
if (m.button == config.look_button) p.active = id;
- pane.clearPointerSelection(@intFromEnum(m.button));
- pane.sel[@intFromEnum(m.button)] = pointed.sel;
+ pane.clearPointerSelection(@backingInt(m.button));
+ pane.sel[@backingInt(m.button)] = pointed.sel;
p.drag = .{
.select = .{
.id = id,
@@ -906,7 +906,7 @@ pub fn dragUpdate(p: *Pardes, mcol: u16, mrow: u16, body_hit: ?Mouse.BodyHit) vo
.select => |*s| {
if (p.panes[s.id]) |pane| {
const r = p.rects[s.id];
- const b = @intFromEnum(s.button);
+ const b = @backingInt(s.button);
const tag_rows: i32 = pane.tag_rows;
if (pane.body_rows > 0 and pane.sel[b].r0 >= tag_rows) if (body_hit) |supplied| {
const mapped_hit = bodyHitForPane(p, s.id, supplied, true) orelse return;
@@ -1235,10 +1235,10 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void {
}
if (s.chorded) {
// a cut/paste chord consumed this drag; the release is inert
- pane.sel[@intFromEnum(s.button)].state = .none;
+ pane.sel[@backingInt(s.button)].state = .none;
return;
}
- const b = @intFromEnum(s.button);
+ const b = @backingInt(s.button);
pane.sel[b].state = .done;
if (s.button == config.select_button) {
const sl = pane.sel[sel_slot];
@@ -1501,7 +1501,7 @@ test "plain left click clears explicit modal selection" {
try std.testing.expectEqual(@as(i32, 3), pane.body.cur_col);
try std.testing.expect(!pane.body.vsel.active);
try std.testing.expect(!pane.body.msel.active);
- try std.testing.expectEqual(.none, pane.sel[@intFromEnum(config.select_button)].state);
+ try std.testing.expectEqual(.none, pane.sel[@backingInt(config.select_button)].state);
}
test "selection drag and queued release do not enter panel pending state" {
diff --git a/src/ninep/addr.zig b/src/ninep/addr.zig
index 3feda5a2..86d2d49e 100644
--- a/src/ninep/addr.zig
+++ b/src/ninep/addr.zig
@@ -638,9 +638,9 @@ test "the address language, form by form" {
}
// Each failure says which it is.
for ([_][2][]const u8{
- .{ "zzz", e_syntax }, .{ "/nomatch/", e_no_match }, .{ "99", e_range },
- .{ "#999", e_range }, .{ "/a[/", e_regexp }, .{ "/(a/", e_regexp },
- .{ "/*a/", e_regexp }, .{ "99:1", e_range }, .{ "2:0", e_col_zero },
+ .{ "zzz", e_syntax }, .{ "/nomatch/", e_no_match }, .{ "99", e_range },
+ .{ "#999", e_range }, .{ "/a[/", e_regexp }, .{ "/(a/", e_regexp },
+ .{ "/*a/", e_regexp }, .{ "99:1", e_range }, .{ "2:0", e_col_zero },
}) |c| {
_ = th.wr(p, addr, "#0");
try testing.expectEqualStrings(c[1], th.wr(p, addr, c[0]).reply.ename);
diff --git a/src/ninep/cols.zig b/src/ninep/cols.zig
index 59f6ae42..6f5bee23 100644
--- a/src/ninep/cols.zig
+++ b/src/ninep/cols.zig
@@ -34,7 +34,7 @@ pub fn writeLayout(p: *Pardes, w: *std.Io.Writer) !void {
const active = activeColumn(p);
for (0..p.ncol) |c| {
try w.print("{d} {d} {d} {d} {s} {s}", .{
- layout.columnSerial(p, c), c, p.col_x[c], p.col_w[c],
+ layout.columnSerial(p, c), c, p.col_x[c], p.col_w[c],
if (active == c) "current" else "notcurrent", if (p.col_n[c] == 0) "empty" else "full",
});
for (p.col_panes[c][0..p.col_n[c]]) |id| if (p.panes[id]) |pane| try w.print(" {d}", .{pane.serial});
@@ -229,8 +229,8 @@ test "Joincol is refused when the joined column cannot give each pane its tag an
const p = try pardes.Pardes.init(testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 12 });
defer p.deinit();
while (p.nextEffect()) |_| {}
- const ctl = @intFromEnum(tree.TopFile.ctl);
- const focus = @intFromEnum(tree.TopFile.focus);
+ const ctl = @backingInt(tree.TopFile.ctl);
+ const focus = @backingInt(tree.TopFile.focus);
// Two panes in the first column, then a second column of two.
const a = try th.newPane(p);
_ = a;
@@ -257,10 +257,10 @@ test "pane/new takes rows from a pane in another column before refusing ENOSPC"
while (p.nextEffect()) |_| {}
const first = p.panes[p.active].?.serial;
// A second column holding one tall pane.
- try testing.expectEqual(tree.Status.ok, th.wr(p, @intFromEnum(tree.TopFile.ctl), "Newcol\n").reply.status);
+ try testing.expectEqual(tree.Status.ok, th.wr(p, @backingInt(tree.TopFile.ctl), "Newcol\n").reply.status);
const tall = try th.newPane(p);
const tall_col = layout.findPane(p, p.paneBySerial(tall).?).?.col;
- const focus = @intFromEnum(tree.TopFile.focus);
+ const focus = @backingInt(tree.TopFile.focus);
var digits: [16]u8 = undefined;
// From the first column, until pane/new is refused.
var moved = false;
@@ -289,7 +289,7 @@ test "exactly 4096 bytes written with echo's newline after a truncation fit ever
defer p.deinit();
const serial = th.serialOf(p);
const text = &@as([4096]u8, @splat('w')) ++ "\n";
- for ([_]u64{ tree.Node.of(serial, .tag), tree.Node.ofCol(layout.columnSerial(p, 0), .tag), @intFromEnum(tree.TopFile.tag) }) |node| {
+ for ([_]u64{ tree.Node.of(serial, .tag), tree.Node.ofCol(layout.columnSerial(p, 0), .tag), @backingInt(tree.TopFile.tag) }) |node| {
_ = th.call(p, .{ .tag = 1, .op = .setattr, .node = node, .truncate = true });
const h = th.call(p, .{ .tag = 2, .op = .open, .node = node, .omode = 1 }).reply.handle;
const r = th.call(p, .{ .tag = 3, .op = .write, .node = node, .handle = h, .data = text });
@@ -320,8 +320,8 @@ test "a Newcol refused because the tags would not fit logs its err alone and spe
}
try testing.expect(p.col_n[col] >= 2);
p.sync();
- const ctl = @intFromEnum(tree.TopFile.ctl);
- const focus = @intFromEnum(tree.TopFile.focus);
+ const ctl = @backingInt(tree.TopFile.ctl);
+ const focus = @backingInt(tree.TopFile.focus);
var digits: [16]u8 = undefined;
const own = try std.fmt.bufPrint(&digits, "{d}\n", .{pane.serial});
var refused = false;
@@ -349,7 +349,7 @@ test "a Newcol refused because the tags would not fit logs its err alone and spe
test "a tagexec word that makes, acts on and focuses no pane reads back nothing" {
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
- const tagexec = @intFromEnum(tree.TopFile.tagexec);
+ const tagexec = @backingInt(tree.TopFile.tagexec);
try testing.expectEqual(tree.Status.ok, th.wr(p, tagexec, "Newcol\n").reply.status);
try testing.expectEqualStrings("", th.rd(p, tagexec, 0, 64).bytes);
// A column's New makes one, and answers it.
@@ -362,7 +362,7 @@ test "a tagexec word that makes, acts on and focuses no pane reads back nothing"
test "New written to a column's ctl reads back the new pane alone, as its exec does" {
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
- const root_exec = @intFromEnum(tree.TopFile.exec);
+ const root_exec = @backingInt(tree.TopFile.exec);
_ = th.wr(p, root_exec, "Msg before\n");
const ctl_node = tree.Node.ofCol(layout.columnSerial(p, 0), .ctl);
try testing.expectEqual(tree.Status.ok, th.wr(p, ctl_node, "New\n").reply.status);
@@ -390,7 +390,7 @@ test "a pane's word written to /tagexec or a column's exec is refused, and acts
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
const col_exec = tree.Node.ofCol(layout.columnSerial(p, 0), .exec);
- for ([_]u64{ @intFromEnum(tree.TopFile.tagexec), col_exec }) |node| {
+ for ([_]u64{ @backingInt(tree.TopFile.tagexec), col_exec }) |node| {
for ([_][]const u8{ "Undo\n", "Msg hi\n", "Redo\n" }) |line| {
const refused = th.wr(p, node, line);
try testing.expectEqual(E.INVAL, refused.errno());
@@ -411,7 +411,7 @@ test "Help and Find at /tagexec act in the session's directory, not the keyboard
const session = buf[0..try tmp.dir.realPath(testing.io, &buf)];
@memcpy(p.session_dir[0..session.len], session);
p.session_dir_len = @intCast(session.len);
- const tagexec = @intFromEnum(tree.TopFile.tagexec);
+ const tagexec = @backingInt(tree.TopFile.tagexec);
for ([_][]const u8{ "Help\n", "Find needle\n" }) |line| {
try testing.expectEqual(tree.Status.ok, th.wr(p, tagexec, line).reply.status);
const made = p.panes[p.active].?.file.?.path;
@@ -427,7 +427,7 @@ test "a shell command at /tagexec or a column's exec is a command pane in the se
const term = p.panes[p.active].?;
try testing.expect(pardes.exec.takesCommandLine(p, p.active));
const col_exec = tree.Node.ofCol(layout.columnSerial(p, 0), .exec);
- for ([_]u64{ @intFromEnum(tree.TopFile.tagexec), col_exec }) |node| {
+ for ([_]u64{ @backingInt(tree.TopFile.tagexec), col_exec }) |node| {
p.active = p.paneBySerial(term.serial).?;
const before = p.next_serial;
const r = th.wr(p, node, "echo from-the-tag\n");
@@ -443,7 +443,7 @@ test "a shell command at /tagexec or a column's exec is a command pane in the se
test "New and Tty run at /tagexec and a column's exec, with no pane at all too" {
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
- const tagexec = @intFromEnum(tree.TopFile.tagexec);
+ const tagexec = @backingInt(tree.TopFile.tagexec);
const col_exec = tree.Node.ofCol(layout.columnSerial(p, 0), .exec);
for ([_]u64{ tagexec, col_exec }) |node| for ([_][]const u8{ "New\n", "Tty\n" }) |line| {
const before = p.next_serial;
@@ -469,7 +469,7 @@ test "every pane word a tag no pane owns does not hold is refused there, Edit in
const Builtin = pardes.builtins.registry.Builtin();
const col_exec = tree.Node.ofCol(layout.columnSerial(p, 0), .exec);
for ([_]struct { node: u64, own: []const u8 }{
- .{ .node = @intFromEnum(tree.TopFile.tagexec), .own = pardes.config.topbar_str },
+ .{ .node = @backingInt(tree.TopFile.tagexec), .own = pardes.config.topbar_str },
.{ .node = col_exec, .own = tagline.column_tag_default },
}) |tag_file| {
var checked: usize = 0;
@@ -517,7 +517,7 @@ test "layout lists each column's place, panes and state, and the active one" {
const first_serial = layout.columnSerial(p, 0);
const new_serial = layout.columnSerial(p, 1);
try testing.expect(first_serial != new_serial);
- const layout_node = @intFromEnum(tree.TopFile.layout);
+ const layout_node = @backingInt(tree.TopFile.layout);
const text = th.rd(p, layout_node, 0, 4096).bytes;
var want: [256]u8 = undefined;
const first = try std.fmt.bufPrint(&want, "{d} 0 {d} {d} notcurrent full {d}\n", .{ first_serial, p.col_x[0], p.col_w[0], p.panes[0].?.serial });
@@ -528,19 +528,19 @@ test "layout lists each column's place, panes and state, and the active one" {
try testing.expect(text.len > 0);
try testing.expectEqual(@as(u64, 0), th.call(p, .{ .tag = 1, .op = .getattr, .node = layout_node }).reply.attr.size); // generated by each read
// /index says which column each pane is in, by its serial, last.
- try testing.expect(std.mem.endsWith(u8, th.rd(p, @intFromEnum(tree.TopFile.index), 0, 4096).bytes, try std.fmt.bufPrint(&want, " {d}\n", .{first_serial})));
+ try testing.expect(std.mem.endsWith(u8, th.rd(p, @backingInt(tree.TopFile.index), 0, 4096).bytes, try std.fmt.bufPrint(&want, " {d}\n", .{first_serial})));
try testing.expect(th.logHas(p, try std.fmt.bufPrint(&want, "newcol {d}\n", .{new_serial})));
// A column that closes takes its name with it; the others keep theirs.
try p.removeColumn(1);
try testing.expect(th.logHas(p, try std.fmt.bufPrint(&want, "delcol {d}\n", .{new_serial})));
- try testing.expectEqual(E.NOENT, th.look_up(p, @intFromEnum(tree.TopFile.col), try std.fmt.bufPrint(&want, "{d}", .{new_serial})).errno());
+ try testing.expectEqual(E.NOENT, th.look_up(p, @backingInt(tree.TopFile.col), try std.fmt.bufPrint(&want, "{d}", .{new_serial})).errno());
try testing.expectEqual(first_serial, layout.columnSerial(p, 0));
}
test "a column's tag and the workspace's read, replace and append as a pane tag does, on one line" {
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
- const col_dir = @intFromEnum(tree.TopFile.col);
+ const col_dir = @backingInt(tree.TopFile.col);
const serial = layout.columnSerial(p, 0);
var name: [16]u8 = undefined;
try testing.expectEqual(tree.Status.ok, th.look_up(p, col_dir, try std.fmt.bufPrint(&name, "{d}", .{serial})).reply.status);
@@ -557,7 +557,7 @@ test "a column's tag and the workspace's read, replace and append as a pane tag
// `>>` appends; a newline in a one-line tag is a space.
_ = th.wr(p, tag, " Lint\nNow");
try testing.expectEqualStrings("Make Lint Now", th.rd(p, tag, 0, 4096).bytes);
- const top = @intFromEnum(tree.TopFile.tag);
+ const top = @backingInt(tree.TopFile.tag);
_ = th.call(p, .{ .tag = 3, .op = .setattr, .node = top, .truncate = true });
_ = th.wr(p, top, "Newcol Exit\n");
try testing.expectEqualStrings("Newcol Exit", tagline.topbar(p));
@@ -574,11 +574,11 @@ test "a focus write makes its pane's column the active one: layout says so and p
p.sync();
try testing.expectEqual(@as(usize, 1), layout.findPane(p, p.active).?.col);
var digits: [16]u8 = undefined;
- _ = th.wr(p, @intFromEnum(tree.TopFile.focus), try std.fmt.bufPrint(&digits, "{d}\n", .{left}));
+ _ = th.wr(p, @backingInt(tree.TopFile.focus), try std.fmt.bufPrint(&digits, "{d}\n", .{left}));
var want: [32]u8 = undefined;
- const text = th.rd(p, @intFromEnum(tree.TopFile.layout), 0, 4096).bytes;
+ const text = th.rd(p, @backingInt(tree.TopFile.layout), 0, 4096).bytes;
try testing.expect(std.mem.endsWith(u8, text, try std.fmt.bufPrint(&want, "active {d}\n", .{layout.columnSerial(p, 0)})));
- const made = th.call(p, .{ .tag = 1, .op = .open, .node = @intFromEnum(tree.TopFile.new) }).reply.handle;
+ const made = th.call(p, .{ .tag = 1, .op = .open, .node = @backingInt(tree.TopFile.new) }).reply.handle;
try testing.expectEqual(@as(usize, 0), layout.findPane(p, p.paneBySerial(made).?).?.col);
}
}
@@ -590,7 +590,7 @@ test "a refused write after a truncation leaves every kind of tag as it was, and
const col = layout.columnSerial(p, 0);
const big = &@as([limits.max_tag_tail + 1]u8, @splat('w'));
// Each tag: a truncating open, then a write too long: nothing changes.
- for ([_]u64{ Node.of(serial, .tag), Node.ofCol(col, .tag), @intFromEnum(tree.TopFile.tag) }) |node| {
+ for ([_]u64{ Node.of(serial, .tag), Node.ofCol(col, .tag), @backingInt(tree.TopFile.tag) }) |node| {
_ = th.wr(p, node, " Mine");
const before = try testing.allocator.dupe(u8, th.rd(p, node, 0, 1 << 16).bytes);
defer testing.allocator.free(before);
@@ -651,13 +651,13 @@ test "a column's ctl and exec act on it as its tag would, and rmdir closes it on
try testing.expectEqual(@as(?usize, 0), layout.columnBySerial(p, right));
try testing.expect(std.mem.endsWith(u8, headerText(p, right).?, " Mine"));
// The root's ctl points a column word at the column's own.
- try testing.expect(std.mem.endsWith(u8, th.wr(p, @intFromEnum(tree.TopFile.ctl), "Delcol\n").reply.ename, "write it to col/<serial>/ctl"));
+ try testing.expect(std.mem.endsWith(u8, th.wr(p, @backingInt(tree.TopFile.ctl), "Delcol\n").reply.ename, "write it to col/<serial>/ctl"));
}
test "tagexec runs a word as a click in the workspace tag; exec files read back what they touched; their messages are the session's" {
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
- const tagexec = @intFromEnum(tree.TopFile.tagexec);
+ const tagexec = @backingInt(tree.TopFile.tagexec);
try testing.expectEqual(tree.Status.ok, th.look_up(p, tree.root, "tagexec").reply.status);
try testing.expectEqual(tree.Status.ok, th.wr(p, tagexec, "Newcol\n").reply.status);
try testing.expectEqual(@as(usize, 2), p.ncol);
@@ -680,7 +680,7 @@ test "a word run from the workspace's or a column's tag runs in the session's di
defer p.deinit();
const session = p.sessionDir();
try testing.expect(!std.mem.eql(u8, session, pardes.Pardes.paneDir(p.panes[0].?))); // the file is elsewhere
- const dirs = [_]u64{ @intFromEnum(tree.TopFile.tagexec), Node.ofCol(layout.columnSerial(p, 0), .exec) };
+ const dirs = [_]u64{ @backingInt(tree.TopFile.tagexec), Node.ofCol(layout.columnSerial(p, 0), .exec) };
for (dirs) |node| {
try testing.expectEqual(tree.Status.ok, th.wr(p, node, "true\n").reply.status);
const made = p.paneBySerial(p.fs.results[0]).?;
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index 6b4bbafb..3e7c367b 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -1277,15 +1277,15 @@ const withFile = th.withFile;
const serialOf = th.serialOf;
const Node = tree.Node;
const Status = tree.Status;
-const root_status = @intFromEnum(tree.TopFile.status);
-const root_look = @intFromEnum(tree.TopFile.look);
-const root_exec = @intFromEnum(tree.TopFile.exec);
+const root_status = @backingInt(tree.TopFile.status);
+const root_look = @backingInt(tree.TopFile.look);
+const root_exec = @backingInt(tree.TopFile.exec);
test "a control character in a write to any ctl refuses the whole write, and a quoted line shows a tab as a blank" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
const col = layout.columnSerial(p, 0);
- for ([_]u64{ @intFromEnum(tree.TopFile.ctl), Node.of(serialOf(p), .ctl), Node.ofCol(col, .ctl) }) |node| {
+ for ([_]u64{ @backingInt(tree.TopFile.ctl), Node.of(serialOf(p), .ctl), Node.ofCol(col, .ctl) }) |node| {
const r = wr(p, node, "Wrap off\nbo\x01gus\n");
try testing.expectEqual(E.INVAL, r.errno());
try testing.expectEqualStrings(e_control, r.reply.ename);
@@ -1325,7 +1325,7 @@ test "pane ctl read is acme's fields -- index's five, width in cells, font, tab
test "commands lists every builtin with its argument and the ctl that takes it" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const node = @intFromEnum(tree.TopFile.commands);
+ const node = @backingInt(tree.TopFile.commands);
const listed = rd(p, node, 0, 1 << 16);
try testing.expectEqual(@as(u64, listed.bytes.len), call(p, .{ .tag = 1, .op = .getattr, .node = node }).reply.attr.size);
try testing.expectEqual(E.PERM, wr(p, node, "Del\n").errno());
@@ -1372,7 +1372,7 @@ test "focus reads the pane with the keyboard, and a serial written to it moves t
defer p.deinit();
const first = serialOf(p);
const second = try th.newPane(p);
- const focus = @intFromEnum(tree.TopFile.focus);
+ const focus = @backingInt(tree.TopFile.focus);
var line: [16]u8 = undefined;
try testing.expectEqualStrings(try std.fmt.bufPrint(&line, "{d}\n", .{second}), rd(p, focus, 0, 64).bytes);
try testing.expectEqual(@as(u64, rd(p, focus, 0, 64).bytes.len), call(p, .{ .tag = 1, .op = .getattr, .node = focus }).reply.attr.size);
@@ -1447,7 +1447,7 @@ test "the root ctl reads the settings as a write takes them, and takes the sessi
const gpa = testing.allocator;
const p = try withFile(gpa, "x\n");
defer p.deinit();
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
const first = rd(p, root_ctl, 0, 1 << 16);
try testing.expectEqual(Status.ok, first.reply.status);
const settings = try gpa.dupe(u8, first.bytes);
@@ -1575,7 +1575,7 @@ test "a write of an Edit block carries it whole, to a pane's ctl, the root's ctl
try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .ctl), "Edit ,x/foo/{\ni/[/\na/]/\n}\n").reply.status);
try testing.expectEqualStrings("[foo] x\n[foo] y\n", rd(p, body, 0, 64).bytes);
p.active = p.paneBySerial(serial).?;
- try testing.expectEqual(Status.ok, wr(p, @intFromEnum(tree.TopFile.ctl), "Edit ,x/\\[/{\nc/</\n}\n").reply.status);
+ try testing.expectEqual(Status.ok, wr(p, @backingInt(tree.TopFile.ctl), "Edit ,x/\\[/{\nc/</\n}\n").reply.status);
try testing.expectEqualStrings("<foo] x\n<foo] y\n", rd(p, body, 0, 64).bytes);
try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .exec), "Edit $a\nend\n.\n").reply.status);
try testing.expectEqualStrings("<foo] x\n<foo] y\nend\n", rd(p, body, 0, 64).bytes);
@@ -1603,11 +1603,11 @@ test "a message from a root ctl write is the session's in the log" {
defer p.deinit();
p.update(.tick); // the pane's `new` is logged before the log is opened
while (p.nextEffect()) |_| {}
- const log = @intFromEnum(tree.TopFile.log);
+ const log = @backingInt(tree.TopFile.log);
const f = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
const frozen = call(p, .{ .tag = 2, .op = .read, .node = log, .handle = f, .size = 8192 }).bytes.len;
_ = call(p, .{ .tag = 3, .op = .write, .node = log, .handle = f, .data = "follow" });
- try testing.expectEqual(Status.ok, wr(p, @intFromEnum(tree.TopFile.ctl), "Kill\n").reply.status);
+ try testing.expectEqual(Status.ok, wr(p, @backingInt(tree.TopFile.ctl), "Kill\n").reply.status);
// What it said, the session's; its own words name it, so its Verbose
// announcement gives way to them.
try testing.expectEqualStrings("msg - Kill: nothing running\n", call(p, .{ .tag = 5, .op = .read, .node = log, .handle = f, .off = frozen, .size = 4096 }).bytes);
@@ -1661,7 +1661,7 @@ test "the root look's file:/re/ goes on from the dot, and a miss leaves the dot
const p = try withFile(gpa, "foo x foo y\nfoo\n");
defer p.deinit();
const dot = Node.of(serialOf(p), .dot);
- const root = @intFromEnum(tree.TopFile.look);
+ const root = @backingInt(tree.TopFile.look);
var line: [256]u8 = undefined;
const path = p.panes[0].?.file.?.path;
const again = try std.fmt.bufPrint(&line, "{s}:/foo/\n", .{path});
@@ -1677,7 +1677,7 @@ test "a look's miss repeats the path whole up to 256 bytes, then gives up its mi
const gpa = testing.allocator;
const p = try withFile(gpa, "x\n");
defer p.deinit();
- const root = @intFromEnum(tree.TopFile.look);
+ const root = @backingInt(tree.TopFile.look);
const long = "some/deeply/nested/directory/that/goes/on/and/on/with/a_rather_long_file_name.txt";
var line: [512]u8 = undefined;
_ = wr(p, root, try std.fmt.bufPrint(&line, "{s}\n", .{long}));
@@ -1926,7 +1926,7 @@ test "Zerox makes a second pane on one buffer: one text, undo and dirty state, i
const a = p.panes[0].?;
const b = p.panes[twin_id].?;
// Both in the index, each its serial, one name.
- const index = rd(p, @intFromEnum(tree.TopFile.index), 0, 4096).bytes;
+ const index = rd(p, @backingInt(tree.TopFile.index), 0, 4096).bytes;
try testing.expectEqual(@as(usize, 2), std.mem.count(u8, index, "/z.txt"));
// b's cursor on `three`; a line written above it in a moves it down.
b.body.cur_row = 2;
@@ -2070,7 +2070,7 @@ test "a bad Tab width and a bad Incl directory are refused invalid, changing not
defer config.tab_now = config.tab_width;
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
for ([_][]const u8{ "Tab 0\n", "Tab 17\n", "Tab x\n" }) |line| {
try testing.expectEqual(E.INVAL, wr(p, root_ctl, line).errno());
// Run from a pane, as a tag click runs it: said invalid too.
@@ -2153,7 +2153,7 @@ test "round 39's small refusals: one name an open, small scratches unasked, twin
tree.runClosedLines(p);
try testing.expectEqualStrings("/tmp/pardes-one.txt", pane.file.?.path);
// Bare Tab on the root ctl says the width, as from a pane.
- try testing.expectEqual(Status.ok, wr(p, @intFromEnum(tree.TopFile.ctl), "Tab\n").reply.status);
+ try testing.expectEqual(Status.ok, wr(p, @backingInt(tree.TopFile.ctl), "Tab\n").reply.status);
// Errnos a mount reads from the words.
_ = wr(p, Node.of(serial, .name), try std.fmt.bufPrint(&line, "{s}/f.txt\n", .{dir}));
try testing.expect(p.executeBuiltinLine(0, "Get"));
@@ -2230,7 +2230,7 @@ test "Mount with no dial is wrong #args, and a dial that is no address says bad
if (comptime !pardes.hosted) return;
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
const bare = wr(p, root_ctl, "Mount work\n");
try testing.expectEqual(E.INVAL, bare.errno());
try testing.expectStringStartsWith(bare.reply.ename, "wrong #args");
@@ -2326,7 +2326,7 @@ test "a refusal's +Unsaved goes in the session's directory when the active pane'
const serial = serialOf(p);
try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .name), "/tmp/pardes-no-such-dir-zz/x.txt\n").reply.status);
try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .body), "edited\n").reply.status);
- try testing.expectEqual(Status.err, wr(p, @intFromEnum(tree.TopFile.ctl), "Exit\n").reply.status);
+ try testing.expectEqual(Status.err, wr(p, @backingInt(tree.TopFile.ctl), "Exit\n").reply.status);
const unsaved = for (p.panes) |slot| {
const pane = slot orelse continue;
const f = pane.file orelse continue;
@@ -2357,7 +2357,7 @@ test "a look at a file it may not read fails the write naming the file" {
test "Pager is a setting of the root ctl: pardes by default, off taken, anything else refused with its choices" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
try testing.expect(std.mem.indexOf(u8, rd(p, root_ctl, 0, 1 << 16).bytes, "Pager pardes\n") != null);
try testing.expectEqual(Status.ok, wr(p, root_ctl, "Pager off\n").reply.status);
try testing.expectEqual(config.Runtime.Pager.off, p.settings.pager);
@@ -2368,7 +2368,7 @@ test "Pager is a setting of the root ctl: pardes by default, off taken, anything
test "a bad setting value is quoted, so two different bad values log as two records, never one counted twice" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
_ = wr(p, root_ctl, "Verbose maybe\n");
_ = wr(p, root_ctl, "Verbose nope\n");
try testing.expect(th.logHas(p, "takes on, off \"maybe\"\n"));
@@ -2494,14 +2494,14 @@ test "look and exec read back what the last command touched, a ctl write's too"
const made = p.panes[p.active].?.serial;
try testing.expect(made != serial);
try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{made}), rd(p, root_exec, 0, 64).bytes);
- try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{made}), rd(p, @intFromEnum(tree.TopFile.look), 0, 64).bytes);
+ try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{made}), rd(p, @backingInt(tree.TopFile.look), 0, 64).bytes);
// A ctl write that makes nothing names the pane it ran at.
- try testing.expectEqual(tree.Status.ok, wr(p, @intFromEnum(tree.TopFile.ctl), "Verbose off\n").reply.status);
+ try testing.expectEqual(tree.Status.ok, wr(p, @backingInt(tree.TopFile.ctl), "Verbose off\n").reply.status);
try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{made}), rd(p, root_exec, 0, 64).bytes);
// Closed, it is no pane to go to: a fresh read of look is empty.
try testing.expectEqual(tree.Status.ok, wr(p, Node.of(made, .ctl), "Del\n").reply.status);
try testing.expect(p.paneBySerial(made) == null);
- try testing.expectEqualStrings("", rd(p, @intFromEnum(tree.TopFile.look), 0, 64).bytes);
+ try testing.expectEqualStrings("", rd(p, @backingInt(tree.TopFile.look), 0, 64).bytes);
}
test "a builtin's Verbose announcement is logged only when it succeeds, its failure said now or by the host later" {
@@ -2568,7 +2568,7 @@ test "an error's words give the errno a mount reads: EINVAL for what is malforme
test "DumpConfig's whole report writes back to the root ctl, line by line, with no error" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
try testing.expectEqual(Status.ok, wr(p, root_ctl, "DumpConfig\n").reply.status);
const report = for (p.panes) |slot| {
const pane = slot orelse continue;
@@ -2594,7 +2594,7 @@ test "a Restore asks again for the ThemeFile the dump names, as a /ctl write of
const p = try withFile(gpa, "x\n");
defer p.deinit();
const good = "/tmp/pardes-restored-theme.zon";
- _ = wr(p, @intFromEnum(tree.TopFile.ctl), "ThemeFile " ++ good ++ "\n");
+ _ = wr(p, @backingInt(tree.TopFile.ctl), "ThemeFile " ++ good ++ "\n");
var custom = pardes.themes[0];
custom.name = "restored";
var encoded: std.Io.Writer.Allocating = .init(gpa);
@@ -2622,7 +2622,7 @@ test "a ThemeFile that fails to load changes nothing: the root ctl still names t
const gpa = testing.allocator;
const p = try withFile(gpa, "x\n");
defer p.deinit();
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
// None loaded: a failed one leaves Theme as it was.
_ = wr(p, root_ctl, "ThemeFile /tmp/pardes-no-such-theme.zon\n");
pardes.colors.failThemeFile(p, p.theme_file_generation, error.FileNotFound);
@@ -2648,7 +2648,7 @@ test "after a ThemeFile the root ctl and DumpConfig say ThemeFile and its path,
const gpa = testing.allocator;
const p = try withFile(gpa, "x\n");
defer p.deinit();
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
const path = "/tmp/pardes-mine-theme.zon";
try testing.expectEqual(Status.ok, wr(p, root_ctl, "ThemeFile " ++ path ++ "\n").reply.status);
var custom = pardes.themes[0];
@@ -2682,7 +2682,7 @@ test "Joincol with no column to the right and Theme with no such theme say so" {
const gpa = testing.allocator;
const p = try withFile(gpa, "x\n");
defer p.deinit();
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
const joined = wr(p, root_ctl, "Joincol\n");
try testing.expectEqual(tree.Status.err, joined.reply.status);
try testing.expectStringStartsWith(joined.reply.ename, "Joincol: no column to the right");
@@ -2731,10 +2731,10 @@ test "a look after Newcol fills the empty column the keyboard is on" {
var line: [4200]u8 = undefined;
// Newcol makes an empty column and gives its tag the keyboard; no pane
// has it, so focus reads empty.
- try testing.expectEqual(tree.Status.ok, wr(p, @intFromEnum(tree.TopFile.ctl), "Newcol\n").reply.status);
+ try testing.expectEqual(tree.Status.ok, wr(p, @backingInt(tree.TopFile.ctl), "Newcol\n").reply.status);
try testing.expectEqual(@as(usize, 0), p.col_n[p.ncol - 1]);
- try testing.expectEqualStrings("", rd(p, @intFromEnum(tree.TopFile.focus), 0, 64).bytes);
- try testing.expectEqual(tree.Status.ok, wr(p, @intFromEnum(tree.TopFile.look), try std.fmt.bufPrint(&line, "{s}/f.txt\n", .{at})).reply.status);
+ try testing.expectEqualStrings("", rd(p, @backingInt(tree.TopFile.focus), 0, 64).bytes);
+ try testing.expectEqual(tree.Status.ok, wr(p, @backingInt(tree.TopFile.look), try std.fmt.bufPrint(&line, "{s}/f.txt\n", .{at})).reply.status);
try testing.expectEqual(@as(usize, 1), p.col_n[p.ncol - 1]);
try testing.expectEqual(p.active, p.col_panes[p.ncol - 1][0]);
}
@@ -2807,7 +2807,7 @@ test "a Restore of a file that is no dump fails the write before any warning, an
const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)];
var line_buf: [4200]u8 = undefined;
const line = try std.fmt.bufPrint(&line_buf, "Restore {s}/notes.txt\n", .{dir});
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
const refused = wr(p, root_ctl, line);
try testing.expectEqual(E.IO, refused.errno());
try testing.expect(std.mem.indexOf(u8, refused.reply.ename, "not a pardes dump: line 1: ") != null);
@@ -2827,7 +2827,7 @@ test "a Restore of a file that is no dump fails the write before any warning, an
test "a setting this frontend cannot show says GUI-only, and DumpDir reads back the directory in effect" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
if (!builtins.capabilities.lift) {
try testing.expectEqualStrings("Lift is GUI-only, invalid here \"Lift\"", wr(p, root_ctl, "Lift on\n").reply.ename);
try testing.expectEqualStrings("GripWidth is GUI-only, invalid here \"GripWidth\"", wr(p, root_ctl, "GripWidth 120\n").reply.ename);
@@ -2852,7 +2852,7 @@ test "a setting this frontend cannot show says GUI-only, and DumpDir reads back
test "Shell refuses a path that is no executable, and bare it goes back to the default" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
const refused = wr(p, root_ctl, "Shell /nonexistent/zzsh\n");
try testing.expectEqual(Status.err, refused.reply.status);
try testing.expect(std.mem.indexOf(u8, refused.reply.ename, "Shell: shell \"/nonexistent/zzsh\" not found") != null);
@@ -2875,9 +2875,9 @@ test "a builtin that fails a ctl write logs only its err, so the same failure ag
defer p.deinit();
p.update(.tick); // the pane's `new` is logged first
while (p.nextEffect()) |_| {}
- const ctl_node = @intFromEnum(tree.TopFile.ctl);
+ const ctl_node = @backingInt(tree.TopFile.ctl);
for (0..3) |_| try testing.expectEqual(Status.err, wr(p, ctl_node, "Unmount zzz\n").reply.status);
- const log = @intFromEnum(tree.TopFile.log);
+ const log = @backingInt(tree.TopFile.log);
const h = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
const text = call(p, .{ .tag = 2, .op = .read, .node = log, .handle = h, .size = 1 << 16 }).bytes;
try testing.expect(std.mem.endsWith(u8, text, "err - ctl: Unmount: no such mount zzz (x3)\n"));
@@ -2915,7 +2915,7 @@ test "Edit's p and = never fail for want of room for +Errors: the text is logged
test "size sets the screen of a session no frontend is attached to, and only of one" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
try testing.expectEqual(E.INVAL, wr(p, root_ctl, "size 120 40\n").errno()); // a frontend's
p.unattended = true;
try testing.expectEqual(Status.ok, wr(p, root_ctl, "size 120 40\n").reply.status);
@@ -2937,7 +2937,7 @@ test "size sets the screen of a session no frontend is attached to, and only of
test "Mount dials its peer and fails, mounting nothing, when none answers; a look through a peer gone says dial failed" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
const dead = "/tmp/pardes-test-no-such-peer.sock";
// A socket path not there is said so; one there that does not answer
// (a directory here) is a dial that failed.
@@ -2955,7 +2955,7 @@ test "Mount dials its peer and fails, mounting nothing, when none answers; a loo
try testing.expectEqualStrings("get: /n/away/f.txt: dial failed: no answer", got.reply.ename);
// Mounted when it answered, gone since: a look through it says so.
try p.fs.mounts.append(p.gpa, .{ .name = try p.gpa.dupe(u8, "gone"), .dial = try p.gpa.dupe(u8, dead) });
- const looked = wr(p, @intFromEnum(tree.TopFile.look), "/n/gone/f.txt\n");
+ const looked = wr(p, @backingInt(tree.TopFile.look), "/n/gone/f.txt\n");
try testing.expect(looked.errno() != 0);
try testing.expect(th.logHas(p, "look: /n/gone/f.txt: dial failed: no answer"));
}
@@ -3005,7 +3005,7 @@ test "Tty in a directory that is not there fails and makes no pane; a shell that
test "a builtin that needs its argument, written bare to an exec, is EINVAL as through ctl" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- for ([_]u64{ root_exec, Node.of(serialOf(p), .exec), @intFromEnum(tree.TopFile.tagexec) }) |node| {
+ for ([_]u64{ root_exec, Node.of(serialOf(p), .exec), @backingInt(tree.TopFile.tagexec) }) |node| {
const refused = wr(p, node, "Mount\n");
try testing.expectEqual(E.INVAL, refused.errno());
try testing.expectEqualStrings("wrong #args in control message \"Mount\"", refused.reply.ename);
@@ -3069,7 +3069,7 @@ test "Grep with no hit says grep: no match and opens nothing, a missing pane dir
test "Unmount of a name not mounted says no such mount, which a mount reads as ENOENT" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const refused = wr(p, @intFromEnum(tree.TopFile.ctl), "Unmount nothere\n");
+ const refused = wr(p, @backingInt(tree.TopFile.ctl), "Unmount nothere\n");
try testing.expectEqual(E.NOENT, refused.errno());
try testing.expectStringStartsWith(refused.reply.ename, "Unmount: no such mount nothere");
}
@@ -3106,7 +3106,7 @@ test "a terminal with text typed at its prompt is never typed into: a look at it
while (p.nextEffect()) |_| {}
var count: usize = 0;
for (p.panes) |slot| count += @intFromBool(slot != null);
- try testing.expectEqual(Status.ok, wr(p, @intFromEnum(tree.TopFile.look), "/tmp\n").reply.status);
+ try testing.expectEqual(Status.ok, wr(p, @backingInt(tree.TopFile.look), "/tmp\n").reply.status);
var typed_into = false;
while (p.nextEffect()) |effect| if (effect == .write and effect.write.pane == term) {
typed_into = true;
@@ -3336,7 +3336,7 @@ test "+Unsaved drops a pane once it has closed" {
const b = try th.newPane(p);
_ = wr(p, Node.of(b, .name), "/tmp/pardes-unsaved-b.txt\n");
_ = wr(p, Node.of(b, .body), "edited\n");
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
try testing.expectEqual(Status.err, wr(p, root_ctl, "Exit\n").reply.status);
var listed: ?*pardes.Pane = null;
for (p.panes) |slot| if (slot) |q| if (q.file) |f| if (f.output) |o| if (o.from == .unsaved) {
@@ -3417,7 +3417,7 @@ test "with no pane at all, the root look opens its file and the root exec runs i
}
};
try Empty.all(p);
- const look_node = @intFromEnum(tree.TopFile.look);
+ const look_node = @backingInt(tree.TopFile.look);
try testing.expectEqual(Status.ok, wr(p, look_node, "f.txt\n").reply.status);
var want: [4200]u8 = undefined;
const path = try std.fmt.bufPrint(&want, "{s}/f.txt", .{session});
@@ -3432,7 +3432,7 @@ test "with no pane at all, the root look opens its file and the root exec runs i
try testing.expectEqual(@as(usize, 0), scratches);
try Empty.all(p);
- try testing.expectEqual(Status.ok, wr(p, @intFromEnum(tree.TopFile.exec), "echo hi\n").reply.status);
+ try testing.expectEqual(Status.ok, wr(p, @backingInt(tree.TopFile.exec), "echo hi\n").reply.status);
const made = p.panes[p.anyPane().?].?;
try testing.expect(made.command != null);
try testing.expectEqualStrings(session, made.cwdSlice());
@@ -3453,7 +3453,7 @@ test "a look at file:3:0 is refused as addr 3:0 is, a column counting from 1" {
test "Kill with a name and nothing running says so and does not fail, as bare Kill does" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const r = wr(p, @intFromEnum(tree.TopFile.ctl), "Kill zzz\n");
+ const r = wr(p, @backingInt(tree.TopFile.ctl), "Kill zzz\n");
try testing.expectEqual(Status.ok, r.reply.status);
try testing.expect(th.logHas(p, "Kill: nothing running"));
}
@@ -3519,7 +3519,7 @@ test "a focus moved over 9P tells the programs that asked for focus reports, as
p.update(.{ .output = .{ .pane = @intCast(shells[1]), .bytes = "\x1b[?1004h" } });
while (p.nextEffect()) |_| {}
var digits: [16]u8 = undefined;
- const moved = wr(p, @intFromEnum(tree.TopFile.focus), try std.fmt.bufPrint(&digits, "{d}\n", .{p.panes[shells[1]].?.serial}));
+ const moved = wr(p, @backingInt(tree.TopFile.focus), try std.fmt.bufPrint(&digits, "{d}\n", .{p.panes[shells[1]].?.serial}));
try testing.expectEqual(Status.ok, moved.reply.status);
try testing.expectEqual(shells[1], p.active);
try testing.expectEqualStrings("\x1b[O\x1b[I", moved.pty_buf[0..moved.pty_len]);
@@ -3536,7 +3536,7 @@ test "a Restore of a name in the DumpDir asks for, and logs, the whole path it r
var buf: [4096]u8 = undefined;
const dir = buf[0..try tmp.dir.realPath(testing.io, &buf)];
try testing.expect(p.settings.dump_dir.set(dir));
- try testing.expectEqual(Status.ok, wr(p, @intFromEnum(tree.TopFile.ctl), "Restore x.dump.zon\n").reply.status);
+ try testing.expectEqual(Status.ok, wr(p, @backingInt(tree.TopFile.ctl), "Restore x.dump.zon\n").reply.status);
var want: [4200]u8 = undefined;
try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{s}/x.dump.zon", .{dir}), p.restore_req.?);
}
@@ -3546,11 +3546,11 @@ test "a line starting with # runs as nothing at an exec or a ctl, silently" {
defer p.deinit();
const serial = serialOf(p);
// The setup's own announcements are made by the first write's update.
- _ = wr(p, @intFromEnum(tree.TopFile.ctl), "# settle\n");
+ _ = wr(p, @backingInt(tree.TopFile.ctl), "# settle\n");
const before = p.next_serial;
const log_before = try pardes.ctlfs.events.freezeLog(p);
defer p.gpa.free(log_before.bytes);
- for ([_]u64{ @intFromEnum(tree.TopFile.exec), Node.of(serial, .exec), @intFromEnum(tree.TopFile.ctl), Node.of(serial, .ctl), Node.ofCol(layout.columnSerial(p, 0), .ctl) }) |node| {
+ for ([_]u64{ @backingInt(tree.TopFile.exec), Node.of(serial, .exec), @backingInt(tree.TopFile.ctl), Node.of(serial, .ctl), Node.ofCol(layout.columnSerial(p, 0), .ctl) }) |node| {
try testing.expectEqual(Status.ok, wr(p, node, "# Platform: tty\n # indented too\n").reply.status);
}
try testing.expectEqual(before, p.next_serial);
@@ -3574,7 +3574,7 @@ test "a builtin that takes no argument, written with one to an exec, is refused
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
const serial = serialOf(p);
- for ([_]u64{ @intFromEnum(tree.TopFile.exec), Node.of(serial, .exec) }) |node| for ([_][]const u8{ "Config extra\n", "DumpConfig extra\n" }) |line| {
+ for ([_]u64{ @backingInt(tree.TopFile.exec), Node.of(serial, .exec) }) |node| for ([_][]const u8{ "Config extra\n", "DumpConfig extra\n" }) |line| {
const r = wr(p, node, line);
try testing.expectEqual(E.INVAL, r.errno());
try testing.expectStringStartsWith(r.reply.ename, "wrong #args in control message");
@@ -3680,7 +3680,7 @@ test "every EINVAL a write gets says why, in its err record too; DEL is a contro
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
const serial = serialOf(p);
- const log = @intFromEnum(tree.TopFile.log);
+ const log = @backingInt(tree.TopFile.log);
const h = call(p, .{ .tag = 1, .op = .open, .node = log, .omode = 2 }).reply.handle;
const Case = struct { node: u64, data: []const u8, words: []const u8, handle: u32 = 0 };
for ([_]Case{
@@ -3703,19 +3703,19 @@ test "/index shows a name as the log does: a newline in it is \\n, a control byt
defer p.deinit();
const term = p.paneBySerial(serialOf(p)).?;
p.setCwd(term, "/tmp/two\nlines\x07\x7f\xc2\x85\xff");
- const index = rd(p, @intFromEnum(tree.TopFile.index), 0, 4096).bytes;
+ const index = rd(p, @backingInt(tree.TopFile.index), 0, 4096).bytes;
// Each byte as itself, so the name decodes to what it is.
try testing.expect(std.mem.indexOf(u8, index, "/tmp/two\\nlines\\x07\\x7f\\xc2\\x85\\xff ") != null);
try testing.expectEqual(@as(usize, 1), std.mem.count(u8, index, "\n"));
try testing.expect(index.len > 0);
- try testing.expectEqual(@as(u64, 0), call(p, .{ .tag = 1, .op = .getattr, .node = @intFromEnum(tree.TopFile.index) }).reply.attr.size);
+ try testing.expectEqual(@as(u64, 0), call(p, .{ .tag = 1, .op = .getattr, .node = @backingInt(tree.TopFile.index) }).reply.attr.size);
// Its tag never carries the raw newline either.
const tag = rd(p, Node.of(serialOf(p), .tag), 0, 4096).bytes;
try testing.expect(std.mem.indexOf(u8, tag, "/tmp/two\\nlines") != null);
// A backslash of the name's own is doubled: `\n` written in a name
// reads back unlike a newline.
p.setCwd(term, "/tmp/back\\nslash");
- try testing.expect(std.mem.indexOf(u8, rd(p, @intFromEnum(tree.TopFile.index), 0, 4096).bytes, "/tmp/back\\\\nslash") != null);
+ try testing.expect(std.mem.indexOf(u8, rd(p, @backingInt(tree.TopFile.index), 0, 4096).bytes, "/tmp/back\\\\nslash") != null);
}
test "a look at a ./ or ../ name that is not there is a miss naming the file; a plain one is looked for as text" {
@@ -3766,7 +3766,7 @@ test "a served-tree pane spoils no Grep, and Look . from a gone directory is ENO
test "a tag write refuses NUL and the other control characters" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- for ([_]u64{ @intFromEnum(tree.TopFile.tag), tree.Node.ofCol(pardes.layout.columnSerial(p, 0), .tag), Node.of(serialOf(p), .tag) }) |node| {
+ for ([_]u64{ @backingInt(tree.TopFile.tag), tree.Node.ofCol(pardes.layout.columnSerial(p, 0), .tag), Node.of(serialOf(p), .tag) }) |node| {
const refused = wr(p, node, " a\x00b");
try testing.expectEqual(E.INVAL, refused.errno());
try testing.expectStringStartsWith(refused.reply.ename, "invalid tag text");
@@ -3815,7 +3815,7 @@ test "a column takes panes until their documented minimums fill it, not until no
const p = try Pardes.init(testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 50 });
defer p.deinit();
while (p.nextEffect()) |_| {}
- const new = @intFromEnum(tree.TopFile.new);
+ const new = @backingInt(tree.TopFile.new);
while (call(p, .{ .tag = 1, .op = .open, .node = new }).reply.status == .ok) p.sync();
p.sync();
const avail = p.screen_h - (p.topBarHeight() + p.columnBarHeight());
@@ -3913,13 +3913,13 @@ test "a closed file is found again: Recent and /recent list it closed, a look at
const opened = p.active;
try testing.expectEqualStrings(a, p.panes[opened].?.file.?.path);
var want: [4300]u8 = undefined;
- try testing.expect(std.mem.indexOf(u8, rd(p, @intFromEnum(tree.TopFile.recent), 0, 8192).bytes, try std.fmt.bufPrint(&want, "open {s}\n", .{a})) != null);
+ try testing.expect(std.mem.indexOf(u8, rd(p, @backingInt(tree.TopFile.recent), 0, 8192).bytes, try std.fmt.bufPrint(&want, "open {s}\n", .{a})) != null);
// Another file, so the jumplist has somewhere to come back from.
try testing.expectEqual(Status.ok, wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/b.txt\n", .{dir})).reply.status);
p.sync();
try testing.expectEqual(Status.ok, wr(p, Node.of(p.panes[opened].?.serial, .ctl), "Del\n").reply.status);
p.sync();
- try testing.expect(std.mem.indexOf(u8, rd(p, @intFromEnum(tree.TopFile.recent), 0, 8192).bytes, try std.fmt.bufPrint(&want, "closed {s}\n", .{a})) != null);
+ try testing.expect(std.mem.indexOf(u8, rd(p, @backingInt(tree.TopFile.recent), 0, 8192).bytes, try std.fmt.bufPrint(&want, "closed {s}\n", .{a})) != null);
// Recent lists it, closed, at its dot; a look at the row opens it there.
try testing.expectEqual(Status.ok, wr(p, root_exec, "Recent\n").reply.status);
const rows = p.panes[p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trimEnd(u8, rd(p, root_exec, 0, 64).bytes, "\n"), 10)).?].?;
@@ -4045,8 +4045,8 @@ test "Back and Forward written to exec keep to the focused file, and JumpScope a
.{ .word = "Forward", .file = "/b.txt", .line = 80 },
.{ .word = "Forward", .file = "/a.txt", .line = 80 },
});
- try testing.expectEqual(Status.ok, wr(p, @intFromEnum(tree.TopFile.ctl), "JumpScope all\n").reply.status);
- try testing.expect(std.mem.indexOf(u8, rd(p, @intFromEnum(tree.TopFile.ctl), 0, 8192).bytes, "JumpScope all\n") != null);
+ try testing.expectEqual(Status.ok, wr(p, @backingInt(tree.TopFile.ctl), "JumpScope all\n").reply.status);
+ try testing.expect(std.mem.indexOf(u8, rd(p, @backingInt(tree.TopFile.ctl), 0, 8192).bytes, "JumpScope all\n") != null);
try walk(p, &.{
.{ .word = "Back", .file = "/b.txt", .line = 80 },
.{ .word = "Back", .file = "/a.txt", .line = 40 },
@@ -4102,14 +4102,14 @@ test "a new file saved shows in /recent, open, while it is" {
try testing.expectEqual(Status.ok, wr(p, Node.of(made, .ctl), "Save\n").reply.status);
p.perform(.{ .save_file = .{ .pane = @intCast(p.paneBySerial(made).?) } });
var want: [4300]u8 = undefined;
- try testing.expect(std.mem.indexOf(u8, rd(p, @intFromEnum(tree.TopFile.recent), 0, 8192).bytes, try std.fmt.bufPrint(&want, "open {s}\n", .{path})) != null);
+ try testing.expect(std.mem.indexOf(u8, rd(p, @backingInt(tree.TopFile.recent), 0, 8192).bytes, try std.fmt.bufPrint(&want, "open {s}\n", .{path})) != null);
}
test "/recent shows a name as /index does, a newline in it escaped" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
p.recent.opened(p.recentGpa(), "/tmp/a\nb\\c");
- const text = rd(p, @intFromEnum(tree.TopFile.recent), 0, 8192).bytes;
+ const text = rd(p, @backingInt(tree.TopFile.recent), 0, 8192).bytes;
try testing.expect(std.mem.indexOf(u8, text, "closed /tmp/a\\nb\\\\c\n") != null);
}
@@ -4191,8 +4191,8 @@ test "size is monotonic: growing is never refused, and a size once taken is take
defer p.deinit();
while (p.nextEffect()) |_| {}
p.unattended = true;
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
- const new = @intFromEnum(tree.TopFile.new);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
+ const new = @backingInt(tree.TopFile.new);
// The dogfood's repro: Newcol, three pane/new, a Tty, then pane/new
// until a column has no room (ENOSPC).
try testing.expectEqual(Status.ok, wr(p, root_ctl, "Newcol\n").reply.status);
@@ -4283,7 +4283,7 @@ test "a file changed on disk under unsaved edits is not reloaded: it says so, ge
var want: [32]u8 = undefined;
try testing.expect(th.logHas(p, try std.fmt.bufPrint(&want, "changed {d}\n", .{serial})));
// Exit and get still ask about the edits.
- try testing.expectEqual(Status.err, wr(p, @intFromEnum(tree.TopFile.ctl), "Exit\n").reply.status);
+ try testing.expectEqual(Status.err, wr(p, @backingInt(tree.TopFile.ctl), "Exit\n").reply.status);
try testing.expect(std.mem.indexOf(u8, wr(p, Node.of(serial, .ctl), "get\n").reply.ename, "Modified") != null);
// Save warns once before overwriting the newer file, then writes.
const first = wr(p, Node.of(serial, .ctl), "Save\n");
@@ -4328,7 +4328,7 @@ test "a looked word is found in its own pane, next place after the dot, wrapping
test "every word's /commands description is its own doc comment's first sentence, no citation" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const listed = rd(p, @intFromEnum(tree.TopFile.commands), 0, 1 << 16).bytes;
+ const listed = rd(p, @backingInt(tree.TopFile.commands), 0, 1 << 16).bytes;
for ([_][]const u8{
"\nRepl arg pane -- Binds this terminal as a language's REPL, so an exec on that language's files is typed into it instead of run.\n",
"\nJoincol root -- Fold the active pane's column into the one on its right, keeping its panes.\n",
@@ -4374,7 +4374,7 @@ test "Newcol at the column cap fails the write and says the cap" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
p.update(.{ .resize = .{ .cols = 4000, .rows = 30 } });
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
while (p.ncol < pardes.MAX_COLS) {
// From the widest column's tag, so no column gets too narrow first.
p.sync();
@@ -4403,7 +4403,7 @@ test "Save on a terminal asked over 9P is an ask in the log, answered with a pat
try testing.expect(p.panes[id].?.prompt == .save);
// Again: the one open stands, one ask in the log.
_ = wr(p, Node.of(serial, .tagexec), "Save\n");
- const log = @intFromEnum(tree.TopFile.log);
+ const log = @backingInt(tree.TopFile.log);
const h = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
try testing.expectEqual(@as(usize, 1), std.mem.count(u8, call(p, .{ .tag = 2, .op = .read, .node = log, .handle = h, .size = 1 << 16 }).bytes, "save path\n"));
_ = call(p, .{ .tag = 3, .op = .release, .node = log, .handle = h });
@@ -4429,7 +4429,7 @@ test "get names the path it could not read, logs the edits it threw away, and a
pardes.panes.File.deleted(p, 0);
pardes.panes.File.deleted(p, 0);
var rec: [32]u8 = undefined;
- const log = @intFromEnum(tree.TopFile.log);
+ const log = @backingInt(tree.TopFile.log);
const h = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
try testing.expectEqual(@as(usize, 1), std.mem.count(u8, call(p, .{ .tag = 2, .op = .read, .node = log, .handle = h, .size = 1 << 16 }).bytes, try std.fmt.bufPrint(&rec, "changed {d} deleted\n", .{serial})));
_ = call(p, .{ .tag = 3, .op = .release, .node = log, .handle = h });
@@ -4441,12 +4441,12 @@ test "a builtin that fails through exec, tagexec or a column's exec fails the wr
p.update(.tick); // the pane's `new` is logged first
while (p.nextEffect()) |_| {}
const serial = serialOf(p);
- for ([_]u64{ root_exec, Node.of(serial, .exec), @intFromEnum(tree.TopFile.tagexec), Node.ofCol(pardes.layout.columnSerial(p, 0), .exec) }) |node| {
+ for ([_]u64{ root_exec, Node.of(serial, .exec), @backingInt(tree.TopFile.tagexec), Node.ofCol(pardes.layout.columnSerial(p, 0), .exec) }) |node| {
const failed = wr(p, node, "Unmount zzz\n");
try testing.expectEqual(Status.err, failed.reply.status);
try testing.expect(std.mem.indexOf(u8, failed.reply.ename, "Unmount: no such mount zzz") != null);
}
- const log = @intFromEnum(tree.TopFile.log);
+ const log = @backingInt(tree.TopFile.log);
const h = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
const text = call(p, .{ .tag = 2, .op = .read, .node = log, .handle = h, .size = 1 << 16 }).bytes;
try testing.expect(std.mem.indexOf(u8, text, "msg ") == null);
@@ -4458,11 +4458,11 @@ test "a builtin that fails through exec, tagexec or a column's exec fails the wr
// A control character is refused with its reason.
try testing.expectEqualStrings(e_control, wr(p, root_exec, "Msg a\x01b\n").reply.ename);
// A look miss: one err, no msg.
- _ = wr(p, @intFromEnum(tree.TopFile.look), "zzqqnotthere\n");
+ _ = wr(p, @backingInt(tree.TopFile.look), "zzqqnotthere\n");
try testing.expect(th.logHas(p, "look: no match for \"zzqqnotthere\""));
try testing.expect(!th.logHas(p, "msg 1 Look: no match"));
// The same miss again is that record counted, as any repeated err is.
- _ = wr(p, @intFromEnum(tree.TopFile.look), "zzqqnotthere\n");
+ _ = wr(p, @backingInt(tree.TopFile.look), "zzqqnotthere\n");
try testing.expect(th.logHas(p, "look: no match for \"zzqqnotthere\" (x2)\n"));
}
@@ -4483,7 +4483,7 @@ test "@p<serial>:<address> takes any sam address; a miss and an unknown serial a
const p = try withFile(testing.allocator, "foo x foo y\nbar\n");
defer p.deinit();
const serial = serialOf(p);
- const root = @intFromEnum(tree.TopFile.look);
+ const root = @backingInt(tree.TopFile.look);
const dot = Node.of(serial, .dot);
const Case = struct { addr: []const u8, want: []const u8 };
for ([_]Case{
@@ -4544,7 +4544,7 @@ test "@p<terminal>:<address> takes any address over the terminal's lines, select
const id = p.paneBySerial(serial).?;
p.update(.{ .output = .{ .pane = @intCast(id), .bytes = "one\r\ntwo MARK three\r\n" } });
const pane = p.panes[id].?;
- const root = @intFromEnum(tree.TopFile.look);
+ const root = @backingInt(tree.TopFile.look);
var line: [64]u8 = undefined;
try testing.expectEqual(Status.ok, wr(p, root, try std.fmt.bufPrint(&line, "@p{d}:0/MARK/\n", .{serial})).reply.status);
try testing.expectEqual(@as(i32, 1), pane.body.cur_row);
@@ -4576,7 +4576,7 @@ test "a bad command inside an Edit block written whole is named, not the } after
test "a refused Delcol changes nothing: no pane, no focus" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- _ = wr(p, @intFromEnum(tree.TopFile.ctl), "Newcol\n");
+ _ = wr(p, @backingInt(tree.TopFile.ctl), "Newcol\n");
const made = try th.newPane(p);
_ = wr(p, Node.of(made, .name), "/tmp/pardes-delcol-refused.txt\n");
_ = wr(p, Node.of(made, .body), "edit\n");
@@ -4599,8 +4599,8 @@ test "a refused Delcol changes nothing: no pane, no focus" {
test "pager answers its +Pager on the open that asked, whatever another client exec'd meanwhile" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const pager = @intFromEnum(tree.TopFile.pager);
- const exec = @intFromEnum(tree.TopFile.exec);
+ const pager = @backingInt(tree.TopFile.pager);
+ const exec = @backingInt(tree.TopFile.exec);
const asked = call(p, .{ .tag = 1, .op = .open, .node = pager, .omode = 2 }).reply.handle;
try testing.expectEqual(Status.ok, call(p, .{ .tag = 2, .op = .write, .node = pager, .handle = asked, .data = "/tmp\n" }).reply.status);
const paged = for (p.panes) |slot| {
@@ -4653,7 +4653,7 @@ test "pager answers its +Pager on the open that asked, whatever another client e
test "what a /pager open writes after its directory is the text: plain in the body, its colours the pane's, clean, in by the read" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const pager = @intFromEnum(tree.TopFile.pager);
+ const pager = @backingInt(tree.TopFile.pager);
const asked = call(p, .{ .tag = 1, .op = .open, .node = pager, .omode = 2 }).reply.handle;
// The directory and the text's start in one write, escapes and all, a
// second line no directory; the rest in writes after it.
@@ -4812,7 +4812,7 @@ test "a second LookWord list look in a directory refills its +Search rather than
const path = try std.fmt.bufPrint(&path_buf, "{s}/words.txt", .{dir});
const p = try Pardes.init(gpa, .{ .file = path, .tty_only = true, .cols = 80, .rows = 30 });
defer p.deinit();
- _ = wr(p, @intFromEnum(tree.TopFile.ctl), "LookWord list\n");
+ _ = wr(p, @backingInt(tree.TopFile.ctl), "LookWord list\n");
pardes.look.lookAt(p, 0, "alpha");
pardes.look.lookAt(p, 0, "beta");
var searches: usize = 0;
@@ -4986,7 +4986,7 @@ test "DumpDir refuses a relative directory and one that may not be written, up f
if (comptime !pardes.hosted) return;
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
try testing.expectEqual(E.INVAL, wr(p, root_ctl, "DumpDir dumps\n").errno());
try testing.expectEqual(E.INVAL, wr(p, root_ctl, "DumpDir /proc/1/root/dumps\n").errno());
try testing.expectEqual(Status.ok, wr(p, root_ctl, "DumpDir /tmp/pardes-dumps-test\n").reply.status);
@@ -4998,7 +4998,7 @@ test "DumpDir refuses a relative directory and one that may not be written, up f
test "a Mount dial with a network it does not know is a bad dial address, EINVAL" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const r = wr(p, @intFromEnum(tree.TopFile.ctl), "Mount peer nowhere!x\n");
+ const r = wr(p, @backingInt(tree.TopFile.ctl), "Mount peer nowhere!x\n");
try testing.expectEqual(E.INVAL, r.errno());
try testing.expectStringStartsWith(r.reply.ename, "Mount: bad dial address: nowhere!x");
}
@@ -5056,11 +5056,11 @@ test "a Mount of a socket path that is not there says no such socket, ENOENT" {
if (comptime !pardes.hosted) return;
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const r = wr(p, @intFromEnum(tree.TopFile.ctl), "Mount peer unix!/tmp/pardes-surely-no-socket\n");
+ const r = wr(p, @backingInt(tree.TopFile.ctl), "Mount peer unix!/tmp/pardes-surely-no-socket\n");
try testing.expectEqual(E.NOENT, r.errno());
try testing.expect(std.mem.indexOf(u8, r.reply.ename, "no such socket") != null);
try testing.expectEqual(@as(usize, 0), p.fs.mounts.items.len);
- try testing.expectEqual(E.INVAL, wr(p, @intFromEnum(tree.TopFile.ctl), "Mount peer rel/x.sock\n").errno());
+ try testing.expectEqual(E.INVAL, wr(p, @backingInt(tree.TopFile.ctl), "Mount peer rel/x.sock\n").errno());
}
test "the init file reads past a BOM, and every line it fails is a notice and an err, never silent" {
diff --git a/src/ninep/events.zig b/src/ninep/events.zig
index 7b73dc0e..78788c3c 100644
--- a/src/ninep/events.zig
+++ b/src/ninep/events.zig
@@ -542,7 +542,7 @@ pub const Action = enum(u8) {
tag_exec = 'x',
pub fn char(a: Action) u8 {
- return @intFromEnum(a);
+ return @backingInt(a);
}
pub fn fromChar(c: u8) ?Action {
@@ -550,7 +550,7 @@ pub const Action = enum(u8) {
}
pub fn onTag(a: Action) bool {
- return @intFromEnum(a) >= 'a';
+ return @backingInt(a) >= 'a';
}
};
@@ -889,7 +889,7 @@ test "a stream read at an offset inside its last answer gets the rest of it agai
defer p.deinit();
p.update(.tick);
while (p.nextEffect()) |_| {}
- const log = @intFromEnum(tree.TopFile.log);
+ const log = @backingInt(tree.TopFile.log);
const f = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
const frozen: u64 = call(p, .{ .tag = 2, .op = .read, .node = log, .handle = f, .size = 8192 }).bytes.len;
_ = call(p, .{ .tag = 3, .op = .write, .node = log, .handle = f, .data = "follow" });
@@ -897,7 +897,7 @@ test "a stream read at an offset inside its last answer gets the rest of it agai
notePath(p, "dump", "/b");
const Read = struct {
fn at(pp: *Pardes, h: u32, off: u64) []const u8 {
- return call(pp, .{ .tag = 4, .op = .read, .node = @intFromEnum(tree.TopFile.log), .handle = h, .off = off, .size = 128 }).bytes;
+ return call(pp, .{ .tag = 4, .op = .read, .node = @backingInt(tree.TopFile.log), .handle = h, .off = off, .size = 128 }).bytes;
}
};
try testing.expectEqualStrings("dump /a\n", Read.at(p, f, frozen));
@@ -1130,7 +1130,7 @@ test "writing an event record back performs the action it names" {
// A look written back sets what look reads back.
_ = wr(p, event, "FL0 3\n");
var want_serial: [16]u8 = undefined;
- try testing.expectEqualStrings(try std.fmt.bufPrint(&want_serial, "{d}\n", .{serial}), rd(p, @intFromEnum(tree.TopFile.look), 0, 64).bytes);
+ try testing.expectEqualStrings(try std.fmt.bufPrint(&want_serial, "{d}\n", .{serial}), rd(p, @backingInt(tree.TopFile.look), 0, 64).bytes);
// Well formed but past the text: said so, not "bad event syntax".
try testing.expectEqualStrings("range past end of body", wr(p, event, "MX0 999\n").reply.ename);
@@ -1144,7 +1144,7 @@ test "the log records whether or not anyone reads, and an open that follows wait
const gpa = testing.allocator;
const p = try withFile(gpa, "logged\n");
defer p.deinit();
- const log = @intFromEnum(tree.TopFile.log);
+ const log = @backingInt(tree.TopFile.log);
var expected: [4200]u8 = undefined;
// Nobody holds /log open, and the pane is recorded anyway.
@@ -1256,21 +1256,21 @@ test "a refused or failed write is an err record in the log, saying which file a
p.update(.tick); // the pane's `new` is logged before the log is opened
while (p.nextEffect()) |_| {}
const serial = serialOf(p);
- const log = @intFromEnum(tree.TopFile.log);
+ const log = @backingInt(tree.TopFile.log);
const f = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
const frozen = call(p, .{ .tag = 2, .op = .read, .node = log, .handle = f, .size = 1 << 16 }).bytes.len;
_ = call(p, .{ .tag = 3, .op = .write, .node = log, .handle = f, .data = "follow" });
var want: [128]u8 = undefined;
const next = struct {
fn record(pp: *Pardes, h: u32, off: usize) []const u8 {
- return call(pp, .{ .tag = 4, .op = .read, .node = @intFromEnum(tree.TopFile.log), .handle = h, .off = off, .size = 4096 }).bytes;
+ return call(pp, .{ .tag = 4, .op = .read, .node = @backingInt(tree.TopFile.log), .handle = h, .off = off, .size = 4096 }).bytes;
}
};
_ = wr(p, Node.of(serial, .addr), "/nowhere/");
try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "err {d} addr: no match for regexp\n", .{serial}), next.record(p, f, frozen));
- _ = wr(p, @intFromEnum(tree.TopFile.ctl), "Bogus");
+ _ = wr(p, @backingInt(tree.TopFile.ctl), "Bogus");
try testing.expectEqualStrings("err - ctl: unknown control message \"Bogus\"\n", next.record(p, f, frozen));
- _ = wr(p, @intFromEnum(tree.TopFile.focus), "99999");
+ _ = wr(p, @backingInt(tree.TopFile.focus), "99999");
try testing.expectEqualStrings("err - focus: no such pane\n", next.record(p, f, frozen));
// A write that succeeds says nothing.
_ = wr(p, Node.of(serial, .addr), "#0");
@@ -1373,7 +1373,7 @@ test "opens of the log share the open records, and a closed one frees its record
const gpa = testing.allocator;
const p = try withFile(gpa, "x\n");
defer p.deinit();
- const log = @intFromEnum(tree.TopFile.log);
+ const log = @backingInt(tree.TopFile.log);
var handles: [tree.open_slots]u32 = undefined;
for (&handles) |*h| h.* = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
try testing.expectEqual(E.NFILE, call(p, .{ .tag = 2, .op = .open, .node = log }).errno());
@@ -1447,7 +1447,7 @@ test "follow new skips what the log held and waits for what comes after" {
p.update(.tick); // the pane's `new` is logged first
while (p.nextEffect()) |_| {}
p.setMessage(0, "before the open");
- const log = @intFromEnum(tree.TopFile.log);
+ const log = @backingInt(tree.TopFile.log);
const h = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
try testing.expectEqual(Status.ok, call(p, .{ .tag = 2, .op = .write, .node = log, .handle = h, .data = "follow new\n" }).reply.status);
try testing.expectEqual(Status.again, call(p, .{ .tag = 3, .op = .read, .node = log, .handle = h, .size = 4096 }).reply.status);
@@ -1461,7 +1461,7 @@ test "a long msg record is cut between words at its cap, with an ellipsis" {
defer p.deinit();
const long = std.mem.asBytes(&@as([60][5]u8, @splat("word ".*))); // 300 bytes
_ = wr(p, Node.of(serialOf(p), .ctl), "Msg " ++ long ++ "\n");
- const log = @intFromEnum(tree.TopFile.log);
+ const log = @backingInt(tree.TopFile.log);
const h = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
const text = call(p, .{ .tag = 2, .op = .read, .node = log, .handle = h, .size = 1 << 16 }).bytes;
const at = std.mem.lastIndexOf(u8, text, "msg ").?;
@@ -1485,8 +1485,8 @@ test "a record is one line of UTF-8: DEL and C1 are spaces, bytes not UTF-8 are
test "a long err record keeps its end, its middle given up to an ellipsis" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- _ = wr(p, @intFromEnum(tree.TopFile.ctl), "Bogus" ++ std.mem.asBytes(&@as([40][8]u8, @splat("abcdefgh".*))) ++ "\n");
- const log = @intFromEnum(tree.TopFile.log);
+ _ = wr(p, @backingInt(tree.TopFile.ctl), "Bogus" ++ std.mem.asBytes(&@as([40][8]u8, @splat("abcdefgh".*))) ++ "\n");
+ const log = @backingInt(tree.TopFile.log);
const h = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
const text = call(p, .{ .tag = 2, .op = .read, .node = log, .handle = h, .size = 1 << 16 }).bytes;
const at = std.mem.lastIndexOf(u8, text, "err - ctl: ").?;
diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig
index 8605cab8..dc104e4b 100644
--- a/src/ninep/pane.zig
+++ b/src/ninep/pane.zig
@@ -1104,7 +1104,7 @@ test "index lists serial kind dirty flag and name, and stats 0, a view generated
const p = try withFile(gpa, "hello\nthere\n");
defer p.deinit();
const pane = p.panes[0].?;
- const index = @intFromEnum(tree.TopFile.index);
+ const index = @backingInt(tree.TopFile.index);
const a = rd(p, index, 0, 4096);
try testing.expectEqual(Status.ok, a.reply.status);
@@ -1138,7 +1138,7 @@ test "a terminal is listed as term with its directory as name" {
var want: [64]u8 = undefined;
try testing.expect(std.mem.indexOf(
u8,
- rd(p, @intFromEnum(tree.TopFile.index), 0, 4096).bytes,
+ rd(p, @backingInt(tree.TopFile.index), 0, 4096).bytes,
try std.fmt.bufPrint(&want, "{d} term 0 /work/dir {d}\n", .{ pane.serial, columnOf(p, 0) }),
) != null);
try testing.expectEqualStrings("/work/dir\n", rd(p, Node.of(pane.serial, .name), 0, 4096).bytes);
@@ -1751,8 +1751,8 @@ test "name refreshes cached syntax for unchanged contents" {
try testing.expectEqual(Status.ok, wr(p, Node.of(pane.serial, .name), "renamed.zig\n").reply.status);
panes.File.refreshHighlights(p);
try testing.expect(pane.file.?.highlights.len >= 2);
- try testing.expectEqual(@intFromEnum(pardes.syntax.Syn.keyword), pane.file.?.highlights[0]);
- try testing.expectEqual(@intFromEnum(pardes.syntax.Syn.keyword), pane.file.?.highlights[1]);
+ try testing.expectEqual(@backingInt(pardes.syntax.Syn.keyword), pane.file.?.highlights[0]);
+ try testing.expectEqual(@backingInt(pardes.syntax.Syn.keyword), pane.file.?.highlights[1]);
try testing.expectEqualStrings("fn check() void {}\n", pane.file.?.content);
}
diff --git a/src/ninep/pty.zig b/src/ninep/pty.zig
index aeb57a00..d80f7175 100644
--- a/src/ninep/pty.zig
+++ b/src/ninep/pty.zig
@@ -893,7 +893,7 @@ test "a shell that exits under a run answers its status, and the log says exit b
const prompt = "\x1b]133;A;cl=line;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07";
p.update(.{ .output = .{ .pane = 0, .bytes = prompt } });
while (p.nextEffect()) |_| {}
- const log = @intFromEnum(tree.TopFile.log);
+ const log = @backingInt(tree.TopFile.log);
const f = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
const frozen = call(p, .{ .tag = 2, .op = .read, .node = log, .handle = f, .size = 1 << 16 }).bytes.len;
_ = call(p, .{ .tag = 3, .op = .write, .node = log, .handle = f, .data = "follow" });
@@ -984,7 +984,6 @@ test "a run's answer says cut when its output's start is gone, and reads a bound
var got = sh.answered(p, node, h, into);
try testing.expectEqualStrings("exit 0\nafter\n", got);
-
// A resize between its start and end reflows the pins with the text.
h = sh.send(p, node);
sh.put(p, c ++ "one\r\ntwo\r\n");
@@ -1092,7 +1091,7 @@ test "a terminal's ctl counts its body, and a new directory is a rename in the l
_ = fields.next();
try testing.expectEqual(body_len, try std.fmt.parseInt(usize, fields.next().?, 10));
- const log = @intFromEnum(tree.TopFile.log);
+ const log = @backingInt(tree.TopFile.log);
const f = call(p, .{ .tag = 4, .op = .open, .node = log }).reply.handle;
const frozen = call(p, .{ .tag = 5, .op = .read, .node = log, .handle = f, .size = 1 << 16 }).bytes.len;
_ = call(p, .{ .tag = 6, .op = .write, .node = log, .handle = f, .data = "follow" });
diff --git a/src/ninep/screen.zig b/src/ninep/screen.zig
index 8d4707e0..ba676ded 100644
--- a/src/ninep/screen.zig
+++ b/src/ninep/screen.zig
@@ -95,7 +95,7 @@ const withTerm = th.withTerm;
const serialOf = th.serialOf;
const Node = tree.Node;
const Status = tree.Status;
-const screen_node = @intFromEnum(tree.TopFile.screen);
+const screen_node = @backingInt(tree.TopFile.screen);
test "listener addresses are readable canonical dials with bounded partial reads" {
const gpa = testing.allocator;
@@ -111,7 +111,7 @@ test "listener addresses are readable canonical dials with bounded partial reads
try testing.expectEqualStrings(expected, bytes);
try testing.expectError(error.ReadOnlyFilesystem, fs.write(p, path, ""));
}
- const node = @intFromEnum(tree.TopFile.listeners);
+ const node = @backingInt(tree.TopFile.listeners);
var off: usize = 0;
while (off < expected.len) {
const part = rd(p, node, off, 3);
diff --git a/src/ninep/testing.zig b/src/ninep/testing.zig
index a35a9cf0..ec665130 100644
--- a/src/ninep/testing.zig
+++ b/src/ninep/testing.zig
@@ -71,7 +71,7 @@ pub fn logHas(p: *Pardes, needle: []const u8) bool {
/// How many times the log, read whole from a fresh open, holds `needle`.
pub fn logCount(p: *Pardes, needle: []const u8) usize {
- const log = @intFromEnum(tree.TopFile.log);
+ const log = @backingInt(tree.TopFile.log);
const h = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
defer _ = call(p, .{ .tag = 3, .op = .release, .node = log, .handle = h });
const text = call(p, .{ .tag = 2, .op = .read, .node = log, .handle = h, .size = 1 << 16 }).bytes;
@@ -95,7 +95,7 @@ pub fn look_up(p: *Pardes, dir: u64, name: []const u8) Answer {
/// The open is what makes the pane; the handle it answers is the serial, which
/// is also what a read of that fid reports.
pub fn newPane(p: *Pardes) !u32 {
- const made = call(p, .{ .tag = 8, .op = .open, .node = @intFromEnum(tree.TopFile.new) });
+ const made = call(p, .{ .tag = 8, .op = .open, .node = @backingInt(tree.TopFile.new) });
if (made.reply.status != .ok or made.reply.handle == 0) return error.NoPane;
return made.reply.handle;
}
diff --git a/src/ninep/tree.zig b/src/ninep/tree.zig
index 5678832b..9aa0225a 100644
--- a/src/ninep/tree.zig
+++ b/src/ninep/tree.zig
@@ -115,7 +115,7 @@ pub fn changesPane(p: *Pardes, req: Req) bool {
return switch (req.op) {
.write => true,
.setattr => truncates(req),
- .open => req.node == @intFromEnum(TopFile.new),
+ .open => req.node == @backingInt(TopFile.new),
.release => req.remove or holdsLines(p, req) or holdsPage(p, req),
.read => holdsPage(p, req),
.lookup, .getattr, .readdir => false,
@@ -279,7 +279,7 @@ pub const TopFile = enum(u5) {
}
};
-pub const root: u64 = @intFromEnum(TopFile.root);
+pub const root: u64 = @backingInt(TopFile.root);
/// Declaration order is readdir order.
pub const PaneFile = enum(u5) {
@@ -363,11 +363,11 @@ pub const Node = packed struct(u64) {
pub fn of(serial: u32, file: PaneFile) u64 {
std.debug.assert(serial != 0);
- return @bitCast(Node{ .file = @intFromEnum(file), .serial = serial });
+ return @bitCast(Node{ .file = @backingInt(file), .serial = serial });
}
pub fn ofCol(serial: u32, file: ColFile) u64 {
- return @bitCast(Node{ .file = @intFromEnum(file), .serial = col_bit | @as(u59, serial) });
+ return @bitCast(Node{ .file = @backingInt(file), .serial = col_bit | @as(u59, serial) });
}
pub fn target(node: u64) ?Target {
@@ -424,9 +424,9 @@ pub fn resolveSelf(p: *Pardes, path: []const u8) ?u64 {
// `new` is reached in /pane, where the panes it makes are.
const top = std.meta.stringToEnum(TopFile, first) orelse return sources.node(normalized);
if (top == .root or top == .new or top == .pane or parts.next() != null) return null;
- return @intFromEnum(top);
+ return @backingInt(top);
}
- const next = parts.next() orelse return @intFromEnum(TopFile.pane);
+ const next = parts.next() orelse return @backingInt(TopFile.pane);
// `new` is served on the wire but deliberately unreachable from an editor
// path: this resolves Look targets and hover previews, and a preview that
// opened `new` to see what was there would make a pane per hover.
@@ -606,7 +606,7 @@ fn attrOf(p: *Pardes, target: Target) ?Reply.Attr {
switch (target) {
.top => |f| return .{
.name = f.fileName(),
- .node = @intFromEnum(f),
+ .node = @backingInt(f),
.dir = f.dir(),
.mode = f.mode(),
.size = topSize(p, f),
@@ -695,11 +695,11 @@ fn lookup(p: *Pardes, req: Req, target: Target) Reply {
const parent: u64 = switch (target) {
.top => |top| if (top.dir()) root else return Reply.fail(req.tag, E.NOTDIR),
.pane => |t| switch (t.file) {
- .dir => @intFromEnum(TopFile.pane),
+ .dir => @backingInt(TopFile.pane),
.pty => Node.of(t.serial, .dir),
else => return Reply.fail(req.tag, E.NOTDIR),
},
- .col => |c| if (c.file == .dir) @intFromEnum(TopFile.col) else return Reply.fail(req.tag, E.NOTDIR),
+ .col => |c| if (c.file == .dir) @backingInt(TopFile.col) else return Reply.fail(req.tag, E.NOTDIR),
};
return handle(p, .{ .tag = req.tag, .op = .getattr, .node = parent });
}
@@ -709,12 +709,12 @@ fn lookup(p: *Pardes, req: Req, target: Target) Reply {
.root => root: {
if (std.mem.eql(u8, name, "os")) return fs.osHandle(p, .{ .tag = req.tag, .op = .getattr, .node = fs.os_root });
// `new` is reached in /pane, where the panes it makes are.
- if (std.meta.stringToEnum(TopFile, name)) |t| if (t != .root and t != .new) break :root @intFromEnum(t);
+ if (std.meta.stringToEnum(TopFile, name)) |t| if (t != .root and t != .new) break :root @backingInt(t);
if (sources.node(name)) |n| return sources.handle(p, .{ .tag = req.tag, .op = .getattr, .node = n });
return Reply.fail(req.tag, E.NOENT);
},
.pane => pane: {
- if (std.mem.eql(u8, name, new_pane)) break :pane @intFromEnum(TopFile.new);
+ if (std.mem.eql(u8, name, new_pane)) break :pane @backingInt(TopFile.new);
// A pane directory is its serial, in decimal digits and never 0.
if (name.len > 10) return Reply.fail(req.tag, E.NOENT);
for (name) |c| if (c < '0' or c > '9') return Reply.fail(req.tag, E.NOENT);
@@ -778,13 +778,13 @@ fn readdir(p: *Pardes, req: Req, target: Target) Reply {
// The guide, then what describes the session, then the
// files that act, then the directories.
inline for (.{ TopFile.README, TopFile.index, TopFile.status, TopFile.focus, TopFile.ctl, TopFile.commands, TopFile.recent, TopFile.look, TopFile.exec, TopFile.pager, TopFile.log, TopFile.screen, TopFile.listeners, TopFile.layout, TopFile.tag, TopFile.tagexec, TopFile.pane, TopFile.col }) |t| {
- if (skip > 0) skip -= 1 else stageDirent(out, p.gpa, @intFromEnum(t), t.dir(), t.fileName());
+ if (skip > 0) skip -= 1 else stageDirent(out, p.gpa, @backingInt(t), t.dir(), t.fileName());
}
if (skip > 0) skip -= 1 else stageDirent(out, p.gpa, fs.os_root, true, "os");
sources.stage(p, out, "", &skip);
},
.pane => {
- if (skip > 0) skip -= 1 else stageDirent(out, p.gpa, @intFromEnum(TopFile.new), false, TopFile.new.fileName());
+ if (skip > 0) skip -= 1 else stageDirent(out, p.gpa, @backingInt(TopFile.new), false, TopFile.new.fileName());
var last: u32 = 0;
while (nextSerialAfter(p, last)) |serial| {
last = serial;
@@ -1378,7 +1378,7 @@ test "a listing read in chunks is what it was at the open, however the panes cha
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
for ([_]TopFile{ .index, .layout, .recent, .ctl }) |file| {
- const node = @intFromEnum(file);
+ const node = @backingInt(file);
const whole = try testing.allocator.dupe(u8, th.rd(p, node, 0, 1 << 16).bytes);
defer testing.allocator.free(whole);
const h = th.call(p, .{ .tag = 1, .op = .open, .node = node }).reply.handle;
@@ -1389,7 +1389,7 @@ test "a listing read in chunks is what it was at the open, however the panes cha
// Something changes between the chunks.
const made = try th.newPane(p);
_ = th.wr(p, Node.of(made, .name), "/tmp/pardes-frozen-listing.txt\n");
- _ = th.wr(p, @intFromEnum(TopFile.ctl), "Verbose off\n");
+ _ = th.wr(p, @backingInt(TopFile.ctl), "Verbose off\n");
while (true) {
const more = th.call(p, .{ .tag = 2, .op = .read, .node = node, .handle = h, .off = got.items.len, .size = 7 }).bytes;
if (more.len == 0) break;
@@ -1397,7 +1397,7 @@ test "a listing read in chunks is what it was at the open, however the panes cha
}
_ = th.call(p, .{ .tag = 3, .op = .release, .node = node, .handle = h, .opened = true });
try testing.expectEqualStrings(whole, got.items);
- _ = th.wr(p, @intFromEnum(TopFile.ctl), "Verbose on\n");
+ _ = th.wr(p, @backingInt(TopFile.ctl), "Verbose on\n");
}
}
@@ -1418,7 +1418,7 @@ test "filesystem inspection preserves pending and displayed Look hover" {
} });
try testing.expect(p.look_hover_wait != null);
const body = Node.of(serialOf(p), .body);
- const screen_node = @intFromEnum(TopFile.screen);
+ const screen_node = @backingInt(TopFile.screen);
for (0..2) |phase| {
if (phase == 1) {
for (0..delay) |_| p.update(.tick);
@@ -1429,7 +1429,7 @@ test "filesystem inspection preserves pending and displayed Look hover" {
const requests = [_]Req{
.{ .tag = 1, .op = .lookup, .node = root, .data = "screen" },
.{ .tag = 1, .op = .lookup, .node = root, .data = "status" },
- .{ .tag = 1, .op = .getattr, .node = @intFromEnum(TopFile.pane) },
+ .{ .tag = 1, .op = .getattr, .node = @backingInt(TopFile.pane) },
.{ .tag = 2, .op = .getattr, .node = body },
.{ .tag = 3, .op = .open, .node = body },
.{ .tag = 4, .op = .read, .node = body, .size = 5 },
@@ -1458,14 +1458,14 @@ test "log stats 0 however much it holds, a stream as acme's generated files are"
defer p.deinit();
_ = th.wr(p, Node.of(th.serialOf(p), .exec), "Msg a record for the log\n");
try testing.expect(th.logHas(p, "a record for the log"));
- try testing.expectEqual(@as(u64, 0), call(p, .{ .tag = 1, .op = .getattr, .node = @intFromEnum(TopFile.log) }).reply.attr.size);
+ try testing.expectEqual(@as(u64, 0), call(p, .{ .tag = 1, .op = .getattr, .node = @backingInt(TopFile.log) }).reply.attr.size);
}
test "filesystem pane creation and truncation cancel Look hover" {
const requests = [_]Req{
// Opening `new` is what makes a pane now; walking to it makes none,
// and so must leave a pending hover alone.
- .{ .tag = 2, .op = .open, .node = @intFromEnum(TopFile.new) },
+ .{ .tag = 2, .op = .open, .node = @backingInt(TopFile.new) },
.{ .tag = 3, .op = .setattr, .node = 0, .truncate = true },
};
for (requests) |request| {
@@ -1493,16 +1493,16 @@ test "README names every file the tree serves" {
}
};
inline for (@typeInfo(TopFile).@"enum".field_values) |value| {
- const t: TopFile = @enumFromInt(value);
+ const t: TopFile = @fromBackingInt(@intCast(value));
if (t != .root and !words.has(t.fileName())) {
std.debug.print("README does not mention /{s}\n", .{t.fileName()});
return error.Undocumented;
}
}
inline for (@typeInfo(PaneFile).@"enum".field_values) |value| {
- const t: PaneFile = @enumFromInt(value);
+ const t: PaneFile = @fromBackingInt(@intCast(value));
const ok = if (t == .dir) true else if (t.inPty() and t != .pty)
- std.mem.indexOf(u8, fs.help, "pty/" ++ comptime @as(PaneFile, @enumFromInt(value)).fileName()) != null
+ std.mem.indexOf(u8, fs.help, "pty/" ++ comptime @as(PaneFile, @fromBackingInt(@intCast(value))).fileName()) != null
else
words.has(t.fileName());
if (!ok) {
@@ -1530,8 +1530,8 @@ test "readdir lists the root and a pane directory without creating anything" {
try testing.expectEqualStrings(name, top[i].name);
try testing.expectEqual(i >= 16, top[i].dir);
}
- try testing.expectEqual(@intFromEnum(TopFile.pane), top[16].node);
- try testing.expectEqual(@intFromEnum(TopFile.col), top[17].node);
+ try testing.expectEqual(@backingInt(TopFile.pane), top[16].node);
+ try testing.expectEqual(@backingInt(TopFile.col), top[17].node);
try testing.expectEqual(fs.os_root, top[18].node);
var idbuf: [16]u8 = undefined;
try testing.expect(th.nameAt(top, try std.fmt.bufPrint(&idbuf, "{d}", .{serial})) == null);
@@ -1554,7 +1554,7 @@ test "readdir lists the root and a pane directory without creating anything" {
try testing.expectEqual(Status.ok, call(p, .{ .tag = 1, .op = .getattr, .node = entry.node }).reply.status);
try testing.expectEqual(before, p.next_serial);
}
- const panes_dir = rdir(p, @intFromEnum(TopFile.pane), 0);
+ const panes_dir = rdir(p, @backingInt(TopFile.pane), 0);
const listed = th.dirents(panes_dir.bytes, &buf);
var idname: [16]u8 = undefined;
const own = th.nameAt(listed, try std.fmt.bufPrint(&idname, "{d}", .{serial})).?;
@@ -1565,16 +1565,16 @@ test "readdir lists the root and a pane directory without creating anything" {
// client that stats every name a listing gave it inert.
const shown = th.nameAt(listed, new_pane).?;
try testing.expect(!shown.dir);
- try testing.expectEqual(Status.ok, look_up(p, @intFromEnum(TopFile.pane), new_pane).reply.status);
- try testing.expectEqual(Status.ok, call(p, .{ .tag = 1, .op = .getattr, .node = @intFromEnum(TopFile.new) }).reply.status);
+ try testing.expectEqual(Status.ok, look_up(p, @backingInt(TopFile.pane), new_pane).reply.status);
+ try testing.expectEqual(Status.ok, call(p, .{ .tag = 1, .op = .getattr, .node = @backingInt(TopFile.new) }).reply.status);
try testing.expectEqual(before, p.next_serial);
const dir = rdir(p, Node.of(serial, .dir), 0);
const files = th.dirents(dir.bytes, &buf);
try testing.expectEqual(@as(usize, 18), files.len);
for ([_][]const u8{
- "name", "body", "tag", "ctl", "addr", "dot", "limit", "data", "xdata",
- "sel", "dirty", "mark", "scroll", "errors", "event", "look", "exec", "tagexec",
+ "name", "body", "tag", "ctl", "addr", "dot", "limit", "data", "xdata",
+ "sel", "dirty", "mark", "scroll", "errors", "event", "look", "exec", "tagexec",
}, 0..) |name, i|
try testing.expectEqualStrings(name, files[i].name);
try testing.expect(th.nameAt(files, ".") == null);
@@ -1588,7 +1588,7 @@ test "readdir lists the root and a pane directory without creating anything" {
try testing.expectEqual(before, p.next_serial);
try testing.expectEqual(E.NOTDIR, rdir(p, Node.of(serial, .body), 0).errno());
- try testing.expectEqual(E.NOTDIR, rdir(p, @intFromEnum(TopFile.index), 0).errno());
+ try testing.expectEqual(E.NOTDIR, rdir(p, @backingInt(TopFile.index), 0).errno());
}
test "lookup resolves top files, pane serials and pane files" {
@@ -1597,7 +1597,7 @@ test "lookup resolves top files, pane serials and pane files" {
defer p.deinit();
const serial = serialOf(p);
- try testing.expectEqual(@as(u64, @intFromEnum(TopFile.index)), look_up(p, root, "index").reply.attr.node);
+ try testing.expectEqual(@as(u64, @backingInt(TopFile.index)), look_up(p, root, "index").reply.attr.node);
try testing.expect(!look_up(p, root, "status").reply.attr.dir);
try testing.expectEqual(@as(u16, 0o444), look_up(p, root, "status").reply.attr.mode);
try testing.expectEqual(@as(u16, 0o666), look_up(p, root, "look").reply.attr.mode);
@@ -1607,17 +1607,17 @@ test "lookup resolves top files, pane serials and pane files" {
try testing.expectEqual(E.NOENT, look_up(p, root, "nosuchthing").errno());
try testing.expectEqual(E.NOENT, look_up(p, root, "self").errno());
try testing.expectEqual(E.NOENT, look_up(p, root, "cons").errno());
- try testing.expectEqual(E.NOTDIR, look_up(p, @intFromEnum(TopFile.index), "x").errno());
+ try testing.expectEqual(E.NOTDIR, look_up(p, @backingInt(TopFile.index), "x").errno());
var idbuf: [16]u8 = undefined;
const serial_name = try std.fmt.bufPrint(&idbuf, "{d}", .{serial});
try testing.expectEqual(E.NOENT, look_up(p, root, serial_name).errno());
- const dir = look_up(p, @intFromEnum(TopFile.pane), serial_name);
+ const dir = look_up(p, @backingInt(TopFile.pane), serial_name);
try testing.expectEqual(Node.of(serial, .dir), dir.reply.attr.node);
try testing.expect(dir.reply.attr.dir);
try testing.expectEqualStrings(serial_name, dir.reply.attr.name);
- try testing.expectEqual(E.NOENT, look_up(p, @intFromEnum(TopFile.pane), "99999").errno());
- try testing.expectEqual(E.NOENT, look_up(p, @intFromEnum(TopFile.pane), "0").errno());
+ try testing.expectEqual(E.NOENT, look_up(p, @backingInt(TopFile.pane), "99999").errno());
+ try testing.expectEqual(E.NOENT, look_up(p, @backingInt(TopFile.pane), "0").errno());
const body = look_up(p, Node.of(serial, .dir), "body");
try testing.expectEqual(Node.of(serial, .body), body.reply.attr.node);
@@ -1634,19 +1634,19 @@ test "opening /pane/new makes a pane and removing one closes it" {
const p = try withFile(gpa, "first\n");
defer p.deinit();
const before = p.next_serial;
- const panes_dir = @intFromEnum(TopFile.pane);
+ const panes_dir = @backingInt(TopFile.pane);
// Browsing /pane creates nothing, and neither does walking or stat-ing
// `new` itself: only an open does. That is what lets `new` be listed at
// all, since `ls -l` stats every name a listing handed it.
try testing.expectEqual(Status.ok, rdir(p, panes_dir, 0).reply.status);
try testing.expectEqual(Status.ok, look_up(p, panes_dir, new_pane).reply.status);
- try testing.expectEqual(Status.ok, call(p, .{ .tag = 1, .op = .getattr, .node = @intFromEnum(TopFile.new) }).reply.status);
+ try testing.expectEqual(Status.ok, call(p, .{ .tag = 1, .op = .getattr, .node = @backingInt(TopFile.new) }).reply.status);
try testing.expectEqual(before, p.next_serial);
// The open makes the pane and hands back its serial; the read only
// observes, so two reads of one fid answer the same pane.
- const made = call(p, .{ .tag = 2, .op = .open, .node = @intFromEnum(TopFile.new) });
+ const made = call(p, .{ .tag = 2, .op = .open, .node = @backingInt(TopFile.new) });
try testing.expectEqual(Status.ok, made.reply.status);
try testing.expectEqual(before + 1, p.next_serial);
const serial = before + 1;
@@ -1654,7 +1654,7 @@ test "opening /pane/new makes a pane and removing one closes it" {
var expected: [16]u8 = undefined;
const want = try std.fmt.bufPrint(&expected, "{d}\n", .{serial});
for (0..2) |_| {
- const answer = call(p, .{ .tag = 3, .op = .read, .node = @intFromEnum(TopFile.new), .handle = made.reply.handle, .size = 64 });
+ const answer = call(p, .{ .tag = 3, .op = .read, .node = @backingInt(TopFile.new), .handle = made.reply.handle, .size = 64 });
try testing.expectEqualStrings(want, answer.bytes);
}
@@ -1668,10 +1668,10 @@ test "opening /pane/new makes a pane and removing one closes it" {
// A second open is a second pane, and releasing a clone fid leaves the
// pane it made standing.
- const second = call(p, .{ .tag = 4, .op = .open, .node = @intFromEnum(TopFile.new) });
+ const second = call(p, .{ .tag = 4, .op = .open, .node = @backingInt(TopFile.new) });
try testing.expectEqual(Status.ok, second.reply.status);
try testing.expect(second.reply.handle != made.reply.handle);
- _ = call(p, .{ .tag = 5, .op = .release, .node = @intFromEnum(TopFile.new), .handle = made.reply.handle, .opened = true });
+ _ = call(p, .{ .tag = 5, .op = .release, .node = @backingInt(TopFile.new), .handle = made.reply.handle, .opened = true });
try testing.expect(p.paneBySerial(serial) != null);
try testing.expectEqualStrings("hi", p.panes[id].?.file.?.content);
@@ -1689,7 +1689,7 @@ test "opening /pane/new makes a pane and removing one closes it" {
// Tremove closes the pane it names, and nothing else in the tree.
try testing.expectEqual(E.PERM, th.rmdir(p, Node.of(serial, .body)).errno());
- try testing.expectEqual(E.PERM, th.rmdir(p, @intFromEnum(TopFile.index)).errno());
+ try testing.expectEqual(E.PERM, th.rmdir(p, @backingInt(TopFile.index)).errno());
try testing.expect(p.paneBySerial(serial) != null);
try testing.expectEqual(Status.ok, th.rmdir(p, Node.of(serial, .dir)).reply.status);
try testing.expect(p.paneBySerial(serial) == null);
@@ -1700,7 +1700,7 @@ test "every open that holds something is one record, named by its handle only on
const p = try th.withTerm(testing.allocator);
defer p.deinit();
const serial = serialOf(p);
- const log = @intFromEnum(TopFile.log);
+ const log = @backingInt(TopFile.log);
const event = Node.of(serial, .event);
const run = Node.of(serial, .pty_run);
const logged = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
@@ -1729,15 +1729,15 @@ test "directories walk to their parents" {
defer p.deinit();
for ([_]struct { node: u64, parent: u64 }{
.{ .node = root, .parent = root },
- .{ .node = @intFromEnum(TopFile.pane), .parent = root },
- .{ .node = Node.of(serialOf(p), .dir), .parent = @intFromEnum(TopFile.pane) },
+ .{ .node = @backingInt(TopFile.pane), .parent = root },
+ .{ .node = Node.of(serialOf(p), .dir), .parent = @backingInt(TopFile.pane) },
.{ .node = fs.os_root, .parent = root },
}) |case| {
const result = look_up(p, case.node, "..");
try testing.expectEqual(Status.ok, result.reply.status);
try testing.expectEqual(case.parent, result.reply.attr.node);
}
- try testing.expectEqual(E.NOTDIR, look_up(p, @intFromEnum(TopFile.index), "..").errno());
+ try testing.expectEqual(E.NOTDIR, look_up(p, @backingInt(TopFile.index), "..").errno());
try testing.expectEqual(E.NOTDIR, look_up(p, Node.of(serialOf(p), .body), "..").errno());
}
@@ -1748,10 +1748,10 @@ test "editor paths resolve to the same nodes the wire serves" {
var path: [64]u8 = undefined;
try testing.expectEqual(root, resolveSelf(p, "").?);
try testing.expectEqual(root, resolveSelf(p, "/./pane/../").?);
- try testing.expectEqual(@intFromEnum(TopFile.index), resolveSelf(p, "index").?);
- try testing.expectEqual(@intFromEnum(TopFile.status), resolveSelf(p, "status").?);
+ try testing.expectEqual(@backingInt(TopFile.index), resolveSelf(p, "index").?);
+ try testing.expectEqual(@backingInt(TopFile.status), resolveSelf(p, "status").?);
try testing.expect(resolveSelf(p, "new") == null);
- try testing.expectEqual(@intFromEnum(TopFile.pane), resolveSelf(p, "pane").?);
+ try testing.expectEqual(@backingInt(TopFile.pane), resolveSelf(p, "pane").?);
try testing.expectEqual(Node.of(serial, .dir), resolveSelf(p, try std.fmt.bufPrint(&path, "pane/{d}", .{serial})).?);
try testing.expectEqual(Node.of(serial, .sel), resolveSelf(p, try std.fmt.bufPrint(&path, "pane/{d}/sel", .{serial})).?);
try testing.expect(resolveSelf(p, try std.fmt.bufPrint(&path, "pane/{d}/pty/ctl", .{serial})) == null);
@@ -1800,7 +1800,7 @@ test "random placements, refused or not, leave no pane under its tag and two row
const action = r.uintLessThan(u8, 8);
switch (action) {
0 => _ = th.wr(p, Node.of(at, .exec), "New\n"),
- 1 => _ = call(p, .{ .tag = 1, .op = .open, .node = @intFromEnum(TopFile.new) }),
+ 1 => _ = call(p, .{ .tag = 1, .op = .open, .node = @backingInt(TopFile.new) }),
2 => _ = th.wr(p, Node.of(at, .exec), "Newcol\n"),
3 => _ = th.wr(p, Node.of(at, .exec), "Edit =\n"),
4 => _ = th.wr(p, Node.of(at, .exec), "Tty\n"),
@@ -1823,7 +1823,7 @@ test "at the pane cap, pane/new, look and New each say so, and look reads back e
// Tall enough that the column holds every pane at its tag and two rows,
// and wide enough that each tag, the session directory's +New, is one.
p.update(.{ .resize = .{ .cols = 400, .rows = pardes.MAX_PANES * 4 } });
- const new = @intFromEnum(TopFile.new);
+ const new = @backingInt(TopFile.new);
while (p.freeSlot() != null) try testing.expectEqual(Status.ok, call(p, .{ .tag = 1, .op = .open, .node = new }).reply.status);
var want: [64]u8 = undefined;
const said = try std.fmt.bufPrint(&want, "no space for a pane: {d} max", .{pardes.MAX_PANES});
@@ -1840,7 +1840,7 @@ test "at the pane cap, pane/new, look and New each say so, and look reads back e
var dir_buf: [4096]u8 = undefined;
const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)];
var line: [4200]u8 = undefined;
- const look_node = @intFromEnum(TopFile.look);
+ const look_node = @backingInt(TopFile.look);
const looked = th.wr(p, look_node, try std.fmt.bufPrint(&line, "{s}/f.txt\n", .{dir}));
try testing.expect(looked.errno() != 0);
try testing.expect(std.mem.indexOf(u8, looked.reply.ename, said) != null);
@@ -1857,7 +1857,7 @@ test "at the pane cap, pane/new, look and New each say so, and look reads back e
test "nothing a mount's close or a no-op truncate sends waits on the editor: a held line runs at its next step" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const exec = @intFromEnum(TopFile.exec);
+ const exec = @backingInt(TopFile.exec);
// `> exec` truncates nothing; `> body` does.
try testing.expect(!needsQuiet(p, .{ .tag = 1, .op = .setattr, .node = exec, .truncate = true }));
try testing.expect(!changesPane(p, .{ .tag = 1, .op = .setattr, .node = exec, .truncate = true }));
@@ -1875,7 +1875,7 @@ test "nothing a mount's close or a no-op truncate sends waits on the editor: a h
test "a command line cut across writes runs once whole, and the last runs at release; an Edit block waits for its end" {
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
- const exec = @intFromEnum(TopFile.exec);
+ const exec = @backingInt(TopFile.exec);
const h = call(p, .{ .tag = 1, .op = .open, .node = exec, .omode = 1 }).reply.handle;
try testing.expect(h != 0);
// Each piece fills its Twrite (a client's one write cut at msize).
@@ -1906,12 +1906,12 @@ test "a refused open, create or remove says why in words and logs no err; a refu
const serial = serialOf(p);
// pane/new is read, never written: a write is refused, and is no
// failure the log tells of.
- const new = th.wr(p, @intFromEnum(TopFile.new), "x\n");
+ const new = th.wr(p, @backingInt(TopFile.new), "x\n");
try testing.expectEqual(Status.err, new.reply.status);
try testing.expectEqualStrings("permission denied", new.reply.ename);
const made = call(p, .{ .tag = 2, .op = .open, .node = Node.of(serial, .body), .create = true });
try testing.expectEqualStrings("permission denied", made.reply.ename);
- const gone = th.rmdir(p, @intFromEnum(TopFile.index));
+ const gone = th.rmdir(p, @backingInt(TopFile.index));
try testing.expectEqual(Status.err, gone.reply.status);
try testing.expect(gone.reply.ename.len > 0 and !std.ascii.isUpper(gone.reply.ename[0]));
// An OTRUNC open's truncation of data after a failed addr: refused, no err.
@@ -1961,7 +1961,7 @@ test "a write with no newline waits for its newline or the close, whatever its s
test "look and exec read back what their own open's write touched; a fresh open reads the session's last" {
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
- const exec = @intFromEnum(TopFile.exec);
+ const exec = @backingInt(TopFile.exec);
const first = p.panes[0].?.serial;
const mine = call(p, .{ .tag = 1, .op = .open, .node = exec, .omode = 2 }).reply.handle;
const theirs = call(p, .{ .tag = 2, .op = .open, .node = exec, .omode = 2 }).reply.handle;
@@ -2013,7 +2013,7 @@ test "a rename of a pane's directory or file is refused as not permitted" {
test "no placement leaves a pane shorter than its tag and two rows; a full column refuses the next" {
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
- const new = @intFromEnum(TopFile.new);
+ const new = @backingInt(TopFile.new);
var made: usize = 1;
const refused = while (made < pardes.MAX_PANES) : (made += 1) {
const a = call(p, .{ .tag = 1, .op = .open, .node = new });
@@ -2078,7 +2078,7 @@ test "a pane made from pane/new goes last in its column, even when the last pane
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
for (0..3) |_| {
- const made = call(p, .{ .tag = 1, .op = .open, .node = @intFromEnum(TopFile.new) }).reply.handle;
+ const made = call(p, .{ .tag = 1, .op = .open, .node = @backingInt(TopFile.new) }).reply.handle;
p.sync();
try testing.expectEqual(made, p.panes[p.col_panes[0][p.col_n[0] - 1]].?.serial);
}
diff --git a/src/pager.zig b/src/pager.zig
index feabd194..aba73d43 100644
--- a/src/pager.zig
+++ b/src/pager.zig
@@ -240,8 +240,8 @@ const Handler = struct {
.reset_strikethrough => s.strikethrough = false,
.direct_color_fg => |c| s.fg = .{ .rgb = .{ c.r, c.g, c.b } },
.direct_color_bg => |c| s.bg = .{ .rgb = .{ c.r, c.g, c.b } },
- .@"8_fg", .@"8_bright_fg" => |name| s.fg = .{ .index = @intFromEnum(name) },
- .@"8_bg", .@"8_bright_bg" => |name| s.bg = .{ .index = @intFromEnum(name) },
+ .@"8_fg", .@"8_bright_fg" => |name| s.fg = .{ .index = @backingInt(name) },
+ .@"8_bg", .@"8_bright_bg" => |name| s.bg = .{ .index = @backingInt(name) },
.@"256_fg" => |i| s.fg = .{ .index = i },
.@"256_bg" => |i| s.bg = .{ .index = i },
.reset_fg => s.fg = .default,
diff --git a/src/pardes.zig b/src/pardes.zig
index 8da0922d..7e166847 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -924,7 +924,7 @@ test "Filter is ordered after Del and toggles only its terminal or +Pager pane"
const testing = std.testing;
const del = std.meta.stringToEnum(Builtin, "Del") orelse return error.MissingDelBuiltin;
const filter = std.meta.stringToEnum(Builtin, "Filter") orelse return error.MissingFilterBuiltin;
- try testing.expectEqual(@intFromEnum(del) + 1, @intFromEnum(filter));
+ try testing.expectEqual(@backingInt(del) + 1, @backingInt(filter));
const p = try Pardes.init(testing.allocator, .{ .tty_only = true });
defer p.deinit();
@@ -3308,8 +3308,8 @@ test "tabbed file aligns syntax cursor and mouse at the nearest insertion gap" {
const pane = try p.setTestFile("\treturn x\n");
const f = &pane.file.?;
f.highlights = try p.tree_sitter_gpa.alloc(u8, f.content.len);
- @memset(f.highlights, @intFromEnum(syntax.Syn.none));
- @memset(f.highlights[1..7], @intFromEnum(syntax.Syn.keyword));
+ @memset(f.highlights, @backingInt(syntax.Syn.none));
+ @memset(f.highlights[1..7], @backingInt(syntax.Syn.keyword));
f.syntax_dirty = false;
pane.body.cur_row = 0;
pane.body.cur_col = 1;
@@ -3721,7 +3721,7 @@ pub fn hit(key: Key, binding: []const config.Chord) bool {
return false;
}
-pub const sel_slot = @intFromEnum(config.select_button);
+pub const sel_slot = @backingInt(config.select_button);
/// Pixel dimensions are meaningful only to the native PDF placement path.
/// Keep resize events layout-only when that path is not part of the build.
@@ -6040,7 +6040,7 @@ pub const Pardes = struct {
// The one-failure rule is a write's: a refused open (its OTRUNC's
// truncation, a setattr, too), create or remove is its Rerror alone,
// no err, as is a write to pane/new, which is only ever read.
- const ruled = req.op == .write and req.node != @intFromEnum(ctlfs.TopFile.new);
+ const ruled = req.op == .write and req.node != @backingInt(ctlfs.TopFile.new);
if (reply.status == .err and ruled) ctlfs.events.noteError(p, req, reply);
// The request was a whole step of its own, so it settles the way a
// step does: the cursor and scroll reconciled, the scripted panes
diff --git a/src/pdf_view.zig b/src/pdf_view.zig
index 567117bb..500f05f3 100644
--- a/src/pdf_view.zig
+++ b/src/pdf_view.zig
@@ -2604,7 +2604,7 @@ pub fn pointerRelease(
) PointerRelease {
if (comptime !enabled) return .{};
const state = &(pane.pdf orelse return .{});
- const slot = @intFromEnum(button);
+ const slot = @backingInt(button);
const grid_selection = pane.sel[slot];
pane.sel[slot].state = .none; // native quads, not projected text cells
diff --git a/src/syntax.zig b/src/syntax.zig
index fa212ca7..1c09c9f3 100644
--- a/src/syntax.zig
+++ b/src/syntax.zig
@@ -214,7 +214,7 @@ fn ensure(spec: *Spec) !Selected {
const capture_styles = spec.capture_styles[0..query.captureCount()];
for (capture_styles, 0..) |*style, id| {
const name = query.captureNameForId(@intCast(id)) orelse "";
- style.* = @intFromEnum(synFor(name));
+ style.* = @backingInt(synFor(name));
if (style.* == 0) query.disableCapture(name);
}
const parser = ts.Parser.create();
@@ -965,11 +965,11 @@ test "syntax formatted locations color hidden context and preserve multiline sou
const styles = try highlightLocationRows(gpa, content, &rows);
defer gpa.free(styles);
const body = std.mem.indexOf(u8, content, "comment body").?;
- try std.testing.expectEqual(@intFromEnum(Syn.comment), styles[body]);
- try std.testing.expectEqual(@intFromEnum(Syn.none), styles[body - 1]);
+ try std.testing.expectEqual(@backingInt(Syn.comment), styles[body]);
+ try std.testing.expectEqual(@backingInt(Syn.none), styles[body - 1]);
const number = std.mem.indexOf(u8, content, "42").?;
- try std.testing.expectEqual(@intFromEnum(Syn.number), styles[number]);
- try std.testing.expectEqual(@intFromEnum(Syn.none), styles[0]);
+ try std.testing.expectEqual(@backingInt(Syn.number), styles[number]);
+ try std.testing.expectEqual(@backingInt(Syn.none), styles[0]);
}
test "syntax formatted locations separate alignment from Markdown indentation" {
@@ -985,8 +985,8 @@ test "syntax formatted locations separate alignment from Markdown indentation" {
};
const styles = try highlightLocationRows(gpa, content, &rows);
defer gpa.free(styles);
- try std.testing.expectEqual(@intFromEnum(Syn.keyword), styles[std.mem.indexOf(u8, content, "Heading").?]);
- try std.testing.expectEqual(@intFromEnum(Syn.string), styles[std.mem.indexOf(u8, content, "Code").?]);
+ try std.testing.expectEqual(@backingInt(Syn.keyword), styles[std.mem.indexOf(u8, content, "Heading").?]);
+ try std.testing.expectEqual(@backingInt(Syn.string), styles[std.mem.indexOf(u8, content, "Code").?]);
}
fn inject(styles: []u8, source: []const u8, node: ts.Node, markdown: bool) void {
const kind = node.kind();
@@ -1149,7 +1149,7 @@ pub fn highlightDiffRows(gpa: std.mem.Allocator, content: []const u8, start_raw:
.meta, .old_path, .new_path => .comment,
else => .none,
};
- if (style != .none) window.fill(at, nl - at, @intFromEnum(style));
+ if (style != .none) window.fill(at, nl - at, @backingInt(style));
}
if (nl >= content.len) break;
at = nl + 1;
@@ -1192,10 +1192,10 @@ fn paintDiffPiece(gpa: std.mem.Allocator, window: anytype, bytes: []const u8, at
for (kinds) |kind| {
const line = lines.next() orelse break;
const style: u8 = switch (kind) {
- .added => @intFromEnum(Syn.string) | diff_added,
- .removed => @intFromEnum(Syn.number) | diff_removed,
- .no_newline => @intFromEnum(Syn.comment),
- .hunk => @intFromEnum(Syn.keyword),
+ .added => @backingInt(Syn.string) | diff_added,
+ .removed => @backingInt(Syn.number) | diff_removed,
+ .no_newline => @backingInt(Syn.comment),
+ .hunk => @backingInt(Syn.keyword),
else => 0,
};
if (style != 0) window.fill(at + offset, line.len, style);
@@ -1273,8 +1273,8 @@ fn paintHunk(gpa: std.mem.Allocator, out: []u8, bytes: []const u8, kinds: []cons
.removed => @memcpy(dst, old_colors[old_at..][0..code_len]),
.added => @memcpy(dst, new_colors[new_at..][0..code_len]),
.context => @memcpy(dst, if (context_new) new_colors[new_at..][0..code_len] else old_colors[old_at..][0..code_len]),
- .no_newline => @memset(out[offset..][0..line.len], @intFromEnum(Syn.comment)),
- .hunk => @memset(out[offset..][0..line.len], @intFromEnum(Syn.keyword)),
+ .no_newline => @memset(out[offset..][0..line.len], @backingInt(Syn.comment)),
+ .hunk => @memset(out[offset..][0..line.len], @backingInt(Syn.keyword)),
else => {},
}
if (kind == .context or kind == .removed) old_at += code_len + 1;
@@ -1322,8 +1322,8 @@ test "syntax a results row is coloured by the file its location names" {
try std.testing.expectEqual(content.len, styles.len);
for (styles[0.."src/a.zig:1:1".len]) |b| try std.testing.expectEqual(@as(u8, 0), b);
const zig_kw = std.mem.indexOf(u8, content, "struct").?;
- try std.testing.expectEqual(@intFromEnum(Syn.keyword), styles[zig_kw]);
- try std.testing.expectEqual(@intFromEnum(Syn.keyword), styles[zig_kw + 5]);
+ try std.testing.expectEqual(@backingInt(Syn.keyword), styles[zig_kw]);
+ try std.testing.expectEqual(@backingInt(Syn.keyword), styles[zig_kw + 5]);
const prose = std.mem.indexOf(u8, content, "just some prose").?;
for (styles[prose .. prose + 14]) |b| try std.testing.expectEqual(@as(u8, 0), b);
const bare = std.mem.indexOf(u8, content, "src/c.zig").?;
@@ -1371,14 +1371,14 @@ test "syntax default full grammar set highlights Typst source" {
const keyword_at = std.mem.indexOf(u8, source, "let").?;
const number_at = std.mem.indexOf(u8, source, "42").?;
const string_at = std.mem.indexOf(u8, source, "\"hello\"").?;
- try std.testing.expectEqual(Syn.comment, @as(Syn, @enumFromInt(styles[comment_at])));
- try std.testing.expectEqual(Syn.keyword, @as(Syn, @enumFromInt(styles[keyword_at])));
- try std.testing.expectEqual(Syn.number, @as(Syn, @enumFromInt(styles[number_at])));
- try std.testing.expectEqual(Syn.string, @as(Syn, @enumFromInt(styles[string_at])));
+ try std.testing.expectEqual(Syn.comment, @as(Syn, @fromBackingInt(@intCast(styles[comment_at]))));
+ try std.testing.expectEqual(Syn.keyword, @as(Syn, @fromBackingInt(@intCast(styles[keyword_at]))));
+ try std.testing.expectEqual(Syn.number, @as(Syn, @fromBackingInt(@intCast(styles[number_at]))));
+ try std.testing.expectEqual(Syn.string, @as(Syn, @fromBackingInt(@intCast(styles[string_at]))));
const short_ext = try highlightFileRange(std.testing.allocator, "paper.typ", source, 0, source.len);
defer std.testing.allocator.free(short_ext);
- try std.testing.expectEqual(Syn.keyword, @as(Syn, @enumFromInt(short_ext[keyword_at])));
+ try std.testing.expectEqual(Syn.keyword, @as(Syn, @fromBackingInt(@intCast(short_ext[keyword_at]))));
}
test "syntax Typst markup constructs paint and raw blocks inject their language" {
@@ -1403,7 +1403,7 @@ test "syntax Typst markup constructs paint and raw blocks inject their language"
const synAt = struct {
fn f(s: []const u8, src: []const u8, needle: []const u8, offset: usize) Syn {
- return @enumFromInt(s[std.mem.indexOf(u8, src, needle).? + offset]);
+ return @fromBackingInt(@intCast(s[std.mem.indexOf(u8, src, needle).? + offset]));
}
}.f;
try std.testing.expectEqual(Syn.keyword, synAt(styles, source, "= Heading", 0));
@@ -1443,7 +1443,7 @@ test "syntax markdown highlights markup, injects inline spans and fenced code bl
const synAt = struct {
fn f(s: []const u8, src: []const u8, needle: []const u8, offset: usize) Syn {
- return @enumFromInt(s[std.mem.indexOf(u8, src, needle).? + offset]);
+ return @fromBackingInt(@intCast(s[std.mem.indexOf(u8, src, needle).? + offset]));
}
}.f;
try std.testing.expectEqual(Syn.keyword, synAt(styles, source, "Title", 0));
@@ -1471,8 +1471,8 @@ test "syntax inline fast path agrees with full Markdown query" {
const actual = try std.testing.allocator.alloc(u8, source.len);
defer std.testing.allocator.free(actual);
for ([_]Syn{ .none, .keyword }) |background| {
- @memset(expected, @intFromEnum(background));
- @memset(actual, @intFromEnum(background));
+ @memset(expected, @backingInt(background));
+ @memset(actual, @backingInt(background));
runQuery(expected, sel, tree, 0);
inject(actual, source, tree.rootNode(), true);
if (!std.mem.eql(u8, expected, actual)) std.debug.print("inline mismatch: {s}\n", .{source});
@@ -1511,9 +1511,9 @@ test "syntax plain Markdown keeps block styles without starting the inline parse
const source = "# Heading\n\nPlain prose.\n\n indented code\n";
const styles = try highlightFileRange(std.testing.allocator, "a.md", source, 0, source.len);
defer std.testing.allocator.free(styles);
- try std.testing.expectEqual(@intFromEnum(Syn.keyword), styles[2]);
- try std.testing.expectEqual(@intFromEnum(Syn.none), styles[std.mem.indexOf(u8, source, "Plain").?]);
- try std.testing.expectEqual(@intFromEnum(Syn.string), styles[std.mem.indexOf(u8, source, "indented").?]);
+ try std.testing.expectEqual(@backingInt(Syn.keyword), styles[2]);
+ try std.testing.expectEqual(@backingInt(Syn.none), styles[std.mem.indexOf(u8, source, "Plain").?]);
+ try std.testing.expectEqual(@backingInt(Syn.string), styles[std.mem.indexOf(u8, source, "indented").?]);
for (specs) |spec| {
if (std.mem.eql(u8, spec.name, "markdown_inline")) try std.testing.expect(spec.selected == null);
}
@@ -1544,7 +1544,7 @@ test "syntax highlightDiff colors unified diff lines by prefix" {
}
fn diffSynAt(styles: []const u8, text: []const u8, needle: []const u8, offset: usize) Syn {
- return @enumFromInt(styles[std.mem.indexOf(u8, text, needle).? + offset] & syn_bits);
+ return @fromBackingInt(@intCast(styles[std.mem.indexOf(u8, text, needle).? + offset] & syn_bits));
}
test "syntax a Zig hunk is coloured as Zig, each side parsed whole" {
@@ -1715,7 +1715,7 @@ test "syntax a hunk painted once is kept, and a long one is parsed in pieces" {
const at = std.mem.indexOf(u8, content, "+const v1000 ").?;
const window = try highlightDiff(gpa, content, at, at + 200);
defer gpa.free(window);
- try std.testing.expectEqual(Syn.number, @as(Syn, @enumFromInt(window["+const v1000 = ".len] & syn_bits)));
+ try std.testing.expectEqual(Syn.number, @as(Syn, @fromBackingInt(@intCast(window["+const v1000 = ".len] & syn_bits))));
var cached: usize = 0;
for (diff_pieces) |slot| if (slot) |piece| {
cached += 1;
@@ -1780,7 +1780,7 @@ test "syntax query filtering preserves upstream colors" {
reference.query = raw_query;
reference.capture_styles = try std.testing.allocator.alloc(u8, raw_query.captureCount());
defer std.testing.allocator.free(reference.capture_styles);
- for (reference.capture_styles, 0..) |*style, id| style.* = @intFromEnum(synFor(raw_query.captureNameForId(@intCast(id)) orelse ""));
+ for (reference.capture_styles, 0..) |*style, id| style.* = @backingInt(synFor(raw_query.captureNameForId(@intCast(id)) orelse ""));
const tree = selected.parser.parseString(source, null) orelse return error.ParseFailed;
defer tree.destroy();
var expected: [source.len]u8 = @splat(0);
@@ -1806,8 +1806,8 @@ test "syntax Zig keyword captures cover both bytes beyond line ten thousand" {
defer std.testing.allocator.free(styles);
for ([_][]const u8{ "fn", "if" }) |keyword| {
const at = std.mem.indexOf(u8, code, keyword).?;
- try std.testing.expectEqual(@intFromEnum(Syn.keyword), styles[at]);
- try std.testing.expectEqual(@intFromEnum(Syn.keyword), styles[at + 1]);
+ try std.testing.expectEqual(@backingInt(Syn.keyword), styles[at]);
+ try std.testing.expectEqual(@backingInt(Syn.keyword), styles[at + 1]);
}
}
@@ -1823,8 +1823,8 @@ test "syntax allocator switching clears default-runtime caches" {
const restored = try highlightFileRange(std.testing.allocator, "a.zig", source, 0, source.len);
defer std.testing.allocator.free(restored);
defer stop();
- try std.testing.expectEqual(@intFromEnum(Syn.keyword), restored[0]);
- try std.testing.expectEqual(@intFromEnum(Syn.keyword), restored[1]);
+ try std.testing.expectEqual(@backingInt(Syn.keyword), restored[0]);
+ try std.testing.expectEqual(@backingInt(Syn.keyword), restored[1]);
}
test "syntax location context snapshots retain omitted multiline comment scope" {
@@ -1848,8 +1848,8 @@ test "syntax location context snapshots retain omitted multiline comment scope"
const styles = try highlightLocationRows(gpa, content, &rows);
defer gpa.free(styles);
for (styles[rows[0].code_start..][0..code.len]) |style|
- try std.testing.expectEqual(@intFromEnum(Syn.comment), style);
- try std.testing.expectEqual(@intFromEnum(Syn.none), styles[0]);
+ try std.testing.expectEqual(@backingInt(Syn.comment), style);
+ try std.testing.expectEqual(@backingInt(Syn.none), styles[0]);
}
test "syntax declaration locations clear snapshots without muting ordinary context" {
@@ -1875,7 +1875,7 @@ test "syntax declaration locations clear snapshots without muting ordinary conte
const styles = try highlightLocationRows(gpa, content, &rows);
defer gpa.free(styles);
for (styles[3..][0..header.len]) |style| try std.testing.expectEqual(@as(u8, 0), style);
- try std.testing.expectEqual(@intFromEnum(Syn.number), styles[std.mem.indexOf(u8, content, "42").?]);
+ try std.testing.expectEqual(@backingInt(Syn.number), styles[std.mem.indexOf(u8, content, "42").?]);
}
test "syntax stacked addresses do not split multiline source groups" {
@@ -1895,11 +1895,11 @@ test "syntax stacked addresses do not split multiline source groups" {
};
const styles = try highlightLocationRows(gpa, content, &rows);
defer gpa.free(styles);
- try std.testing.expectEqual(@intFromEnum(Syn.comment), styles[std.mem.indexOf(u8, content, "42").?]);
- try std.testing.expectEqual(@intFromEnum(Syn.number), styles[std.mem.indexOf(u8, content, "7;").?]);
+ try std.testing.expectEqual(@backingInt(Syn.comment), styles[std.mem.indexOf(u8, content, "42").?]);
+ try std.testing.expectEqual(@backingInt(Syn.number), styles[std.mem.indexOf(u8, content, "7;").?]);
for ([_][]const u8{ "a.c:1:1", "a.c:2:1", "a.c:3:1" }) |label| {
const at = std.mem.indexOf(u8, content, label).?;
- for (styles[at..][0..label.len]) |style| try std.testing.expectEqual(@intFromEnum(Syn.none), style);
+ for (styles[at..][0..label.len]) |style| try std.testing.expectEqual(@backingInt(Syn.none), style);
}
}
diff --git a/src/terminal.zig b/src/terminal.zig
index a8e7931c..33ad22e6 100644
--- a/src/terminal.zig
+++ b/src/terminal.zig
@@ -1347,7 +1347,7 @@ pub fn forwardKey(p: *Pardes, id: usize, key: Key) void {
pub fn enterTty(p: *Pardes, id: usize) void {
const pane = p.panes[id] orelse return;
- const selected = pane.rawPointerText(pane.sel[@intFromEnum(config.select_button)]) != null;
+ const selected = pane.rawPointerText(pane.sel[@backingInt(config.select_button)]) != null;
if (comptime enabled) if (!selected and pane.terminal != null and pane.body.cur_pinned and pane.terminal.?.vt.cursorIsAtPrompt()) handoff: {
const screen = pane.terminal.?.vt.screens.active;
const goff: i32 = @intCast(screen.pages.scrollbar().offset);
diff --git a/src/web.zig b/src/web.zig
index fed2ba5a..f89aa7e9 100644
--- a/src/web.zig
+++ b/src/web.zig
@@ -258,18 +258,20 @@ fn mouseWithHit(button_arg: u32, kind_arg: u32, col_arg: u32, row_arg: u32, mods
3 => .drag,
else => return,
};
- s.core.update(.{ .mouse = .{
- .body_hit = hit,
- .tag_hit = tag_hit,
- .button = button,
- .kind = kind,
- .col = @intCast(@min(col_arg, std.math.maxInt(u16))),
- .row = @intCast(@min(row_arg, std.math.maxInt(u16))),
- .ctrl = mods & 1 != 0,
- // Alt-click is B2 and Cmd/Super-click B3 (mouse.emulateButton).
- .alt = mods & 2 != 0,
- .super = mods & 8 != 0,
- } });
+ s.core.update(.{
+ .mouse = .{
+ .body_hit = hit,
+ .tag_hit = tag_hit,
+ .button = button,
+ .kind = kind,
+ .col = @intCast(@min(col_arg, std.math.maxInt(u16))),
+ .row = @intCast(@min(row_arg, std.math.maxInt(u16))),
+ .ctrl = mods & 1 != 0,
+ // Alt-click is B2 and Cmd/Super-click B3 (mouse.emulateButton).
+ .alt = mods & 2 != 0,
+ .super = mods & 8 != 0,
+ },
+ });
}
export fn pardes_touch_scroll(delta: f32) void {
@@ -347,7 +349,7 @@ export fn pardes_tag_layer_value(index: u32, field: u32) u32 {
if (layer.rows == 0) return 0;
return switch (field) {
0 => layer.cols,
- 1 => @intFromEnum(layer.kind),
+ 1 => @backingInt(layer.kind),
2 => layer.id,
3 => layer.serial,
4 => layer.viewport.x,
@@ -421,7 +423,7 @@ export fn pardes_row_metrics(body_w: u16, body_h: u16, tagline_w: u16, tagline_h
export fn pardes_pointer_shape() u32 {
const s = &(state orelse return 0);
- return @intFromEnum(s.core.surface.pointer_shape);
+ return @backingInt(s.core.surface.pointer_shape);
}
export fn pardes_cursor_y() i32 {
@@ -557,6 +559,6 @@ fn encodeAttrs(style: pardes.CellStyle) u16 {
attrs |= @as(u16, @intFromBool(style.invisible)) << 5;
attrs |= @as(u16, @intFromBool(style.strikethrough)) << 6;
attrs |= @as(u16, @intFromBool(style.font_role == .tagline)) * attr_tagline;
- attrs |= @as(u16, @intFromEnum(style.ul)) << 8;
+ attrs |= @as(u16, @backingInt(style.ul)) << 8;
return attrs;
}