diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-21 14:35:15 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-22 10:03:15 -0300 |
| commit | bc3d18d27f9fc1155db7fac3946c4d38774f9e65 (patch) | |
| tree | 9178ce95952797f8a78b16c2b805e53368efb35a /src | |
| parent | 1ecb9b720840ea8e4753823fa8cddcf5d6a3a4d2 (diff) | |
| download | pardes-bc3d18d27f9fc1155db7fac3946c4d38774f9e65.tar.gz pardes-bc3d18d27f9fc1155db7fac3946c4d38774f9e65.zip | |
Build with Zig 0.17
ghostty, libvaxis and uucode move to ghostty's 0.17 pins, cloud9 to its 0.17
main, SDL to castholm's release-3.4.x (3.4.18), zstbi and tree-sitter to
forks with 0.17 build files (see build.zig.zon). A bare zig build copies the
binaries into ~/.local/bin (-Dhome-install=false leaves it out): 0.17 keeps
the prefix from build scripts. A terminal's edited copy goes when the program
clears the screen. tinywin.snap is gone; perf baselines are re-recorded.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src')
47 files changed, 384 insertions, 277 deletions
diff --git a/src/9p_io.zig b/src/9p_io.zig index 18c51ece..27d79b93 100644 --- a/src/9p_io.zig +++ b/src/9p_io.zig @@ -1553,7 +1553,7 @@ test "a socket path too long for sun_path is no listener, and leaves the editor' } else { _ = unsetenv("XDG_RUNTIME_DIR"); }; - const long = "n" ** 120; + const long = &@as([120]u8, @splat('n')); try testing.expect(listen(testing.io, testing.allocator, p, long, "", null, null) == null); try testing.expect(pardes.turn.answer_held == null); try testing.expect(pardes.turn.wake_parked == null); @@ -1567,7 +1567,7 @@ test "a listening editor posts itself into the 9P registry and unposts on stop" _ = try std.fmt.bufPrintSentinel(&directory, "/tmp/pardes-post-XXXXXX", .{}, 0); if (mkdtemp(&directory) == null) return error.TempDirectoryFailed; const dir = std.mem.span(@as([*:0]const u8, &directory)); - const old_runtime = if (libc.getenv("XDG_RUNTIME_DIR")) |v| try gpa.dupeZ(u8, std.mem.span(v)) else null; + const old_runtime = if (libc.getenv("XDG_RUNTIME_DIR")) |v| try gpa.dupeSentinel(u8, std.mem.span(v), 0) else null; defer { if (old_runtime) |v| { _ = setenv("XDG_RUNTIME_DIR", v, 1); @@ -1628,7 +1628,7 @@ test "Unix TCP and QUIC share one listener through reads writes reconnects and r if (mkdtemp(&directory) == null) return error.TempDirectoryFailed; // What the listener posted and left inside goes with it. defer std.Io.Dir.cwd().deleteTree(testing.io, std.mem.sliceTo(&directory, 0)) catch |err| std.debug.print("deleteTree: {s}\n", .{@errorName(err)}); - const old_runtime = if (libc.getenv("XDG_RUNTIME_DIR")) |v| try gpa.dupeZ(u8, std.mem.span(v)) else null; + const old_runtime = if (libc.getenv("XDG_RUNTIME_DIR")) |v| try gpa.dupeSentinel(u8, std.mem.span(v), 0) else null; defer { if (old_runtime) |v| { _ = setenv("XDG_RUNTIME_DIR", v, 1); @@ -1749,7 +1749,7 @@ test "a change waits while the editor is out mid-step, a read does not, and the if (mkdtemp(&directory) == null) return error.TempDirectoryFailed; // What the listener posted and left inside goes with it. defer std.Io.Dir.cwd().deleteTree(testing.io, std.mem.sliceTo(&directory, 0)) catch |err| std.debug.print("deleteTree: {s}\n", .{@errorName(err)}); - const old_runtime = if (libc.getenv("XDG_RUNTIME_DIR")) |v| try gpa.dupeZ(u8, std.mem.span(v)) else null; + const old_runtime = if (libc.getenv("XDG_RUNTIME_DIR")) |v| try gpa.dupeSentinel(u8, std.mem.span(v), 0) else null; defer { if (old_runtime) |v| { _ = setenv("XDG_RUNTIME_DIR", v, 1); @@ -1824,7 +1824,7 @@ test "a held read is answered when the log has news, and a flushed one spends no if (mkdtemp(&directory) == null) return error.TempDirectoryFailed; // What the listener posted and left inside goes with it. defer std.Io.Dir.cwd().deleteTree(testing.io, std.mem.sliceTo(&directory, 0)) catch |err| std.debug.print("deleteTree: {s}\n", .{@errorName(err)}); - const old_runtime = if (libc.getenv("XDG_RUNTIME_DIR")) |v| try gpa.dupeZ(u8, std.mem.span(v)) else null; + const old_runtime = if (libc.getenv("XDG_RUNTIME_DIR")) |v| try gpa.dupeSentinel(u8, std.mem.span(v), 0) else null; defer { if (old_runtime) |v| { _ = setenv("XDG_RUNTIME_DIR", v, 1); @@ -2051,7 +2051,7 @@ test "a pane's PARDES_MOUNT is the session's directory under 9ns --mntgen, and u const names = [_][*:0]const u8{ "NINE_MNTGEN", "NINE_MOUNT", "PARDES_MOUNT" }; var saved: [names.len]?[:0]u8 = @splat(null); for (names, &saved) |name, *value| { - if (libc.getenv(name)) |old| value.* = try testing.allocator.dupeZ(u8, std.mem.span(old)); + if (libc.getenv(name)) |old| value.* = try testing.allocator.dupeSentinel(u8, std.mem.span(old), 0); } defer for (names, saved) |name, value| { if (value) |old| { @@ -2073,7 +2073,7 @@ test "9P shell environment states being inside pardes apart from how to reach it const names = [_][*:0]const u8{ "XDG_RUNTIME_DIR", "HOME", "PARDES_PID", "PARDES_9P", "PARDES_PANE" }; var saved: [names.len]?[:0]u8 = @splat(null); for (names, &saved) |name, *value| { - if (libc.getenv(name)) |old| value.* = try testing.allocator.dupeZ(u8, std.mem.span(old)); + if (libc.getenv(name)) |old| value.* = try testing.allocator.dupeSentinel(u8, std.mem.span(old), 0); } defer for (names, saved) |name, value| { if (value) |old| { diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index 4fe0760c..c6c2eadd 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -17,6 +17,14 @@ - A diff paged into a session (`git show | pardes -`) opens its `+Diff` alone; the `+Pager` no longer stays folded under it. +- Built with Zig 0.17. A bare `zig build` still puts the binaries in + `~/.local/bin`, now as a copy beside the prefix, which `--prefix` no + longer prevents; `-Dhome-install=false` does. ghostty, libvaxis, uucode + and SDL (3.4.18) move to their Zig 0.17 versions, and tree-sitter to a + 0.28 development snapshot. +- A terminal's edited copy goes when the program clears the screen, + instead of staying where its rows were. + - n/N follow Helix search registers, counts, wrapping and select mode. `*` sets a search from the selection; `Alt-*` omits word boundaries. The location ring remains as LookNext/LookPrev (Space j n/p). diff --git a/src/Layer.zig b/src/Layer.zig index 7a5fcf7e..ba45bc88 100644 --- a/src/Layer.zig +++ b/src/Layer.zig @@ -51,7 +51,7 @@ cols: u16 = 0, rows: u16 = 0, /// A body's compact rows, from its top. context_rows: u16 = 0, -context_separators: std.bit_set.StaticBitSet(limits.wrap_rows) = .initEmpty(), +context_separators: std.bit_set.StaticBitSet(limits.wrap_rows) = .empty, /// `rows * cols`, row after row. cells: []pardes.Cell = &.{}, cursor: ?struct { x: u16, y: u16, bar: bool = false } = null, @@ -72,7 +72,7 @@ pub fn capacity(layer: *const Layer, metrics: Metrics) u16 { } pub fn setContextLines(layer: *Layer, lines: []const i32) void { - layer.context_separators = .initEmpty(); + layer.context_separators = .empty; const count = @min(lines.len, layer.context_rows); var index: usize = 0; while (index + 1 < count and index < limits.wrap_rows) : (index += 1) { diff --git a/src/Messages.zig b/src/Messages.zig index 2314939f..b67a8402 100644 --- a/src/Messages.zig +++ b/src/Messages.zig @@ -519,20 +519,20 @@ pub fn errorWords(err: anyerror, buf: []u8) []const u8 { /// A ZON parse failure in a person's words: the first error the parser /// found and its line, `line 3: expected ','`. pub fn zonWhy(diag: *const std.zon.parse.Diagnostics, buf: []u8) []const u8 { - var errors = diag.iterateErrors(); - const first = errors.next() orelse return "not valid ZON"; - const loc = first.getLocation(diag); - return std.fmt.bufPrint(buf, "line {d}: {f}", .{ loc.line + 1, first.fmtMessage(diag) }) catch "not valid ZON"; + if (diag.errors.len == 0) return "not valid ZON"; + const first = diag.errors[0]; + return std.fmt.bufPrint(buf, "line {d}: {s}", .{ first.loc.line + 1, first.msg }) catch "not valid ZON"; } test "errors are said in words, and a ZON failure names its line" { var buf: [128]u8 = undefined; try std.testing.expectEqualStrings("file not found", errorWords(error.FileNotFound, &buf)); try std.testing.expectEqualStrings("too large", errorWords(error.FileTooLarge, &buf)); - var diag: std.zon.parse.Diagnostics = .{}; - defer diag.deinit(std.testing.allocator); + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + var diag: std.zon.parse.Diagnostics = undefined; const T = struct { a: u8 }; - try std.testing.expectError(error.ParseZon, std.zon.parse.fromSliceAlloc(T, std.testing.allocator, ".{\n .a = 1,\n .b = 2 }", &diag, .{})); + try std.testing.expectError(error.ParseZon, std.zon.parse.fromSlice(T, .{ .gpa = std.testing.allocator, .arena = arena.allocator(), .source = ".{\n .a = 1,\n .b = 2 }", .diagnostics = &diag })); try std.testing.expect(std.mem.startsWith(u8, zonWhy(&diag, &buf), "line 3: ")); } diff --git a/src/TerminalImages.zig b/src/TerminalImages.zig index bc1b2ea8..4140813f 100644 --- a/src/TerminalImages.zig +++ b/src/TerminalImages.zig @@ -38,6 +38,72 @@ const GlyphKey = struct { id: u32, generation: u64, src: PixelRect, cols: u16 }; /// left corner (above or left of it is negative). const Rect = struct { x: i64, y: i64, w: i64, h: i64 }; +/// The runs of Kitty placeholder cells between two pins, one row's run at a +/// time, as ghostty's own `kitty.graphics.unicode.placementIterator` gave +/// them before it moved into its RenderState, which pardes does not keep. +const PlaceholderRuns = struct { + rows: ghostty_vt.PageList.RowIterator, + row: ?ghostty_vt.Pin, + /// Where the scan of `row` resumes: a run ended by an incompatible + /// placeholder starts the next one there. + x: usize = 0, + + fn init(top: ghostty_vt.Pin, bottom: ghostty_vt.Pin) PlaceholderRuns { + var rows = top.rowIterator(.right_down, bottom); + const row = rows.next(); + return .{ .rows = rows, .row = row }; + } + + fn next(self: *PlaceholderRuns) ?gfx.unicode.Placement { + while (self.row) |row| { + if (!row.rowAndCell().row.kitty_virtual_placeholder) { + self.advance(); + continue; + } + var run: ?gfx.unicode.IncompletePlacement = null; + var start: usize = 0; + const cells = row.cells(.all); + while (self.x < cells.len) : (self.x += 1) { + const cell = &cells[self.x]; + if (cell.codepoint() != gfx.unicode.placeholder) { + if (run) |done| return complete(row, start, done); + continue; + } + const style = row.style(cell); + const curr: gfx.unicode.IncompletePlacement = .init(&style, row.grapheme(cell) orelse &.{}); + if (run) |*prev| { + if (!prev.append(&curr)) return complete(row, start, prev.*); + } else { + run = curr.start(); + start = self.x; + } + } + self.advance(); + if (run) |done| return complete(row, start, done); + } + return null; + } + + fn advance(self: *PlaceholderRuns) void { + self.row = self.rows.next(); + self.x = 0; + } + + fn complete(row: ghostty_vt.Pin, x: usize, run: gfx.unicode.IncompletePlacement) gfx.unicode.Placement { + var pin = row; + pin.x = @intCast(x); + return .{ + .pin = pin, + .image_id = run.imageId(), + .placement_id = run.placement_id orelse 0, + .col = run.col.?, + .row = run.row.?, + .width = run.width, + .height = 1, + }; + } +}; + pub fn deinit(ti: *TerminalImages, gpa: std.mem.Allocator) void { var conv = ti.converted.valueIterator(); while (conv.next()) |c| gpa.free(c.rgba); @@ -91,7 +157,7 @@ pub fn draw( // Virtual placements: shown through the placeholder cells, one run of // them on a row at a time. The placeholders themselves are not text. - var runs = gfx.unicode.placementIterator(top, bottom); + var runs: PlaceholderRuns = .init(top, bottom); while (runs.next()) |run| { const at = pages.pointFromPin(.viewport, run.pin) orelse continue; const v = at.viewport.y; @@ -104,7 +170,8 @@ pub fn draw( cell.len = 1; } const img = storage.imageById(run.image_id) orelse continue; - const rp = run.renderPlacement(storage, &img, cw, ch) catch continue; + const target = storage.placeholderTarget(run.image_id, run.placement_id) orelse continue; + const rp = run.renderPlacement(&target.placement, &img, cw, ch) catch continue; if (rp.dest_width == 0 or rp.dest_height == 0 or rp.source_width == 0 or rp.source_height == 0) continue; ctx.place(img, .{ .x = rp.source_x, .y = rp.source_y, .w = rp.source_width, .h = rp.source_height }, .{ .x = @as(i64, at.viewport.x) * cw + rp.offset_x, @@ -122,7 +189,8 @@ pub fn draw( const placed = entry.value_ptr.*; const pin = switch (placed.location) { .pin => |pin| pin, - .virtual => continue, + // ponytail: a placement relative to another (P=/Q=, new in ghostty) is not drawn; resolve its chain if a program needs it. + .virtual, .relative => continue, }; const img = storage.images.get(entry.key_ptr.image_id) orelse continue; const at = pages.pointFromPin(.screen, pin.*) orelse continue; @@ -221,7 +289,8 @@ const Ctx = struct { fn pixelsOf(ti: *TerminalImages, gpa: std.mem.Allocator, img: gfx.Image) ?[]const u8 { const n = @as(usize, img.width) * img.height; if (n == 0) return null; - if (img.format == .rgba) return if (img.data.len == n * 4) img.data else null; + const data = img.data.bytes() orelse return null; + if (img.format == .rgba) return if (data.len == n * 4) data else null; const gop = ti.converted.getOrPut(gpa, img.id) catch return null; if (gop.found_existing) { if (gop.value_ptr.generation == img.generation) { @@ -247,10 +316,11 @@ fn convert(gpa: std.mem.Allocator, img: gfx.Image, n: usize) ?[]u8 { .gray => 1, else => return null, }; - if (img.data.len != n * depth) return null; + const data = img.data.bytes() orelse return null; + if (data.len != n * depth) return null; const out = gpa.alloc(u8, n * 4) catch return null; for (0..n) |i| { - const px = img.data[i * depth ..][0..depth]; + const px = data[i * depth ..][0..depth]; out[i * 4 ..][0..4].* = switch (depth) { 3 => .{ px[0], px[1], px[2], 255 }, 2 => .{ px[0], px[0], px[0], px[1] }, diff --git a/src/builtins.zig b/src/builtins.zig index f73c5982..d9cef8c9 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -98,11 +98,11 @@ fn isEnabled(comptime T: type) bool { /// word that is one here, or in no build. pub fn absentWhy(name: []const u8) ?[]const u8 { @setEvalBranchQuota(20000); - inline for (@typeInfo(@This()).@"struct".decls) |d| { - if (comptime @TypeOf(@field(@This(), d.name)) == type) { - const T = @field(@This(), d.name); + inline for (@typeInfo(@This()).@"struct".decl_names) |d| { + if (comptime @TypeOf(@field(@This(), d)) == type) { + const T = @field(@This(), d); if (comptime @typeInfo(T) == .@"struct" and @hasDecl(T, "run") and !isEnabled(T)) { - if (std.mem.eql(u8, d.name, name)) return if (@hasDecl(T, "gui_only")) "GUI-only" else "not in this build"; + if (std.mem.eql(u8, d, name)) return if (@hasDecl(T, "gui_only")) "GUI-only" else "not in this build"; } } } @@ -112,12 +112,12 @@ pub fn absentWhy(name: []const u8) ?[]const u8 { fn manualBuiltinCount() comptime_int { comptime { var count = 0; - for (@typeInfo(@This()).@"struct".decls) |d| { - if (@TypeOf(@field(@This(), d.name)) != type) continue; - const T = @field(@This(), d.name); + for (@typeInfo(@This()).@"struct".decl_names) |d| { + if (@TypeOf(@field(@This(), d)) != type) continue; + const T = @field(@This(), d); if (@typeInfo(T) != .@"struct" or !@hasDecl(T, "run") or !isEnabled(T)) continue; if (@TypeOf(T.run) != fn (Ctx) void) - @compileError(d.name ++ ".run must have signature fn (Ctx) void"); + @compileError(d ++ ".run must have signature fn (Ctx) void"); count += 1; } return count; @@ -129,9 +129,9 @@ fn manualBuiltinList() [manualBuiltinCount()]type { @setEvalBranchQuota(4000); var list: [manualBuiltinCount()]type = undefined; var count = 0; - for (@typeInfo(@This()).@"struct".decls) |d| { - if (@TypeOf(@field(@This(), d.name)) != type) continue; - const T = @field(@This(), d.name); + for (@typeInfo(@This()).@"struct".decl_names) |d| { + if (@TypeOf(@field(@This(), d)) != type) continue; + const T = @field(@This(), d); if (@typeInfo(T) != .@"struct" or !@hasDecl(T, "run") or !isEnabled(T)) continue; list[count] = T; count += 1; @@ -317,7 +317,7 @@ test "Exit over a ctl write or a click names every pane it asks about, a second first.file.?.saved_hash = 0; // edited: what it had is not what it has p.newScratchBelow(p.active); const second = p.panes[p.active].?; - panes.File.setContent(p, &second.file.?, try std.testing.allocator.dupe(u8, "x" ** 120)); + panes.File.setContent(p, &second.file.?, try std.testing.allocator.dupe(u8, &@as([120]u8, @splat('x')))); try std.testing.expect(second.file.?.revision != second.file.?.saved_revision); // A ctl write, or a click through exec (ctl.captured). if (clicked) p.fs.capturing = true else p.fs.no_prompt = true; @@ -341,7 +341,7 @@ test "Exit over a ctl write or a click names every pane it asks about, a second try std.testing.expect(noticed); // Edited since: only that one is named again (acme's rule). p.fs.failure_len = 0; - panes.File.setContent(p, &second.file.?, try std.testing.allocator.dupe(u8, "y" ** 120)); + panes.File.setContent(p, &second.file.?, try std.testing.allocator.dupe(u8, &@as([120]u8, @splat('y')))); try std.testing.expect(p.executeBuiltinLine(p.active, "Exit")); try std.testing.expect(!p.quit); const again = p.fs.failure[0..p.fs.failure_len]; diff --git a/src/colors.zig b/src/colors.zig index 379d1301..dd0d8938 100644 --- a/src/colors.zig +++ b/src/colors.zig @@ -205,7 +205,7 @@ const name_tint_chroma: f32 = 0.06; /// ink where that hue holds, the name reads on its ground (nameTintFloor) /// and it stands off the ink. Null when no colour of the theme will do. fn derivedNameTint(th: *const Theme, ink: [3]u8, ground: [3]u8) ?[3]u8 { - const pal = th.palette orelse [_][3]u8{th.kw} ** 16; + const pal = th.palette orelse @as([16][3]u8, @splat(th.kw)); const sources = [_][3]u8{ th.kw, pal[4], pal[5], pal[6], pal[3], pal[2], pal[1], th.num, th.str, th.box } ++ [_][3]u8{ th.column_box orelse th.num, th.box_dirty orelse th.num, th.sel_bg, th.search_bg orelse th.num } ++ [_][3]u8{ th.diagnostic_info orelse th.num, th.diagnostic_hint orelse th.num, th.diagnostic_warning orelse th.num } ++ @@ -468,28 +468,29 @@ const curated = struct { pub const dark = @import("themes/dark.zig"); }; -fn fold(comptime C: type) [@typeInfo(C).@"struct".decls.len]Theme { +fn fold(comptime C: type) [@typeInfo(C).@"struct".decl_names.len]Theme { comptime { @setEvalBranchQuota(400000); - var out: [@typeInfo(C).@"struct".decls.len]Theme = undefined; - for (@typeInfo(C).@"struct".decls, 0..) |d, i| { + var out: [@typeInfo(C).@"struct".decl_names.len]Theme = undefined; + const theme_info = @typeInfo(Theme).@"struct"; + for (@typeInfo(C).@"struct".decl_names, 0..) |d, i| { var t: Theme = undefined; - const source = @field(C, d.name).theme; - for (@typeInfo(Theme).@"struct".fields) |f| { - @field(t, f.name) = if (f.type == ?Decor and @hasField(@TypeOf(source), f.name)) decor: { + const source = @field(C, d).theme; + for (theme_info.field_names, theme_info.field_types, theme_info.field_attrs) |name, T, attrs| { + @field(t, name) = if (T == ?Decor and @hasField(@TypeOf(source), name)) decor: { // A nested literal is folded field by field too. var decor: Decor = .{}; - const given = @field(source, f.name); - for (@typeInfo(Decor).@"struct".fields) |g| if (@hasField(@TypeOf(given), g.name)) { - @field(decor, g.name) = @field(given, g.name); + const given = @field(source, name); + for (@typeInfo(Decor).@"struct".field_names) |g| if (@hasField(@TypeOf(given), g)) { + @field(decor, g) = @field(given, g); }; break :decor decor; - } else if (@hasField(@TypeOf(source), f.name)) - @field(source, f.name) - else if (f.default_value_ptr) |ptr| - @as(*const f.type, @ptrCast(@alignCast(ptr))).* + } else if (@hasField(@TypeOf(source), name)) + @field(source, name) + else if (attrs.defaultValue(T)) |value| + value else - @compileError("theme " ++ d.name ++ " is missing " ++ f.name); + @compileError("theme " ++ d ++ " is missing " ++ name); } out[i] = t; } @@ -501,7 +502,7 @@ fn fold(comptime C: type) [@typeInfo(C).@"struct".decls.len]Theme { /// takes: a faithful port (`dracula`) keeps the plain name, and helix's /// looser copy of it is still there as `dracula_helix` (the zed ones already /// carry `_zed`). -fn foldImports(comptime ours: anytype, comptime C: type) [@typeInfo(C).@"struct".decls.len]Theme { +fn foldImports(comptime ours: anytype, comptime C: type) [@typeInfo(C).@"struct".decl_names.len]Theme { comptime { @setEvalBranchQuota(400000); var out = fold(C); @@ -514,7 +515,7 @@ fn foldImports(comptime ours: anytype, comptime C: type) [@typeInfo(C).@"struct" pub const themes = fold(curated) ++ foldImports(fold(curated), @import("generated_themes")); /// The first `native_count` of `themes` are pardes's own; the rest imported. -pub const native_count = @typeInfo(curated).@"struct".decls.len; +pub const native_count = @typeInfo(curated).@"struct".decl_names.len; /// The picker's sections (`Themes`), in ring order, each running from /// the theme it names to the next section's; `NextColor` and `Theme` still @@ -677,8 +678,8 @@ pub const ChromeTheme = struct { pub fn interpolate(from: ChromeTheme, to: ChromeTheme, step: u16, steps: u16) ChromeTheme { var out: ChromeTheme = undefined; const t = @as(f32, @floatFromInt(@min(step, steps))) / @as(f32, @floatFromInt(@max(1, steps))); - inline for (@typeInfo(ChromeTheme).@"struct".fields) |field| - @field(out, field.name) = if (step == 0) @field(from, field.name) else if (step >= steps) @field(to, field.name) else mixOklab(@field(from, field.name), @field(to, field.name), t); + inline for (@typeInfo(ChromeTheme).@"struct".field_names) |name| + @field(out, name) = if (step == 0) @field(from, name) else if (step >= steps) @field(to, name) else mixOklab(@field(from, name), @field(to, name), t); return out; } }; @@ -801,14 +802,16 @@ pub fn loadThemeFile(p: *Pardes, generation: u32, bytes: []const u8, animate: bo themeFileError(p, request, error.ThemeFileTooLarge); return false; } - const source = p.gpa.dupeZ(u8, bytes) catch |err| { + const source = p.gpa.dupeSentinel(u8, bytes, 0) catch |err| { themeFileError(p, request, err); return false; }; defer p.gpa.free(source); - var diagnostics: std.zon.parse.Diagnostics = .{}; - defer diagnostics.deinit(p.gpa); - const parsed = std.zon.parse.fromSliceAlloc(Theme, p.gpa, source, &diagnostics, .{}) catch |err| { + // The parse's results live in `arena`; the theme kept owns only its name. + var arena: std.heap.ArenaAllocator = .init(p.gpa); + defer arena.deinit(); + var diagnostics: std.zon.parse.Diagnostics = undefined; + var parsed = std.zon.parse.fromSlice(Theme, .{ .gpa = p.gpa, .arena = arena.allocator(), .source = source, .diagnostics = &diagnostics }) catch |err| { if (err != error.ParseZon) themeFileError(p, request, err) else { // Which line, and what the parser wanted there. var why: [200]u8 = undefined; @@ -817,10 +820,13 @@ pub fn loadThemeFile(p: *Pardes, generation: u32, bytes: []const u8, animate: bo return false; }; if (parsed.name.len == 0 or parsed.name.len > 255) { - std.zon.parse.free(p.gpa, parsed); themeFileError(p, request, error.InvalidThemeName); return false; } + parsed.name = p.gpa.dupe(u8, parsed.name) catch |err| { + themeFileError(p, request, err); + return false; + }; const target_chrome = ChromeTheme.fromTheme(&parsed); if (animate and p.animate_theme_changes) @@ -829,7 +835,7 @@ pub fn loadThemeFile(p: *Pardes, generation: u32, bytes: []const u8, animate: bo p.chrome_animation.snap(target_chrome); const old = p.custom_theme; p.custom_theme = parsed; - if (old) |theme_value| std.zon.parse.free(p.gpa, theme_value); + if (old) |theme_value| p.gpa.free(theme_value.name); var settled: [limits.host_path_cap]u8 = undefined; @memcpy(settled[0..request.path.len], request.path); _ = p.theme_file_loaded.set(settled[0..request.path.len]); @@ -847,7 +853,7 @@ pub fn carryTheme(p: *Pardes, old: *const Pardes, index: bool) !void { const t = old.custom_theme orelse return; var copy = t; copy.name = try p.gpa.dupe(u8, t.name); - if (p.custom_theme) |mine| std.zon.parse.free(p.gpa, mine); + if (p.custom_theme) |mine| p.gpa.free(mine.name); p.custom_theme = copy; _ = p.theme_file_loaded.set(old.theme_file_loaded.get()); } @@ -931,7 +937,7 @@ fn likeness(theme_name: []const u8, name: []const u8) usize { in_order += 1; pos = at + 1; } - const inside: usize = if (name.len > 0 and std.ascii.indexOfIgnoreCase(theme_name, name) != null) name.len * 4 else 0; + const inside: usize = if (name.len > 0 and std.ascii.findIgnoreCase(theme_name, name) != null) name.len * 4 else 0; return prefix * 3 + in_order + inside; } @@ -952,7 +958,7 @@ pub fn setThemeIndex(p: *Pardes, index: usize) void { p.chrome_animation.snap(target_chrome); if (p.custom_theme) |theme_value| { p.custom_theme = null; - std.zon.parse.free(p.gpa, theme_value); + p.gpa.free(theme_value.name); } p.theme_file_loaded.clear(); if (p.theme_file_path.get().len > 0) { @@ -1264,10 +1270,12 @@ test "legacy ThemeFile documents inherit Pardes UI roles without new fields" { rest = rest[at + std.mem.indexOfScalar(u8, rest[at..], '}').? + 1 ..]; rest = std.mem.trimStart(u8, rest, " ,"); } - const source = try std.testing.allocator.dupeZ(u8, legacy.items); + const source = try std.testing.allocator.dupeSentinel(u8, legacy.items, 0); defer std.testing.allocator.free(source); - const parsed = try std.zon.parse.fromSliceAlloc(Theme, std.testing.allocator, source, null, .{}); - defer std.zon.parse.free(std.testing.allocator, parsed); + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + var diagnostics: std.zon.parse.Diagnostics = undefined; + const parsed = try std.zon.parse.fromSlice(Theme, .{ .gpa = std.testing.allocator, .arena = arena.allocator(), .source = source, .diagnostics = &diagnostics }); try std.testing.expectEqual(@as(?[3]u8, null), parsed.tag_active_bg); try std.testing.expectEqual(@as(?[3]u8, null), parsed.tag_name_fg); try std.testing.expectEqual(@as(?[3]u8, null), parsed.tag_active_name_fg); diff --git a/src/config.zig b/src/config.zig index 50009660..8166954d 100644 --- a/src/config.zig +++ b/src/config.zig @@ -2170,10 +2170,12 @@ pub const User = struct { defer gpa.free(one_path); const bytes = try std.Io.Dir.cwd().readFileAlloc(io, one_path, gpa, .limited(4096)); defer gpa.free(bytes); - const source = try gpa.dupeZ(u8, bytes); + const source = try gpa.dupeSentinel(u8, bytes, 0); defer gpa.free(source); - const parsed = try std.zon.parse.fromSliceAlloc(Sample, gpa, source, null, .{}); - defer std.zon.parse.free(gpa, parsed); + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + var diagnostics: std.zon.parse.Diagnostics = undefined; + const parsed = try std.zon.parse.fromSlice(Sample, .{ .gpa = gpa, .arena = arena.allocator(), .source = source, .diagnostics = &diagnostics }); try std.testing.expectEqualStrings("one", parsed.name); try std.testing.expectEqual([3]u8{ 1, 2, 3 }, parsed.rgb); } @@ -2239,25 +2241,26 @@ const doc_typ = struct { fn hasChordField(T: type) bool { if (@typeInfo(T) != .array or @typeInfo(@typeInfo(T).array.child) != .@"struct") return false; - for (@typeInfo(@typeInfo(T).array.child).@"struct".fields) |f| if (f.type == Chord) return true; + for (@typeInfo(@typeInfo(T).array.child).@"struct".field_types) |F| if (F == Chord) return true; return false; } /// Bound somewhere in this file: a binding, a prefix or a key list. fn bound(c: Chord) bool { const config = @import("config.zig"); - inline for (@typeInfo(config).@"struct".decls) |d| { - const v = @field(config, d.name); + inline for (@typeInfo(config).@"struct".decl_names) |d| { + const v = @field(config, d); const T = @TypeOf(v); if (T == []const Chord) { for (v) |b| if (same(b, c)) return true; } else if (T == comptime_int or T == u21 or T == u8) { // a prefix or a bare key; only the tty toggle carries Ctrl - const plain = !c.alt and !c.shift and (!c.ctrl or comptime std.mem.indexOf(u8, d.name, "toggle") != null); + const plain = !c.alt and !c.shift and (!c.ctrl or comptime std.mem.indexOf(u8, d, "toggle") != null); if (plain and v >= 0x20 and v < 0x7f and v == c.cp) return true; } else if (comptime hasChordField(T)) { - for (v) |e| inline for (@typeInfo(@TypeOf(e)).@"struct".fields) |f| - if (f.type == Chord and same(@field(e, f.name), c)) return true; + const info = @typeInfo(@TypeOf(v[0])).@"struct"; + for (v) |e| inline for (info.field_names, info.field_types) |name, F| + if (F == Chord and same(@field(e, name), c)) return true; } } return false; diff --git a/src/detached/client.zig b/src/detached/client.zig index 69ab2fdd..cf1842d9 100644 --- a/src/detached/client.zig +++ b/src/detached/client.zig @@ -1182,12 +1182,12 @@ test "detached session: a frontend is never asked to fork, write, or watch" { // One: the union a frontend decodes into has no other variant. Named // rather than counted, so re-adding `spawn` fails with the name in it. - const fields = @typeInfo(wire.ServerMsg).@"union".fields; - inline for (fields) |f| { + const fields = @typeInfo(wire.ServerMsg).@"union".field_names; + inline for (fields) |name| { for (allowed) |ok| { - if (std.mem.eql(u8, f.name, ok)) break; + if (std.mem.eql(u8, name, ok)) break; } else { - std.debug.print("ServerMsg.{s} is not an effect a frontend may perform\n", .{f.name}); + std.debug.print("ServerMsg.{s} is not an effect a frontend may perform\n", .{name}); return error.MachineLocalEffectOnTheWire; } } diff --git a/src/detached/wire.zig b/src/detached/wire.zig index c9d9b578..f1b7a1b3 100644 --- a/src/detached/wire.zig +++ b/src/detached/wire.zig @@ -20,9 +20,10 @@ const chrome_layout: u64 = 0x5e758b47fb0cf8da; comptime { @setEvalBranchQuota(10_000); var hash = std.hash.Fnv1a_64.init(); - for (@typeInfo(pardes.Chrome).@"struct".fields) |field| { - hash.update(field.name); - hash.update(@typeName(field.type)); + const info = @typeInfo(pardes.Chrome).@"struct"; + for (info.field_names, info.field_types) |name, T| { + hash.update(name); + hash.update(@typeName(T)); } if (hash.final() != chrome_layout) @compileError(std.fmt.comptimePrint("pardes.Chrome changed (layout 0x{x}): bump wire.version, then chrome_layout", .{hash.final()})); } @@ -285,21 +286,22 @@ pub const Frame = struct { region.clip > region.rect.w or region.thumb_y > region.rect.h or region.thumb_h > region.rect.h - region.thumb_y) return error.BadValue; regions.appendAssumeCapacity(region); } - inline for (@typeInfo(pardes.Chrome).@"struct".fields) |field| { - const rgb = &@field(chrome, field.name); - if (field.type == ?[3]u8) { + const info = @typeInfo(pardes.Chrome).@"struct"; + inline for (info.field_names, info.field_types) |name, T| { + const rgb = &@field(chrome, name); + if (T == ?[3]u8) { if (try r.getBool()) { rgb.* = .{ 0, 0, 0 }; for (&rgb.*.?) |*channel| channel.* = try r.getByte(); } - } else if (field.type == u8) { + } else if (T == u8) { rgb.* = try r.getByte(); - } else if (field.type == u32) { + } else if (T == u32) { rgb.* = try r.getU32(); - } else if (field.type == f32) { + } else if (T == f32) { rgb.* = @bitCast(try r.getU32()); if (!std.math.isFinite(rgb.*)) return error.BadValue; - } else if (field.type == [8]f32) { + } else if (T == [8]f32) { for (rgb) |*value| { value.* = @bitCast(try r.getU32()); if (!std.math.isFinite(value.*)) return error.BadValue; @@ -781,7 +783,7 @@ pub fn layersBound(layers: []const pardes.Layer, tags: []const pardes.Layer, reg const region_len = 1 + 1 + 4 + 8 + 1 + 2 + 2 + 1 + 2 + 4 + 4; /// The palette: each colour three bytes, a theme's optional ones a flag /// before them. -const chrome_len = @typeInfo(pardes.Chrome).@"struct".fields.len * 4 + 8 * 4; +const chrome_len = @typeInfo(pardes.Chrome).@"struct".field_names.len * 4 + 8 * 4; pub fn encodeFrameLayers(out: []u8, cols: u16, rows: u16, cursor: ?Cursor, pointer_shape: pardes.Surface.PointerShape, cells: []const pardes.Cell, prev: []const pardes.Cell, layers: []const pardes.Layer, tags: []const pardes.Layer, regions: []const pardes.Region, chrome: pardes.Chrome) Error![]const u8 { // The protocol's ceiling, enforced by the ENCODER too, and BEFORE the @@ -865,18 +867,19 @@ pub fn encodeFrameLayers(out: []u8, cols: u16, rows: u16, cursor: ?Cursor, point try w.putU32(@bitCast(region.lift)); try w.putU32(@bitCast(region.line)); } - inline for (@typeInfo(pardes.Chrome).@"struct".fields) |field| { - const rgb = @field(chrome, field.name); - if (field.type == ?[3]u8) { + const info = @typeInfo(pardes.Chrome).@"struct"; + inline for (info.field_names, info.field_types) |name, T| { + const rgb = @field(chrome, name); + if (T == ?[3]u8) { try w.putBool(rgb != null); if (rgb) |value| for (value) |channel| try w.putByte(channel); - } else if (field.type == u8) { + } else if (T == u8) { try w.putByte(rgb); - } else if (field.type == u32) { + } else if (T == u32) { try w.putU32(rgb); - } else if (field.type == f32) { + } else if (T == f32) { try w.putU32(@bitCast(rgb)); - } else if (field.type == [8]f32) { + } else if (T == [8]f32) { for (rgb) |value| try w.putU32(@bitCast(value)); } else for (rgb) |channel| try w.putByte(channel); } diff --git a/src/draw.zig b/src/draw.zig index b35d55e8..e6420ed4 100644 --- a/src/draw.zig +++ b/src/draw.zig @@ -1598,7 +1598,7 @@ test "a tag of three rows has its grip on the first, and band under it that stil test "place puts every part where the painters and layers put it, in every layout" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 30 }); defer p.deinit(); - _ = try p.setTestFile("placed\n" ** 80); + _ = try p.setTestFile(std.mem.asBytes(&@as([80][7]u8, @splat("placed\n".*)))); p.newColumn(0); p.newScratchIn(0, p.activeColumn().?); p.newScratchBelow(0); @@ -1713,7 +1713,7 @@ test "a notice wider than its band, as a shader's compile error is, draws its en _ = try p.setTestFile("text\n"); var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); defer arena.deinit(); - const long = "Shader /home/someone/shaders/test_shadertoy_invalid.glsl: error: Linking fragment stage: No function definition (body) found: " ** 3; + const long = std.mem.asBytes(&@as([3][126]u8, @splat("Shader /home/someone/shaders/test_shadertoy_invalid.glsl: error: Linking fragment stage: No function definition (body) found: ".*))); for ([_][]const u8{ "Msg " ++ long, "" }) |line| { // The Msg builtin, and the path a failed compile takes (Post.zig). if (line.len > 0) try std.testing.expect(p.executeBuiltinLine(p.active, line)) else p.setMessage(p.active, long); @@ -1952,7 +1952,7 @@ test "the focused cursor glides a jump, lands a step at once, and is exact at re if (!builtins.capabilities.lift) return error.SkipZigTest; const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 30 }); defer p.deinit(); - _ = try p.setTestFile("some text on a line\n" ** 20); + _ = try p.setTestFile(std.mem.asBytes(&@as([20][20]u8, @splat("some text on a line\n".*)))); p.settings.cursor_blink = false; var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); defer arena.deinit(); @@ -2078,7 +2078,7 @@ test "a terminal's cursor lands with scrolling output, never gliding against it" defer arena.deinit(); const ms = std.time.ns_per_ms; var now: u64 = std.time.ns_per_s; - p.update(.{ .output = .{ .pane = @intCast(term), .bytes = "line\r\n" ** 20 ++ "$ some command typed" } }); + p.update(.{ .output = .{ .pane = @intCast(term), .bytes = std.mem.asBytes(&@as([20][6]u8, @splat("line\r\n".*))) ++ "$ some command typed" } }); p.advance(now); _ = try p.render(arena.allocator()); // Enter: three lines of output scroll up, the cursor to a new prompt. @@ -2101,10 +2101,10 @@ test "a monkey over notices, prompts, tags and tiny panes at a gui's metrics nev const random = prng.random(); const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24 }); defer p.deinit(); - _ = try p.setTestFile("fuzz\n\u{754c}\u{754c} wide\n" ** 20); + _ = try p.setTestFile(std.mem.asBytes(&@as([20][17]u8, @splat("fuzz\n\u{754c}\u{754c} wide\n".*)))); var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); defer arena.deinit(); - const words = [_][]const u8{ "error:", "\u{754c}", "x", "Shader /tmp/a.glsl:", "e\u{301}", "\t", "long-" ** 20, " " }; + const words = [_][]const u8{ "error:", "\u{754c}", "x", "Shader /tmp/a.glsl:", "e\u{301}", "\t", std.mem.asBytes(&@as([20][5]u8, @splat("long-".*))), " " }; const commands = [_][]const u8{ "New", "Newcol", "Collapse", "Tagbottom", "TreeContext", "Wrap", "Find", "Del", "FocusTint", "Debug" }; var text: std.ArrayListUnmanaged(u8) = .empty; defer text.deinit(std.testing.allocator); @@ -2143,7 +2143,7 @@ test "a monkey over notices, prompts, tags and tiny panes at a gui's metrics nev // A tag of several rows. 5 => if (p.panes[p.active]) |pane| { text.clearRetainingCapacity(); - for (0..random.uintAtMost(usize, 5)) |_| try text.appendSlice(std.testing.allocator, if (random.boolean()) " Look\nmore \u{754c}" else "\n" ++ "x" ** 150); + for (0..random.uintAtMost(usize, 5)) |_| try text.appendSlice(std.testing.allocator, if (random.boolean()) " Look\nmore \u{754c}" else "\n" ++ &@as([150]u8, @splat('x'))); if (pane.tag.own) |own| std.testing.allocator.free(own); pane.tag.own = try std.testing.allocator.dupe(u8, text.items); }, @@ -2173,7 +2173,7 @@ test "a wide glyph cut by a tag's or a notice's edge is joined into the grid as defer arena.deinit(); const pane = p.panes[p.active].?; // Both alignments, so one of them puts a wide glyph across each edge. - for ([_][]const u8{ "\u{754c}" ** 30, "x" ++ "\u{754c}" ** 30 }) |wide| { + for ([_][]const u8{ std.mem.asBytes(&@as([30][3]u8, @splat("\u{754c}".*))), "x" ++ std.mem.asBytes(&@as([30][3]u8, @splat("\u{754c}".*))) }) |wide| { if (pane.tag.own) |own| std.testing.allocator.free(own); pane.tag.own = try std.testing.allocator.dupe(u8, wide); var message: [200]u8 = undefined; @@ -2201,7 +2201,7 @@ test "a body with context rows is painted once, and the grid's rows are what a p if (comptime !@import("syntax.zig").enabled) return error.SkipZigTest; const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 60, .rows = 16 }); defer p.deinit(); - const pane = try p.setTestFile("pub const Box = struct {\n pub fn run() void {\n" ++ (" // body line\n" ** 30) ++ " }\n};\n"); + const pane = try p.setTestFile("pub const Box = struct {\n pub fn run() void {\n" ++ (std.mem.asBytes(&@as([30][21]u8, @splat(" // body line\n".*)))) ++ " }\n};\n"); p.gpa.free(pane.file.?.path); pane.file.?.path = try p.gpa.dupe(u8, "/test.zig"); if (!panes.File.supportsContext(pane)) return error.SkipZigTest; @@ -2250,7 +2250,7 @@ test "a body with context rows is painted once, and the grid's rows are what a p /// Two columns, the file in the left one and a shell in the right, the /// right one focused with its cursor settled. fn twoColumns(p: *Pardes, arena: *std.heap.ArenaAllocator) !void { - _ = try p.setTestFile("some text on a line\n" ** 6); + _ = try p.setTestFile(std.mem.asBytes(&@as([6][20]u8, @splat("some text on a line\n".*)))); _ = try p.newShell(1, ""); try std.testing.expect(layout.splitColumn(p, 0, 1, false)); p.sync(); @@ -2386,7 +2386,7 @@ test "a pane focus reaches brightens on the same spring the one it leaves dims o if (!builtins.capabilities.lift) return error.SkipZigTest; const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24 }); defer p.deinit(); - _ = try p.setTestFile("some text on a line\n" ** 4); + _ = try p.setTestFile(std.mem.asBytes(&@as([4][20]u8, @splat("some text on a line\n".*)))); p.newScratchBelow(0); p.settings.inactive_dim = 40; p.settings.motion = .smooth; diff --git a/src/dump.zig b/src/dump.zig index 402918c4..545d09ec 100644 --- a/src/dump.zig +++ b/src/dump.zig @@ -421,9 +421,9 @@ pub const Parsed = struct { pub fn check(gpa: std.mem.Allocator, bytes: []const u8, why: []u8) !void { var arena: std.heap.ArenaAllocator = .init(gpa); defer arena.deinit(); - const source = try arena.allocator().dupeZ(u8, bytes); - var diag: std.zon.parse.Diagnostics = .{}; - const state = std.zon.parse.fromSliceAlloc(State, arena.allocator(), source, &diag, .{ .free_on_error = false }) catch |err| { + const source = try arena.allocator().dupeSentinel(u8, bytes, 0); + var diag: std.zon.parse.Diagnostics = undefined; + const state = std.zon.parse.fromSlice(State, .{ .gpa = gpa, .arena = arena.allocator(), .source = source, .diagnostics = &diag }) catch |err| { const said = pardes.Messages.zonWhy(&diag, why[0 .. why.len - 1]); if (said.ptr != why.ptr) @memcpy(why[0..said.len], said); why[said.len] = 0; @@ -436,21 +436,13 @@ pub fn readZon(gpa: std.mem.Allocator, bytes: []const u8, label: []const u8) !Pa var parsed: Parsed = .{ .value = undefined, .arena = .init(gpa) }; errdefer parsed.deinit(); const arena = parsed.arena.allocator(); - const source = try gpa.dupeZ(u8, bytes); + const source = try gpa.dupeSentinel(u8, bytes, 0); defer gpa.free(source); - parsed.value = if (builtin.os.tag == .emscripten or builtin.os.tag == .freestanding) - std.zon.parse.fromSliceAlloc(State, arena, source, null, .{ .free_on_error = false }) catch |err| { - if (err == error.ParseZon) log.err("parse dump {s}: {s}", .{ label, @errorName(err) }); - return err; - } - else blk: { - var diag: std.zon.parse.Diagnostics = .{}; - defer diag.deinit(arena); - break :blk std.zon.parse.fromSliceAlloc(State, arena, source, &diag, .{ .free_on_error = false }) catch |err| { - if (err == error.ParseZon) log.err("parse dump {s}: {f}", .{ label, diag }); - return err; - }; + var diag: std.zon.parse.Diagnostics = undefined; + parsed.value = std.zon.parse.fromSlice(State, .{ .gpa = gpa, .arena = arena, .source = source, .diagnostics = &diag }) catch |err| { + if (err == error.ParseZon) log.err("{f}", .{diag.fmt(label)}); + return err; }; try validate(parsed.value); return parsed; diff --git a/src/esp32p4.zig b/src/esp32p4.zig index 6772e75d..ed18efd9 100644 --- a/src/esp32p4.zig +++ b/src/esp32p4.zig @@ -506,7 +506,7 @@ fn apply(c: *pardes.Pardes, ev: vaxis.Event) void { c.update(.pointer_leave); dirty = true; }, - .focus_in, .mouse_leave => {}, + .focus_in, .mouse_leave, .cursor_position => {}, // Capability replies. vaxis's own Loop sets these fields directly (`Loop.zig:377-403`); // with no Loop, this is where they land. DA1 is the terminator: every terminal answers it // last, so it is the signal that the whole handshake is in and the detected features can be diff --git a/src/esp32p4/input_rescue.zig b/src/esp32p4/input_rescue.zig index ba6974d2..d7556d46 100644 --- a/src/esp32p4/input_rescue.zig +++ b/src/esp32p4/input_rescue.zig @@ -245,7 +245,7 @@ test "a long transmit does not lose the input that arrives during it" { defer port.sent.deinit(std.testing.allocator); var ring: Ring = .{}; - const frame = "\x1b[1;1H" ++ "x" ** 400; + const frame = "\x1b[1;1H" ++ &@as([400]u8, @splat('x')); try std.testing.expectEqual(@as(u32, 0), pump(&port, &ring, frame, 1_000_000)); // Every output byte went out, in order. diff --git a/src/esp32p4/selftest.zig b/src/esp32p4/selftest.zig index 97b43059..19b71e90 100644 --- a/src/esp32p4/selftest.zig +++ b/src/esp32p4/selftest.zig @@ -270,7 +270,7 @@ export fn zig_main() noreturn { const typed = "the quick brown fox jumps over the lazy dog, and then some more besides"; var port: FakePort = .{ .tx_cap = 2, .incoming = typed }; var ring: input_rescue.Ring = .{}; - const frame = "\x1b[1;1H" ++ "x" ** 300; + const frame = "\x1b[1;1H" ++ &@as([300]u8, @splat('x')); const abandoned = input_rescue.pump(&port, &ring, frame, 1_000_000); check("the frame went out whole", abandoned == 0 and port.sent == frame.len); @@ -677,7 +677,7 @@ pub fn statPath(io: std.Io, path: []const u8, options: std.Io.Dir.StatFileOption } test "a path with a part over 255 bytes is NameTooLong, never a panic" { - const long = "/tmp/" ++ "x" ** 300 ++ "/f"; + const long = "/tmp/" ++ &@as([300]u8, @splat('x')) ++ "/f"; try std.testing.expectError(error.NameTooLong, statPath(std.testing.io, long, .{})); } @@ -1152,7 +1152,7 @@ pub fn find(arena: std.mem.Allocator, dir: []const u8, pat: []const u8, out: []u notes.skipped += 1; continue; }) orelse break; - if (std.ascii.indexOfIgnoreCase(e.basename, pat) != null) { + if (std.ascii.findIgnoreCase(e.basename, pat) != null) { hits[hits_len] = try arena.dupe(u8, e.path); hits_len += 1; } @@ -1167,7 +1167,7 @@ pub fn find(arena: std.mem.Allocator, dir: []const u8, pat: []const u8, out: []u } else { for (sources) |s| { if (hits_len >= hits.len) break; - if (std.ascii.indexOfIgnoreCase(std.fs.path.basename(s.path), pat) != null) { + if (std.ascii.findIgnoreCase(std.fs.path.basename(s.path), pat) != null) { hits[hits_len] = s.path; hits_len += 1; } @@ -1201,7 +1201,7 @@ fn grepText(path: []const u8, text: []const u8, pat: []const u8, out: []u8, budg while (it.next()) |raw| { line += 1; if (result.hits >= budget) break; - const at = std.ascii.indexOfIgnoreCase(raw, pat) orelse continue; + const at = std.ascii.findIgnoreCase(raw, pat) orelse continue; const ln = std.mem.trimEnd(u8, raw, " \t\r"); var cut = @min(ln.len, 200); while (cut > 0 and cut < ln.len and ln[cut] & 0xc0 == 0x80) cut -= 1; diff --git a/src/gui/Post.zig b/src/gui/Post.zig index fc256135..8d0e14d9 100644 --- a/src/gui/Post.zig +++ b/src/gui/Post.zig @@ -610,13 +610,13 @@ const GhosttyUniforms = extern struct { }; test "the uniform block is ghostty's, offset for offset, and the prefix names it in that order" { - const ours = @typeInfo(Uniforms).@"struct".fields; - const theirs = @typeInfo(GhosttyUniforms).@"struct".fields; - try std.testing.expectEqual(theirs.len, ours.len); + const ours = @typeInfo(Uniforms).@"struct"; + const theirs = @typeInfo(GhosttyUniforms).@"struct"; + try std.testing.expectEqual(theirs.field_names.len, ours.field_names.len); try std.testing.expectEqual(@sizeOf(GhosttyUniforms), @sizeOf(Uniforms)); - inline for (ours, theirs) |a, b| { - try std.testing.expectEqual(@offsetOf(GhosttyUniforms, b.name), @offsetOf(Uniforms, a.name)); - try std.testing.expectEqual(b.type, a.type); + inline for (ours.field_names, ours.field_types, theirs.field_names, theirs.field_types) |a, a_type, b, b_type| { + try std.testing.expectEqual(@offsetOf(GhosttyUniforms, b), @offsetOf(Uniforms, a)); + try std.testing.expectEqual(b_type, a_type); } // By NAME: iSelectionForegroundColor sits where ghostty's Zig says // selection_background, which is where its GLSL puts the foreground. @@ -633,7 +633,7 @@ test "the uniform block is ghostty's, offset for offset, and the prefix names it .{ "vec3", "iBackgroundColor" }, .{ "vec3", "iForegroundColor" }, .{ "vec3", "iCursorColor" }, .{ "vec3", "iCursorText" }, .{ "vec3", "iSelectionForegroundColor" }, .{ "vec3", "iSelectionBackgroundColor" }, }; - try std.testing.expectEqual(ours.len, glsl.len); + try std.testing.expectEqual(ours.field_names.len, glsl.len); // Its three blocks (Globals, Palette, Colors) read as one, in order. const start = std.mem.indexOf(u8, prefix, "uniform Globals {").?; const end = std.mem.indexOf(u8, prefix, "uniform PardesPost {").?; diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 5a026664..b8687fd3 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -25,11 +25,7 @@ const ninep_io = @import("../9p_io.zig"); const detached_client = @import("../detached/client.zig"); const tracy = @import("../tracy.zig"); -pub const c = @cImport({ - @cDefine("SDL_DISABLE_OLD_NAMES", "1"); - @cInclude("SDL3/SDL.h"); - @cInclude("font.h"); -}); +pub const c = @import("gui_c"); // SDL3 and font.h, translated by build.zig const host_io = @import("../host_io.zig"); extern "c" fn setenv(name: [*:0]const u8, value: [*:0]const u8, overwrite: c_int) c_int; @@ -4806,7 +4802,7 @@ fn dumpThemes(ctx: ?*anyopaque, pane: u8) void { } fn putClipboard(gpa: std.mem.Allocator, text: []const u8) void { - const z = gpa.dupeZ(u8, text) catch return; + const z = gpa.dupeSentinel(u8, text, 0) catch return; defer gpa.free(z); _ = c.SDL_SetClipboardText(z.ptr); } @@ -5131,7 +5127,7 @@ test "a wheel over codex in a terminal reaches its pty as the mouse reports it a wheelAt(&g, &in, .{ .y = 1, .integer_y = 1 }, mc); try std.testing.expectEqualStrings("\x1b[<64;6;4M", try Sent.take(core, &sent)); wheelAt(&g, &in, .{ .y = -3, .integer_y = -3 }, mc); - try std.testing.expectEqualStrings("\x1b[<65;6;4M" ** 3, try Sent.take(core, &sent)); + try std.testing.expectEqualStrings(std.mem.asBytes(&@as([3][10]u8, @splat("\x1b[<65;6;4M".*))), try Sent.take(core, &sent)); try std.testing.expectEqual(@as(i32, 0), g.scroll_notch); try std.testing.expect(g.scroll_pane == null); // A touchpad's fractions add up to a turn. @@ -7157,7 +7153,7 @@ test "every pixel of a grip column is band, button or ring, and the button sits const gpa = std.testing.allocator; const core = try pardes.Pardes.init(gpa, .{ .cols = 60, .rows = 20 }); defer core.deinit(); - const pane = try core.setTestFile("text\n" ** 60); + const pane = try core.setTestFile(std.mem.asBytes(&@as([60][5]u8, @splat("text\n".*)))); pane.tag.own = try gpa.dupe(u8, "second\nthird"); core.newScratchBelow(0); for ([_]struct { w: u32, h: u32, tag: u32 }{ .{ .w = 10, .h = 20, .tag = 12 }, .{ .w = 17, .h = 35, .tag = 30 }, .{ .w = 9, .h = 19, .tag = 15 }, .{ .w = 12, .h = 24, .tag = 24 } }) |m| for ([_]bool{ false, true }) |bottom| for ([_]usize{ 0, 1 }) |focus| for ([_]bool{ false, true }) |dirty| { @@ -10156,7 +10152,7 @@ test "the selection glows round its block, on the body only, fading in over 100 const gpa = std.testing.allocator; const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 24 }); defer core.deinit(); - _ = try core.setTestFile("some text on a line\n" ** 30); + _ = try core.setTestFile(std.mem.asBytes(&@as([30][20]u8, @splat("some text on a line\n".*)))); core.settings.selection_glow = true; pardes.test_api.sync(core); const s = try core.render(core.scratch.allocator()); @@ -10206,7 +10202,7 @@ test "a hovered word glows along its foot, never over the cursor, fading in over const gpa = std.testing.allocator; const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 24 }); defer core.deinit(); - _ = try core.setTestFile("some text on a line\n" ** 30); + _ = try core.setTestFile(std.mem.asBytes(&@as([30][20]u8, @splat("some text on a line\n".*)))); core.settings.hover_glow = true; pardes.test_api.sync(core); const s = try core.render(core.scratch.allocator()); @@ -10256,7 +10252,7 @@ test "occlusion shades each body's edges, inside it, never a tag, a grip or the const gpa = std.testing.allocator; const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 24 }); defer core.deinit(); - _ = try core.setTestFile("some text on a line\n" ** 30); + _ = try core.setTestFile(std.mem.asBytes(&@as([30][20]u8, @splat("some text on a line\n".*)))); core.settings.occlusion = true; pardes.test_api.sync(core); const s = try core.render(core.scratch.allocator()); @@ -10295,7 +10291,7 @@ test "a body tells its first line, and lapis's dots under it move a quarter as f const gpa = std.testing.allocator; const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 24 }); defer core.deinit(); - const pane = try core.setTestFile("line\n" ** 80); + const pane = try core.setTestFile(std.mem.asBytes(&@as([80][5]u8, @splat("line\n".*)))); pane.scrollBy(8); try std.testing.expect(core.executeBuiltinLine(0, "Theme lapis")); core.settings.parallax = true; diff --git a/src/host_io.zig b/src/host_io.zig index a90c903d..d789a77d 100644 --- a/src/host_io.zig +++ b/src/host_io.zig @@ -172,7 +172,7 @@ pub const Lsp = struct { const declared_path = if (file) |f| f.path else ""; const path = try gpa.dupe(u8, filesystem.localPath(declared_path) orelse declared_path); errdefer gpa.free(path); - const source = try gpa.dupeZ(u8, if (file) |f| f.content else ""); + const source = try gpa.dupeSentinel(u8, if (file) |f| f.content else "", 0); errdefer gpa.free(source); const arg = try gpa.dupe(u8, req.arg); errdefer gpa.free(arg); @@ -210,7 +210,7 @@ pub const Lsp = struct { if (f.output != null) continue; const local = filesystem.localPath(f.path) orelse continue; const other_path = try gpa.dupe(u8, local); - const other_source = gpa.dupeZ(u8, f.content) catch |err| { + const other_source = gpa.dupeSentinel(u8, f.content, 0) catch |err| { gpa.free(other_path); return err; }; @@ -785,7 +785,7 @@ pub const Shell = struct { var dir_buf: [4096]u8 = undefined; const dir = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)]; var path: [4200:0]u8 = undefined; - const p = try std.fmt.bufPrintZ(&path, "{s}/mysh", .{dir}); + const p = try std.fmt.bufPrintSentinel(&path, "{s}/mysh", .{dir}, 0); try std.testing.expectEqual(Family.bash, familyOf(p.ptr)); try std.testing.expectEqual(Family.none, familyOf("/bin/sh")); } @@ -1662,7 +1662,7 @@ pub fn forkShell( test "shell spawn rejects invalid directories before creating a child" { const rcs: Shell.PromptFiles = .{}; try std.testing.expectError(error.InvalidPath, forkShell(null, 0, &rcs, "/bin/sh", "/tmp\x00/ignored", 24, 80, null)); - const too_long = [_]u8{'x'} ** 4096; + const too_long = @as([4096]u8, @splat('x')); try std.testing.expectError(error.NameTooLong, forkShell(null, 0, &rcs, "/bin/sh", &too_long, 24, 80, null)); var tmp = std.testing.tmpDir(.{}); @@ -1675,7 +1675,7 @@ test "shell spawn rejects invalid directories before creating a child" { try std.testing.expectError(error.NotDir, forkShell(null, 0, &rcs, "/bin/sh", file, 24, 80, null)); const explicit_file = try std.fmt.bufPrint(&path_buf, "/n/os{s}/file", .{directory}); try std.testing.expectError(error.NotDir, forkShell(null, 0, &rcs, "/bin/sh", explicit_file, 24, 80, null)); - const missing = try std.fmt.bufPrint(&path_buf, "{s}/missing/" ++ ("child/" ** 50), .{directory}); + const missing = try std.fmt.bufPrint(&path_buf, "{s}/missing/" ++ (std.mem.asBytes(&@as([50][6]u8, @splat("child/".*)))), .{directory}); try std.testing.expect(missing.len > 256); try std.testing.expectError(error.FileNotFound, forkShell(null, 0, &rcs, "/bin/sh", missing, 24, 80, null)); } @@ -1720,7 +1720,7 @@ test "shell spawn uses an explicit OS directory longer than 256 bytes" { if (!haveFile("/bin/sh")) return error.SkipZigTest; var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); - const sub_path = "nested-directory-with-more-than-forty-characters/" ** 7; + const sub_path = std.mem.asBytes(&@as([7][49]u8, @splat("nested-directory-with-more-than-forty-characters/".*))); try tmp.dir.createDirPath(std.testing.io, sub_path); var directory_buf: [4096]u8 = undefined; const directory = directory_buf[0..try tmp.dir.realPathFile(std.testing.io, sub_path, &directory_buf)]; @@ -1801,7 +1801,7 @@ test "shell cwd rejects truncation and preserves an owned child path longer than const io = std.testing.io; var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); - const nested = "nested-directory-with-more-than-forty-characters/" ** 24; + const nested = std.mem.asBytes(&@as([24][49]u8, @splat("nested-directory-with-more-than-forty-characters/".*))); try tmp.dir.createDirPath(io, nested); var path_buf: [pardes.memory.limits.host_path_cap + 1]u8 = undefined; const directory = path_buf[0..try tmp.dir.realPathFile(io, nested, &path_buf)]; diff --git a/src/image.zig b/src/image.zig index 72520ad6..8bf9de08 100644 --- a/src/image.zig +++ b/src/image.zig @@ -242,11 +242,11 @@ pub const GlyphArt = struct { const glyphs_ascii = glyphs ++ ascii_glyphs; fn matchCell(cell: *const [64][3]u8, pal: Palette, gset: []const Glyph) Cell { - var counts = [_]u16{0} ** 16; + var counts = @as([16]u16, @splat(0)); for (cell) |px| counts[nearest(px, pal)] += 1; var cand: [4]u4 = undefined; var ncand: usize = 0; - var used = [_]bool{false} ** 16; + var used = @as([16]bool, @splat(false)); while (ncand < 4) : (ncand += 1) { var best: ?usize = null; for (counts, 0..) |c, i| { @@ -432,7 +432,7 @@ pub const GlyphArt = struct { test "render: tiny image produces a grid within bounds" { const a = std.testing.allocator; // 2x2 checker, RGBA - var img = [_]u8{0} ** (2 * 2 * 4); + var img = @as([2 * 2 * 4]u8, @splat(0)); img[0] = 255; img[1] = 255; img[2] = 255; diff --git a/src/linux/v9fs.zig b/src/linux/v9fs.zig index 5e031bfe..15945e7b 100644 --- a/src/linux/v9fs.zig +++ b/src/linux/v9fs.zig @@ -64,11 +64,11 @@ pub fn helperPath(buf: []u8) ![:0]u8 { const path = if (std.c.getenv("PARDES_V9FS_HELPER")) |env| blk: { const override = std.mem.span(env); if (!std.fs.path.isAbsolute(override)) return error.AbsoluteHelperPathRequired; - break :blk try std.fmt.bufPrintZ(buf, "{s}", .{override}); + break :blk try std.fmt.bufPrintSentinel(buf, "{s}", .{override}, 0); } else blk: { var own: [4096]u8 = undefined; const parent = std.fs.path.dirname(try selfPath(&own)) orelse return error.ExecutablePathUnavailable; - break :blk try std.fmt.bufPrintZ(buf, "{s}/{s}", .{ parent, executable }); + break :blk try std.fmt.bufPrintSentinel(buf, "{s}/{s}", .{ parent, executable }, 0); }; if (std.c.access(path.ptr, 1) != 0) return error.V9fsHelperNotFound; return path; diff --git a/src/locations.zig b/src/locations.zig index 745393e5..2828566d 100644 --- a/src/locations.zig +++ b/src/locations.zig @@ -587,12 +587,13 @@ pub const Config = struct { const key = token[0..colon]; const value = token[colon + 1 ..]; var found = false; - inline for (@typeInfo(Config).@"struct".fields) |field| { - if (std.mem.eql(u8, key, field.name)) { - @field(result, field.name) = switch (@typeInfo(field.type)) { + const info = @typeInfo(Config).@"struct"; + inline for (info.field_names, info.field_types) |name, T| { + if (std.mem.eql(u8, key, name)) { + @field(result, name) = switch (@typeInfo(T)) { .bool => if (std.mem.eql(u8, value, "on")) true else if (std.mem.eql(u8, value, "off")) false else return error.ExpectedOnOrOff, - .int => std.fmt.parseInt(field.type, value, 10) catch return error.InvalidContext, - .@"enum" => std.meta.stringToEnum(field.type, value) orelse return error.InvalidLayout, + .int => std.fmt.parseInt(T, value, 10) catch return error.InvalidContext, + .@"enum" => std.meta.stringToEnum(T, value) orelse return error.InvalidLayout, else => @compileError("unsupported location setting type"), }; found = true; @@ -604,11 +605,12 @@ pub const Config = struct { } pub fn write(config: Config, writer: *std.Io.Writer) !void { - inline for (@typeInfo(Config).@"struct".fields, 0..) |field, index| { + const info = @typeInfo(Config).@"struct"; + inline for (info.field_names, info.field_types, 0..) |name, T, index| { if (index > 0) try writer.writeByte(' '); - try writer.writeAll(field.name ++ ":"); - const value = @field(config, field.name); - switch (@typeInfo(field.type)) { + try writer.writeAll(name ++ ":"); + const value = @field(config, name); + switch (@typeInfo(T)) { .bool => try writer.writeAll(if (value) "on" else "off"), .int => try writer.print("{d}", .{value}), .@"enum" => try writer.writeAll(@tagName(value)), @@ -809,11 +811,11 @@ test "locations cache bounds memory and entries and evicts least recently used" try std.testing.expectEqual(@as(usize, 2), cache.len); try std.testing.expect(cache.bytes <= 40); try std.testing.expectEqualStrings("b.unknown", cache.entries[0].path); - try std.testing.expectError(error.SourceTooLarge, cache.getBounded(gpa, "large.unknown", "x" ** 41, false, false, 40)); + try std.testing.expectError(error.SourceTooLarge, cache.getBounded(gpa, "large.unknown", &@as([41]u8, @splat('x')), false, false, 40)); try std.testing.expectEqual(@as(usize, 2), cache.len); if (syntax.supportsPath("large.zig")) { const before = cache.analyses; - try std.testing.expectError(error.SourceTooLarge, cache.getBounded(gpa, "large.zig", "x" ** 25, true, true, 40)); + try std.testing.expectError(error.SourceTooLarge, cache.getBounded(gpa, "large.zig", &@as([25]u8, @splat('x')), true, true, 40)); try std.testing.expectEqual(before, cache.analyses); } cache.deinit(gpa); diff --git a/src/look.zig b/src/look.zig index 1065cb02..f9c470cf 100644 --- a/src/look.zig +++ b/src/look.zig @@ -671,7 +671,7 @@ pub fn runSearch(p: *Pardes, id: usize, pat_raw: []const u8, kind: Search, start const cl: usize = @intCast(@max(0, pane.body.cur_row)); const cc: usize = @intCast(@max(0, pane.body.cur_col)); for (lines, 0..) |ln, i| { - const at = std.ascii.indexOfIgnoreCase(ln, pat) orelse continue; + const at = std.ascii.findIgnoreCase(ln, pat) orelse continue; const row = try std.fmt.allocPrint(arena, "{s}:{d}:{d}{c}{d} {s}\n", .{ loc, i + 1, at + 1, config.range_sep, at + pat.len, std.mem.trimEnd(u8, ln, " \t"), }); @@ -1273,7 +1273,7 @@ fn missText(text: []const u8, buf: *[miss_path_cap + "…".len]u8) []const u8 { test "a miss names a long path by its start and its end, its middle given up to …" { var cut: [miss_path_cap + "…".len]u8 = undefined; - const long = "/home/someone/" ++ "deep/" ** 80 ++ "the-file.zig"; + const long = "/home/someone/" ++ std.mem.asBytes(&@as([80][5]u8, @splat("deep/".*))) ++ "the-file.zig"; const said = missText(long, &cut); try std.testing.expect(said.len <= miss_path_cap); try std.testing.expect(std.mem.startsWith(u8, said, "/home/someone/")); @@ -2185,7 +2185,7 @@ test "Look ignores missing and out of bounds pane addresses" { test "a pointer resting where a look-hover found nothing does not wake the core every frame" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24 }); defer p.deinit(); - _ = try p.setTestFile(" \n" ** 30); + _ = try p.setTestFile(std.mem.asBytes(&@as([30][6]u8, @splat(" \n".*)))); p.sync(); const r = p.rects[p.active]; // Resting on blanks in the body: a wait, then nothing to open. diff --git a/src/lsp/lsp.zig b/src/lsp/lsp.zig index 96d42bbd..4a70efe5 100644 --- a/src/lsp/lsp.zig +++ b/src/lsp/lsp.zig @@ -92,7 +92,7 @@ else pub const backend_name = "lsp-client"; pub const supports: std.EnumSet(Kind) = blk: { - var s: std.EnumSet(Kind) = .initEmpty(); + var s: std.EnumSet(Kind) = .empty; for (0..backends.len) |i| s.setUnion(backends[i].supports); break :blk s; }; diff --git a/src/lsp/lsp_client.zig b/src/lsp/lsp_client.zig index 54bbaa79..b396879b 100644 --- a/src/lsp/lsp_client.zig +++ b/src/lsp/lsp_client.zig @@ -159,7 +159,7 @@ pub const specs = [_]Spec{ /// answered per connection; a kind its server never advertised simply returns /// no rows, which the harness reports as CLAIMED-EMPTY per language — honest, /// since the claim here is about the protocol, not about every server. -pub const supports: std.EnumSet(lsp.Kind) = .initFull(); +pub const supports: std.EnumSet(lsp.Kind) = .full; /// Routing: an extension in the table whose spec is not disabled by its env /// var. Deliberately does NOT probe for the binary — this runs on the Tab diff --git a/src/macos.zig b/src/macos.zig index 20463481..37db0abd 100644 --- a/src/macos.zig +++ b/src/macos.zig @@ -724,7 +724,7 @@ fn initCore(runtime: ?*const Runtime, cols_arg: u16, rows_arg: u16) !void { // in Debug, libc's malloc otherwise. libc's measured at least as fast as // std.heap.smp_allocator everywhere and faster on MuPDF's page-sized // rasters, so this shell no longer differs. - const gpa = if (builtin.mode == .Debug) debug_gpa.allocator() else std.heap.c_allocator; + const gpa = if (builtin.mode == .debug) debug_gpa.allocator() else std.heap.c_allocator; const allocs = pardes.memory.init(gpa); errdefer pardes.memory.deinit(); @@ -858,7 +858,7 @@ export fn pardes_deinit() void { st.gpa.destroy(st.threaded); pardes.memory.deinit(); // Leaks are logged and do not fail, as std.start treats the others'. - if (builtin.mode == .Debug) { + if (builtin.mode == .debug) { _ = debug_gpa.deinit(); debug_gpa = .init; } @@ -2871,22 +2871,22 @@ test "pardes.h matches the Zig boundary" { try expectEqual(@offsetOf(c.pardes_cell_s, "len"), @offsetOf(Cell, "len")); try expectEqual(@offsetOf(c.pardes_cell_s, "flags"), @offsetOf(Cell, "flags")); try expectEqual(@sizeOf(c.pardes_scene_s), @sizeOf(Scene)); - inline for (@typeInfo(Scene).@"struct".fields) |field| - try expectEqual(@offsetOf(c.pardes_scene_s, field.name), @offsetOf(Scene, field.name)); + inline for (@typeInfo(Scene).@"struct".field_names) |name| + try expectEqual(@offsetOf(c.pardes_scene_s, name), @offsetOf(Scene, name)); try expectEqual(@sizeOf(c.pardes_panel_box_s), @sizeOf(PanelBox)); - inline for (@typeInfo(PanelBox).@"struct".fields) |field| - try expectEqual(@offsetOf(c.pardes_panel_box_s, field.name), @offsetOf(PanelBox, field.name)); + inline for (@typeInfo(PanelBox).@"struct".field_names) |name| + try expectEqual(@offsetOf(c.pardes_panel_box_s, name), @offsetOf(PanelBox, name)); try expectEqual(@sizeOf(c.pardes_panel_track_s), @sizeOf(PanelTrack)); - inline for (@typeInfo(PanelTrack).@"struct".fields) |field| { - const c_name = comptime if (std.mem.eql(u8, field.name, "motion")) + inline for (@typeInfo(PanelTrack).@"struct".field_names) |name| { + const c_name = comptime if (std.mem.eql(u8, name, "motion")) "reserved0" else - field.name; - try expectEqual(@offsetOf(c.pardes_panel_track_s, c_name), @offsetOf(PanelTrack, field.name)); + name; + try expectEqual(@offsetOf(c.pardes_panel_track_s, c_name), @offsetOf(PanelTrack, name)); } try expectEqual(@sizeOf(c.pardes_image_s), @sizeOf(Image)); - inline for (@typeInfo(Image).@"struct".fields) |field| - try expectEqual(@offsetOf(c.pardes_image_s, field.name), @offsetOf(Image, field.name)); + inline for (@typeInfo(Image).@"struct".field_names) |name| + try expectEqual(@offsetOf(c.pardes_image_s, name), @offsetOf(Image, name)); try expectEqual(@sizeOf(c.pardes_runtime_s), @sizeOf(Runtime)); try expectEqual(@as(u32, c.PARDES_COLOR_DEFAULT), color_default); @@ -3177,7 +3177,7 @@ test "mac tag layer ABI preserves logical capacity and physical grip" { }); try std.testing.expectEqual(@as(u32, 11), pardes_tag_layer_value(0, 8)); try std.testing.expectEqual(@as(u8, 'Z'), pardes_tag_layer_cells(0).?[11].text[0]); - var canonical: [24]Cell = @splat(encodeCell(.{ .text = .{'G'} ++ .{0} ** 6, .len = 1, .default = false })); + var canonical: [24]Cell = @splat(encodeCell(.{ .text = .{ 'G', 0, 0, 0, 0, 0, 0 }, .len = 1, .default = false })); var source: [24]pardes.Cell = @splat(.{}); blankTagCells(&canonical, 8, 3, &source, &core.surface.tag_layers); try std.testing.expectEqual(@as(u8, 'G'), canonical[9].text[0]); diff --git a/src/main.zig b/src/main.zig index 26259b43..e3bae75f 100644 --- a/src/main.zig +++ b/src/main.zig @@ -464,6 +464,12 @@ fn nativeMain(init: std.process.Init) !void { } opts.tty_only = explicit_tty or session_only; opts.mounts = mounts[0..mounts_len]; + // `zig build run-isolated` with nothing named: something to look at on + // arrival, read out of the binary itself. + if (pardes.isolated and positional == null) { + session_only = false; + positional = "src/pardes.zig"; + } if (detach != null and attach != null) badArgs(init.io, "--detach and --attach are opposites: one runs the session, the other joins one", .{}); // --wait waits on the pane a FILE opens: with none there is nothing to diff --git a/src/memory.zig b/src/memory.zig index abfd40f6..48403c55 100644 --- a/src/memory.zig +++ b/src/memory.zig @@ -38,7 +38,7 @@ pub const limits = struct { }; const Allocator = std.mem.Allocator; -const debug_enabled = builtin.mode == .Debug; +const debug_enabled = builtin.mode == .debug; pub const Allocators = struct { pardes: Allocator, diff --git a/src/modal.zig b/src/modal.zig index 50e0ddf4..82f1a3a0 100644 --- a/src/modal.zig +++ b/src/modal.zig @@ -163,7 +163,7 @@ pub const Normal = struct { }; pub const Input = struct { - roles: std.EnumSet(Role) = .initEmpty(), + roles: std.EnumSet(Role) = .empty, cp: u21, ctrl: bool = false, alt: bool = false, diff --git a/src/ninep/addr.zig b/src/ninep/addr.zig index b78c46e7..3feda5a2 100644 --- a/src/ninep/addr.zig +++ b/src/ninep/addr.zig @@ -646,7 +646,7 @@ test "the address language, form by form" { try testing.expectEqualStrings(c[1], th.wr(p, addr, c[0]).reply.ename); } - const nested = "," ** 4096; + const nested = &@as([4096]u8, @splat(',')); _ = th.wr(p, addr, "#0"); try testing.expectEqual(E.INVAL, th.wr(p, addr, nested).errno()); } diff --git a/src/ninep/cols.zig b/src/ninep/cols.zig index e3b456ba..59f6ae42 100644 --- a/src/ninep/cols.zig +++ b/src/ninep/cols.zig @@ -288,18 +288,18 @@ test "exactly 4096 bytes written with echo's newline after a truncation fit ever const p = try th.withFile(testing.allocator, "x\n"); defer p.deinit(); const serial = th.serialOf(p); - const text = "w" ** 4096 ++ "\n"; + 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| { _ = 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 }); try testing.expectEqual(tree.Status.ok, r.reply.status); _ = th.call(p, .{ .tag = 4, .op = .release, .node = node, .handle = h, .opened = true }); - try testing.expect(std.mem.endsWith(u8, th.rd(p, node, 0, 1 << 16).bytes, "w" ** 4096)); + try testing.expect(std.mem.endsWith(u8, th.rd(p, node, 0, 1 << 16).bytes, &@as([4096]u8, @splat('w')))); // One more byte is over. _ = th.call(p, .{ .tag = 5, .op = .setattr, .node = node, .truncate = true }); const h2 = th.call(p, .{ .tag = 6, .op = .open, .node = node, .omode = 1 }).reply.handle; - try testing.expectEqual(E.NOSPC, th.call(p, .{ .tag = 7, .op = .write, .node = node, .handle = h2, .data = "w" ** 4097 ++ "\n" }).errno()); + try testing.expectEqual(E.NOSPC, th.call(p, .{ .tag = 7, .op = .write, .node = node, .handle = h2, .data = &@as([4097]u8, @splat('w')) ++ "\n" }).errno()); _ = th.call(p, .{ .tag = 8, .op = .release, .node = node, .handle = h2, .opened = true }); } } @@ -316,7 +316,7 @@ test "a Newcol refused because the tags would not fit logs its err alone and spe for (p.col_panes[col][0..p.col_n[col]]) |k| { const each = p.panes[k].?; if (each.tag.own) |old| p.gpa.free(old); - each.tag.own = try p.gpa.dupe(u8, "word " ** 60); + each.tag.own = try p.gpa.dupe(u8, std.mem.asBytes(&@as([60][5]u8, @splat("word ".*)))); } try testing.expect(p.col_n[col] >= 2); p.sync(); @@ -588,7 +588,7 @@ test "a refused write after a truncation leaves every kind of tag as it was, and defer p.deinit(); const serial = th.serialOf(p); const col = layout.columnSerial(p, 0); - const big = "w" ** (limits.max_tag_tail + 1); + 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| { _ = th.wr(p, node, " Mine"); diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index f6457b83..6b4bbafb 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -1682,9 +1682,9 @@ test "a look's miss repeats the path whole up to 256 bytes, then gives up its mi var line: [512]u8 = undefined; _ = wr(p, root, try std.fmt.bufPrint(&line, "{s}\n", .{long})); try testing.expect(th.logHas(p, try std.fmt.bufPrint(&line, "look: no match for \"{s}\"\n", .{long}))); - const huge = "é" ** 150; // 300 bytes: its middle cut to fit 256, between characters + const huge = std.mem.asBytes(&@as([150][2]u8, @splat("é".*))); // 300 bytes: its middle cut to fit 256, between characters _ = wr(p, root, huge ++ "\n"); - try testing.expect(th.logHas(p, "look: no match for \"" ++ "é" ** 63 ++ "…" ++ "é" ** 63 ++ "\"\n")); + try testing.expect(th.logHas(p, "look: no match for \"" ++ std.mem.asBytes(&@as([63][2]u8, @splat("é".*))) ++ "…" ++ std.mem.asBytes(&@as([63][2]u8, @splat("é".*))) ++ "\"\n")); } test "exec runs a builtin at the pane and records the pane it acted on" { @@ -2041,7 +2041,7 @@ test "Zerox twins dump their text once and come back on one buffer from a Restor defer p.deinit(); const first = serialOf(p); _ = wr(p, Node.of(first, .name), "/tmp/pardes-zerox-dump.txt\n"); - _ = wr(p, Node.of(first, .body), "unsaved " ** 64 ++ "\n"); + _ = wr(p, Node.of(first, .body), std.mem.asBytes(&@as([64][8]u8, @splat("unsaved ".*))) ++ "\n"); try testing.expect(p.executeBuiltinLine(0, "Zerox")); try testing.expect(p.executeBuiltinLine(0, "Zerox")); try pardes.dump.dumpState(p); @@ -2888,7 +2888,7 @@ test "a builtin that fails a ctl write logs only its err, so the same failure ag test "an exec line over the command limit fails the write and says the limit; a builtin's may be longer" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); - const long = "echo " ++ "y" ** pardes.exec.command_max ++ "\n"; + const long = "echo " ++ &@as([pardes.exec.command_max]u8, @splat('y')) ++ "\n"; const refused = wr(p, root_exec, long); try testing.expectEqual(E.INVAL, refused.errno()); try testing.expectEqualStrings(e_too_long, refused.reply.ename); @@ -2896,7 +2896,7 @@ test "an exec line over the command limit fails the write and says the limit; a try testing.expect(th.logHas(p, try std.fmt.bufPrint(&rec, "err {d} exec: invalid command line: a command line is at most 1024 bytes", .{serialOf(p)}))); try testing.expectEqualStrings(e_control, wr(p, root_exec, "echo a\x01b\n").reply.ename); try testing.expect(th.logHas(p, try std.fmt.bufPrint(&rec, "err {d} exec: invalid command line: it holds", .{serialOf(p)}))); - try testing.expectEqual(Status.ok, wr(p, root_exec, "Msg " ++ "z" ** 1100 ++ "\n").reply.status); + try testing.expectEqual(Status.ok, wr(p, root_exec, "Msg " ++ &@as([1100]u8, @splat('z')) ++ "\n").reply.status); } test "Edit's p and = never fail for want of room for +Errors: the text is logged instead" { @@ -4012,8 +4012,8 @@ test "Back and Forward written to exec keep to the focused file, and JumpScope a defer p.deinit(); var tmp = testing.tmpDir(.{}); defer tmp.cleanup(); - try tmp.dir.writeFile(testing.io, .{ .sub_path = "a.txt", .data = "row\n" ** 100 }); - try tmp.dir.writeFile(testing.io, .{ .sub_path = "b.txt", .data = "row\n" ** 100 }); + try tmp.dir.writeFile(testing.io, .{ .sub_path = "a.txt", .data = std.mem.asBytes(&@as([100][4]u8, @splat("row\n".*))) }); + try tmp.dir.writeFile(testing.io, .{ .sub_path = "b.txt", .data = std.mem.asBytes(&@as([100][4]u8, @splat("row\n".*))) }); var dir_buf: [4096]u8 = undefined; const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)]; var line: [4200]u8 = undefined; diff --git a/src/ninep/events.zig b/src/ninep/events.zig index 3910ac05..7b73dc0e 100644 --- a/src/ninep/events.zig +++ b/src/ninep/events.zig @@ -938,7 +938,7 @@ test "event records are acme's bytes, one per read, and .again when empty" { try testing.expectEqualStrings("ML0 ", rd(p, event, 0, 4).bytes); try testing.expectEqualStrings("3 4 3 one\n", rd(p, event, 0, 4096).bytes); - const big = "z" ** max_record_text; + const big = &@as([max_record_text]u8, @splat('z')); _ = noteAction(p, 0, .body_exec, 0, max_record_text, 0, big); try testing.expectEqualStrings("MX0 256 0 0 \n", rd(p, event, 0, 4096).bytes); @@ -1388,7 +1388,7 @@ test "opens of the log share the open records, and a closed one frees its record test "a click in the body reports the offsets of the word it takes, so the record can be written back" { const config = @import("../config.zig"); const gpa = testing.allocator; - const text = "alpha qty beta\n qty\n\tqty\ndef f(qty): return qty.x\n" ++ "w" ** 100 ++ " qty\n"; + const text = "alpha qty beta\n qty\n\tqty\ndef f(qty): return qty.x\n" ++ &@as([100]u8, @splat('w')) ++ " qty\n"; const p = try withFile(gpa, text); defer p.deinit(); // A scratch made over 9P, clicked while another pane has the keyboard. @@ -1459,7 +1459,7 @@ test "follow new skips what the log held and waits for what comes after" { test "a long msg record is cut between words at its cap, with an ellipsis" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); - const long = "word " ** 60; // 300 bytes + 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 h = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle; @@ -1485,7 +1485,7 @@ 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" ++ "abcdefgh" ** 40 ++ "\n"); + _ = wr(p, @intFromEnum(tree.TopFile.ctl), "Bogus" ++ std.mem.asBytes(&@as([40][8]u8, @splat("abcdefgh".*))) ++ "\n"); const log = @intFromEnum(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; @@ -1500,7 +1500,7 @@ test "a long err record keeps its end, its middle given up to an ellipsis" { test "two failures that agree only in what their records cut are two records, not one counted" { const p = try th.withFile(testing.allocator, "x\n"); defer p.deinit(); - const long = "why " ** 80; + const long = std.mem.asBytes(&@as([80][4]u8, @splat("why ".*))); p.setMessage(0, long ++ "first"); p.setMessage(0, long ++ "second"); try testing.expect(!th.logHas(p, "(x2)")); diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig index 3b70d62f..8605cab8 100644 --- a/src/ninep/pane.zig +++ b/src/ninep/pane.zig @@ -1427,7 +1427,7 @@ test "a tag write past the limit is refused whole, naming the limit" { const tag = Node.of(serialOf(p), .tag); const before = try testing.allocator.dupe(u8, rd(p, tag, 0, 1 << 16).bytes); defer testing.allocator.free(before); - const big = "w" ** (limits.max_tag_tail + 10); + const big = &@as([limits.max_tag_tail + 10]u8, @splat('w')); const r = wr(p, tag, big); try testing.expectEqual(E.NOSPC, r.errno()); // `no space` is what 9ns maps to ENOSPC, so a shell through a mount @@ -1549,20 +1549,21 @@ test "a name with a component over 255 bytes is refused, and a long path's faile const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); const serial = serialOf(p); - const refused = wr(p, Node.of(serial, .name), "/tmp/" ++ "c" ** 256 ++ "/f.txt\n"); + const refused = wr(p, Node.of(serial, .name), "/tmp/" ++ &@as([256]u8, @splat('c')) ++ "/f.txt\n"); try testing.expectEqual(E.INVAL, refused.errno()); try testing.expectEqualStrings("invalid file name: a component over 255 bytes", refused.reply.ename); - try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .name), "/tmp/" ++ "c" ** 255 ++ "\n").reply.status); + try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .name), "/tmp/" ++ &@as([255]u8, @splat('c')) ++ "\n").reply.status); // Held with no newline, it is refused by that write, not at the close. const held = call(p, .{ .tag = 1, .op = .open, .node = Node.of(serial, .name), .omode = 1 }).reply.handle; - try testing.expectEqual(E.INVAL, call(p, .{ .tag = 2, .op = .write, .node = Node.of(serial, .name), .handle = held, .data = "/tmp/" ++ "e" ** 256 }).errno()); + try testing.expectEqual(E.INVAL, call(p, .{ .tag = 2, .op = .write, .node = Node.of(serial, .name), .handle = held, .data = "/tmp/" ++ &@as([256]u8, @splat('e')) }).errno()); _ = call(p, .{ .tag = 3, .op = .release, .node = Node.of(serial, .name), .handle = held, .opened = true }); try testing.expectEqual(@as(usize, 0), p.fs.closed_lines.items.len); // A Save of a 3000-byte path the host refuses: the waiting write's // reason is at the end, the path giving up its middle. // (Under /tmp: under / a user's Save is refused permission, not // missing.) - const long = "/tmp/nonexistent-pardes-root/" ++ ("d" ** 200 ++ "/") ** 15 ++ "f.txt"; + const segment = &@as([200]u8, @splat('d')) ++ "/"; + const long = "/tmp/nonexistent-pardes-root/" ++ std.mem.asBytes(&@as([15][201]u8, @splat(segment.*))) ++ "f.txt"; const id = p.paneBySerial(serial).?; try nameBuffer(p, id, long, false); p.fs.late_failure_len = 0; diff --git a/src/ninep/pty.zig b/src/ninep/pty.zig index c58cf676..aeb57a00 100644 --- a/src/ninep/pty.zig +++ b/src/ninep/pty.zig @@ -1044,12 +1044,12 @@ test "a run's answer says cut when its output's start is gone, and reads a bound const q = try withTerm(gpa); defer q.deinit(); const kept = q.panes[0].?; - kept.terminal.?.vt.screens.get(.primary).?.pages.explicit_max_size = 1; + kept.terminal.?.vt.screens.get(.primary).?.pages.limits.set(.bytes, 1); const run = Node.of(serialOf(q), .pty_run); sh.put(q, prompt); h = sh.send(q, run); sh.put(q, c); - const lines = "pruned\r\n" ** 64; + const lines = std.mem.asBytes(&@as([64][8]u8, @splat("pruned\r\n".*))); var fed: usize = 0; while (!kept.terminal.?.stream.handler.out_start.?.garbage) : (fed += 1) { if (fed == 1000) return error.TestUnexpectedResult; @@ -1146,7 +1146,7 @@ test "a run's answer longer than its room is cut, its newline kept" { var slot: Run = .{}; const p = try th.withTerm(testing.allocator); defer p.deinit(); - answer(p, &slot, "busy: {s} is running", .{"x" ** 200}); + answer(p, &slot, "busy: {s} is running", .{&@as([200]u8, @splat('x'))}); try testing.expectEqual(slot.answer.len, slot.len); try testing.expectEqual(@as(u8, '\n'), slot.answer[slot.len - 1]); } diff --git a/src/ninep/screen.zig b/src/ninep/screen.zig index b991c3e4..8d4707e0 100644 --- a/src/ninep/screen.zig +++ b/src/ninep/screen.zig @@ -333,7 +333,7 @@ test "a terminal's body is its logical lines: a row the terminal wrapped is join const p = try th.withTerm(testing.allocator); defer p.deinit(); const pane = p.panes[0].?; - const long = "w" ** 50 ++ "x" ** 150; // wider than the pane: it wraps + const long = &@as([50]u8, @splat('w')) ++ &@as([150]u8, @splat('x')); // wider than the pane: it wraps try testing.expect(long.len > pane.cols); p.update(.{ .output = .{ .pane = 0, .bytes = long ++ "\r\nnext" } }); while (p.nextEffect()) |_| {} diff --git a/src/ninep/tree.zig b/src/ninep/tree.zig index eedab43b..5678832b 100644 --- a/src/ninep/tree.zig +++ b/src/ninep/tree.zig @@ -509,7 +509,7 @@ pub fn fitErr(text: []const u8, out: []u8) []const u8 { test "a reason past 128 bytes keeps its end: the path in it gives up its middle" { var out: [128]u8 = undefined; - const long = "Save /home/someone/projects/" ++ "deep/" ** 30 ++ "file.txt: no such directory"; + const long = "Save /home/someone/projects/" ++ std.mem.asBytes(&@as([30][5]u8, @splat("deep/".*))) ++ "file.txt: no such directory"; const fit = fitErr(long, &out); try testing.expect(fit.len <= 128); try testing.expect(std.mem.startsWith(u8, fit, "Save /home/someone/")); @@ -517,7 +517,7 @@ test "a reason past 128 bytes keeps its end: the path in it gives up its middle" try testing.expect(std.mem.indexOf(u8, fit, "…") != null); try testing.expect(std.unicode.utf8ValidateSlice(fit)); // No path: the whole text's middle goes, the end stays. - const words = "why " ** 40 ++ "the reason"; + const words = std.mem.asBytes(&@as([40][4]u8, @splat("why ".*))) ++ "the reason"; try testing.expect(std.mem.endsWith(u8, fitErr(words, &out), "the reason")); try testing.expectEqualStrings("short", fitErr("short", &out)); // Through the tree: a look at a long ./ name not there, a miss, says @@ -525,7 +525,7 @@ test "a reason past 128 bytes keeps its end: the path in it gives up its middle" const p = try th.withFile(testing.allocator, "x\n"); defer p.deinit(); var line: [512]u8 = undefined; - const r = th.wr(p, Node.of(serialOf(p), .look), try std.fmt.bufPrint(&line, "./{s}x.txt\n", .{"no-such-dir/" ** 20})); + const r = th.wr(p, Node.of(serialOf(p), .look), try std.fmt.bufPrint(&line, "./{s}x.txt\n", .{std.mem.asBytes(&@as([20][12]u8, @splat("no-such-dir/".*)))})); try testing.expectEqual(Status.ok, r.reply.status); try testing.expect(th.logHas(p, "x.txt: no such file")); } @@ -1492,17 +1492,17 @@ test "README names every file the tree serves" { return false; } }; - inline for (@typeInfo(TopFile).@"enum".fields) |f| { - const t: TopFile = @enumFromInt(f.value); + inline for (@typeInfo(TopFile).@"enum".field_values) |value| { + const t: TopFile = @enumFromInt(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".fields) |f| { - const t: PaneFile = @enumFromInt(f.value); + inline for (@typeInfo(PaneFile).@"enum".field_values) |value| { + const t: PaneFile = @enumFromInt(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(f.value)).fileName()) != null + std.mem.indexOf(u8, fs.help, "pty/" ++ comptime @as(PaneFile, @enumFromInt(value)).fileName()) != null else words.has(t.fileName()); if (!ok) { diff --git a/src/normal.zig b/src/normal.zig index 77feb7cf..8de23d1c 100644 --- a/src/normal.zig +++ b/src/normal.zig @@ -1015,7 +1015,7 @@ test "gj/gk step the wrapped rows a body draws while j/k keep the file's lines" const p = try Pardes.init(gpa, .{ .tty_only = true }); defer p.deinit(); while (p.nextEffect()) |_| {} - const long = "a" ** 400; + const long = &@as([400]u8, @splat('a')); const pane = try p.setTestFile(long ++ "\nsecond\n"); p.settings.wrap = true; const width = panes.File.wrapWidth(pane, true); diff --git a/src/pager.zig b/src/pager.zig index 30418623..feabd194 100644 --- a/src/pager.zig +++ b/src/pager.zig @@ -38,7 +38,7 @@ pub fn parse(gpa: std.mem.Allocator, raw: []const u8, colour: bool) !Page { errdefer h.text.deinit(gpa); errdefer h.spans.deinit(gpa); try h.text.ensureTotalCapacity(gpa, raw.len); - var stream: ghostty_vt.Stream(*Handler) = .init(&h); + var stream: ghostty_vt.Stream(*Handler) = .init(.{ .handler = &h }); defer stream.deinit(); stream.nextSlice(raw); if (h.failed) return error.OutOfMemory; diff --git a/src/panes.zig b/src/panes.zig index ba1dedb5..07d5ccb1 100644 --- a/src/panes.zig +++ b/src/panes.zig @@ -318,7 +318,7 @@ pub const Pane = struct { /// `older` is an earlier message line still on screen; `index` says /// which (`Pane.msg_older`). pub const Kind = enum { older, message, leader, prompt }; - pub const max = @typeInfo(Kind).@"enum".fields.len - 1 + message_stack; + pub const max = @typeInfo(Kind).@"enum".field_names.len - 1 + message_stack; kinds: [max]Kind = undefined, index: [max]u8 = @splat(0), diff --git a/src/pardes.zig b/src/pardes.zig index 5f330712..8da0922d 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -807,7 +807,7 @@ test "TreeContext tag style preserves message rows and its opt-out survives rest if (comptime !syntax.enabled) return error.SkipZigTest; const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 60, .rows = 16 }); defer p.deinit(); - const pane = try p.setTestFile("pub const Box = struct {\n pub fn run() void {\n" ++ (" // body\n" ** 30) ++ " }\n};\n"); + const pane = try p.setTestFile("pub const Box = struct {\n pub fn run() void {\n" ++ (std.mem.asBytes(&@as([30][16]u8, @splat(" // body\n".*)))) ++ " }\n};\n"); p.gpa.free(pane.file.?.path); pane.file.?.path = try p.gpa.dupe(u8, "/test.zig"); if (!panes.File.supportsContext(pane)) return error.SkipZigTest; @@ -1247,7 +1247,9 @@ test "Def and Refs are a speaking file's tag words; gd, gr and a 2-1 chord all r const r = p.rects[0]; const x0 = r.x + config.GUTTER + panes.File.gutterWidth(pane); const use_y = p.bodyTop(pane, r) + 1; - const tag = try tagline.tagText(p, p.scratch.allocator(), pane); + // Copied out of the scratch arena, which each p.update resets. + const tag = try std.testing.allocator.dupe(u8, try tagline.tagText(p, p.scratch.allocator(), pane)); + defer std.testing.allocator.free(tag); for ([_]struct { word: []const u8, kind: lsp.Kind }{ .{ .word = " Def ", .kind = .definition }, .{ .word = " Refs", .kind = .references } }) |w| { // B1 sweeps the use of `alpha` on the second line (bytes 30..35), // leaving the cursor at its far end. @@ -1348,7 +1350,7 @@ test "acme placement: under a pane's text when it has many blank rows, else halv try std.testing.expectEqual(text_end, p.rects[second].y); // Fill both with text: no blank space is big, so the biggest pane is // halved. - const full = "x\n" ** 80; + const full = std.mem.asBytes(&@as([80][2]u8, @splat("x\n".*))); for ([_]usize{ top, second }) |id| panes.File.setContent(p, &p.panes[id].?.file.?, try p.gpa.dupe(u8, full)); p.sync(); const big = if (p.rects[second].h >= p.rects[top].h) second else top; @@ -2006,7 +2008,7 @@ test "a command pane shows how its command ended, and the next command there run try std.testing.expectEqual(@as(usize, 0), Count.signals); p.host = host_before; // A command line longer than a command pane takes is refused. - const long = "x" ** (exec.command_max + 1); + const long = &@as([exec.command_max + 1]u8, @splat('x')); try std.testing.expectEqual(@as(?usize, null), exec.execute(p, 1, long)); } @@ -2970,9 +2972,9 @@ test "restored terminals keep monotonic nonzero pane identities" { fn chordName(comptime c: config.Chord) []const u8 { comptime { const mods = (if (c.ctrl) "C-" else "") ++ (if (c.alt) "A-" else "") ++ (if (c.shift) "S-" else ""); - for (@typeInfo(Key).@"struct".decls) |d| { - if (@TypeOf(@field(Key, d.name)) != u21) continue; - if (@field(Key, d.name) == c.cp) return mods ++ d.name; + for (@typeInfo(Key).@"struct".decl_names) |d| { + if (@TypeOf(@field(Key, d)) != u21) continue; + if (@field(Key, d) == c.cp) return mods ++ d; } if (c.cp < 0x20 or c.cp > 0x7e) @compileError("chord has no name for the index"); return mods ++ &[_]u8{@as(u8, @intCast(c.cp))}; @@ -3088,11 +3090,11 @@ pub const builtin_rows: [std.enums.values(Builtin).len]Row = blk: { for (std.enums.values(Builtin), 0..) |b, i| { const keys = if (config.leader_path.get(b)) |path| leaderKeys(path) else ""; const rest = shortcuts(b); - const named = @tagName(b) ++ (if (rest.len == 0) "" else (" " ** (namew - @tagName(b).len)) ++ " " ++ rest); + const named = @tagName(b) ++ (if (rest.len == 0) "" else (&@as([namew - @tagName(b).len]u8, @splat(' '))) ++ " " ++ rest); rows[i] = .{ .path = config.leader_path.get(b), .cmd = b, - .line = keys ++ (" " ** (4 + keyw - keys.len)) ++ " " ++ named, + .line = keys ++ (&@as([4 + keyw - keys.len]u8, @splat(' '))) ++ " " ++ named, }; } const last = "\x7f"; @@ -3111,8 +3113,8 @@ comptime { @setEvalBranchQuota(20000); // one branch per string byte, behind the decl walk that folds Builtin var it = std.mem.tokenizeScalar(u8, config.topbar_str, ' '); words: while (it.next()) |w| { - for (@typeInfo(Builtin).@"enum".fields) |f| - if (std.mem.eql(u8, f.name, w)) continue :words; + for (@typeInfo(Builtin).@"enum".field_names) |name| + if (std.mem.eql(u8, name, w)) continue :words; @compileError("topbar word is not a builtin: " ++ w); } } @@ -4499,7 +4501,7 @@ pub const Pardes = struct { /// Panes made this step that found no room in their column /// (exec.placeNew): closed at the step's end, once whatever made them /// is done with them. - unplaced: std.StaticBitSet(MAX_PANES) = .initEmpty(), + unplaced: std.StaticBitSet(MAX_PANES) = .empty, /// A look's word search is running (look.lookUnresolved): from a /// terminal its rows refill the directory's one +Search (Output). word_look: bool = false, @@ -5018,7 +5020,7 @@ pub const Pardes = struct { if (p.dump_out) |d| gpa.free(d); p.fallback.deinit(); if (p.last_dump) |d| gpa.free(d); - if (p.custom_theme) |theme_value| std.zon.parse.free(gpa, theme_value); + if (p.custom_theme) |theme_value| gpa.free(theme_value.name); if (p.chord_arg) |a| gpa.free(a); for (p.spawn_dirs) |d| if (d) |dir| gpa.free(dir); p.pipe.deinit(gpa); @@ -8508,7 +8510,7 @@ test "raw tty Ctrl-B switches to editor mode without sending child input" { test "the jump list never holds two entries in a row the same, when the one between them goes" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 40 }); defer p.deinit(); - const pane = try p.setTestFile("a\n" ** 200); + const pane = try p.setTestFile(std.mem.asBytes(&@as([200][2]u8, @splat("a\n".*)))); const at: Loc = .{ .pane = 0, .serial = pane.serial, .line = 1, .col = 1 }; // A, a pane long closed with no file to keep it, A again, then far on. p.jumps[0] = at; @@ -9054,7 +9056,7 @@ const JumpsTest = struct { fn init(order: []const u8) !JumpsTest { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 80 }); errdefer p.deinit(); - const text = "row\n" ** 100; + const text = std.mem.asBytes(&@as([100][4]u8, @splat("row\n".*))); _ = try p.setTestFile(text); var t: JumpsTest = .{ .p = p }; for ([_][]const u8{ "/b.txt", "/test.txt", "" }, 1..) |path, n| { diff --git a/src/pdf.zig b/src/pdf.zig index d98d5ff2..5adc62d1 100644 --- a/src/pdf.zig +++ b/src/pdf.zig @@ -4,9 +4,7 @@ const std = @import("std"); const c_heap = @import("c_heap"); -const c = @cImport({ - @cInclude("pdf_bridge.h"); -}); +const c = @import("pdf_c"); // src/pdf_bridge.h, translated by build.zig /// What MuPDF allocates from, itself and the libraries it bundles (they all /// allocate through its context): `start`'s allocator, through the shared C @@ -1130,7 +1128,7 @@ pub const Document = struct { const page_number = try document.checkedPage(page); if (std.mem.indexOfScalar(u8, needle, 0) != null) return error.InvalidNeedle; - const needle_z = try gpa.dupeZ(u8, needle); + const needle_z = try gpa.dupeSentinel(u8, needle, 0); defer gpa.free(needle_z); var found: c.pardes_pdf_search_result = @@ -2067,7 +2065,7 @@ test "MuPDF search returns normalized oriented quads and word selection text" { const projected = try document.pageText(std.testing.allocator, 0); defer std.testing.allocator.free(projected); - try std.testing.expect(std.ascii.indexOfIgnoreCase(projected, "Pardes") != null); + try std.testing.expect(std.ascii.findIgnoreCase(projected, "Pardes") != null); // Exercise transactional cache replacement before searching page zero // again; a failed ownership handoff here tends to surface as a double drop. if (document.pages > 1) { @@ -2093,7 +2091,7 @@ test "MuPDF search returns normalized oriented quads and word selection text" { const text = try document.copySelection(std.testing.allocator, 0, selected.start, selected.end); defer std.testing.allocator.free(text); - try std.testing.expect(std.ascii.indexOfIgnoreCase(text, "Pardes") != null); + try std.testing.expect(std.ascii.findIgnoreCase(text, "Pardes") != null); } test "highlighted render changes pixels while plain render stays stable" { diff --git a/src/regexp.zig b/src/regexp.zig index 86132f60..4cbca57e 100644 --- a/src/regexp.zig +++ b/src/regexp.zig @@ -58,7 +58,7 @@ pub const Regex = struct { /// Timed on this machine's ReleaseSafe build: 10M steps of the worst /// patterns take 45-80 ms, and a Debug build is ten times slower. - pub const budget: u64 = if (builtin.mode == .Debug) 4_000_000 else 32_000_000; + pub const budget: u64 = if (builtin.mode == .debug) 4_000_000 else 32_000_000; pub const e_long = std.fmt.comptimePrint("bad regular expression: longer than mvzr's {d} operations (about {d} pattern characters)", .{ max_ops, max_ops }); pub const e_anchor = "bad regular expression: in a pattern with \\n, ^ can only come first and $ only just before a \\n"; @@ -503,10 +503,10 @@ test "a class with non-ASCII runes matches those runes: [éa-z], a range of them } test "a pattern past 64 characters compiles, and one past the limit says so" { - var long = try Regex.compile("a" ** 200); - const text = "x" ++ "a" ** 200 ++ "\n"; + var long = try Regex.compile(&@as([200]u8, @splat('a'))); + const text = "x" ++ &@as([200]u8, @splat('a')) ++ "\n"; try std.testing.expectEqual(@as(usize, 1), (try long.find(text, 0, text.len, text.len)).?.start); - try std.testing.expectError(error.TooLong, Regex.compile("a" ** (max_ops + 8))); + try std.testing.expectError(error.TooLong, Regex.compile(&@as([max_ops + 8]u8, @splat('a')))); try std.testing.expectError(error.Bad, Regex.compile("a[b")); } @@ -546,13 +546,13 @@ test "a search that would backtrack without end runs out of budget, promptly" { // As long a chain as mvzr compiles, over runs one `a` short of it: 2^20 // steps from every start. for (0..line.len / 20) |i| line[i * 20 + 19] = 'b'; - var chain = try Regex.compile("a?" ** 20 ++ "a" ** 20); + var chain = try Regex.compile(std.mem.asBytes(&@as([20][2]u8, @splat("a?".*))) ++ &@as([20]u8, @splat('a'))); try std.testing.expectError(error.TooSlow, chain.find(&line, 0, line.len, line.len)); } test "the match is the leftmost, however long the line" { // A window cut into the identifier would find `x... =` from its middle. - const text = "let " ++ "x" ** 100 ++ " = 1"; + const text = "let " ++ &@as([100]u8, @splat('x')) ++ " = 1"; var assign = try Regex.compile("\\s*(\\w+)\\s*="); const m = (try assign.find(text, 0, text.len, text.len)).?; try std.testing.expectEqual(@as(usize, 3), m.start); diff --git a/src/sam_edit.zig b/src/sam_edit.zig index d0c51bdb..f6253c89 100644 --- a/src/sam_edit.zig +++ b/src/sam_edit.zig @@ -1102,7 +1102,7 @@ fn expectEdit(text: []const u8, command: []const u8, want: []const u8) !void { test "an x over 100k lines is 100k searches, each with its own step budget" { const th = @import("ninep/testing.zig"); - const line = "x" ** 80 ++ "\n"; + const line = &@as([80]u8, @splat('x')) ++ "\n"; const text = try std.testing.allocator.alloc(u8, line.len * 100_000); defer std.testing.allocator.free(text); for (0..100_000) |k| @memcpy(text[line.len * k ..][0..line.len], line); diff --git a/src/syntax.zig b/src/syntax.zig index b2f5ea99..fa212ca7 100644 --- a/src/syntax.zig +++ b/src/syntax.zig @@ -1859,7 +1859,7 @@ test "syntax declaration locations clear snapshots without muting ordinary conte defer stop(); const header = "pub fn run() void {"; const content = "| \t" ++ header ++ "\n| \t const value = 42;\nfile.zig:3\t}\n"; - const snapshots = [_]u8{0xff} ** header.len; + const snapshots = @as([header.len]u8, @splat(0xff)); const Row = struct { path: []const u8 = "file.zig", code_start: usize, diff --git a/src/terminal.zig b/src/terminal.zig index 3190c6e3..a8e7931c 100644 --- a/src/terminal.zig +++ b/src/terminal.zig @@ -207,7 +207,7 @@ const LivePalette = struct { var seed = GColor.default; for (base, 0..) |rgb, i| seed[i] = rgb; - self.colors = GColor.generate256Color(seed, .initEmpty(), bg, fg, false); + self.colors = GColor.generate256Color(seed, .empty, bg, fg, false); self.key = key; return &self.colors; } @@ -609,10 +609,10 @@ pub fn create(gpa: std.mem.Allocator, cols: u16, rows: u16) !*Pane { state.vt = try ghostty_vt.Terminal.init(terminalIo(), gpa, .{ .cols = cols, .rows = rows, - .max_scrollback = 16 * 1024 * 1024, + .max_scrollback_bytes = 16 * 1024 * 1024, .kitty_image_storage_limit = if (images_enabled) TerminalImages.storage_limit else 0, }); - state.stream = .initAlloc(gpa, .{ .inner = state.vt.vtHandler() }); + state.stream = .init(.{ .handler = .{ .inner = state.vt.vtHandler() }, .allocator = gpa }); state.replay.head = 0; state.replay.len = 0; state.reply_len = 0; @@ -1055,7 +1055,11 @@ fn ingestWithPositions(pane: *Pane, bytes: []const u8) void { } }; } else failed = true; + // Whether the program cleared the screen (ED 2, a switch of screens); + // pardes reads the flag nowhere else. + pane.terminal.?.vt.flags.dirty.clear = false; ingest(pane, bytes); + const cleared = pane.terminal.?.vt.flags.dirty.clear; // RIS can destroy the alternate screen and every pin it owned. const alive = if (screens.generation(key) == generation) pages else null; var moved = false; @@ -1065,7 +1069,15 @@ fn ingestWithPositions(pane: *Pane, bytes: []const u8) void { if (pin.garbage) pointer_rows_lost = true; }; }; + // The program cleared the screen, or the rows the live copy stood on are + // gone (pruned, a reset): the copy goes with them, as what the program + // drew next. Kept, ghostty would move its rows to the top of what is + // left, over the program's new text. + var copy_lost = cleared or alive == null; for (spans[0..nspans]) |span| { + if (span.overlay == overlay) if (span.start.pin) |pin| if (alive != null and pin.garbage) { + copy_lost = true; + }; const start = pinnedRow(alive, span.start); const rows = @max(1, pinnedRow(alive, span.end) -| start +| 1); moved = moved or start != span.overlay.row or rows != span.overlay.rows; @@ -1096,6 +1108,11 @@ fn ingestWithPositions(pane: *Pane, bytes: []const u8) void { pane.clearPointerSelection(button); pane.sel[button].state = .none; }; + if (copy_lost) if (pane.ovl) |copy| { + pane.gpa.free(copy.text); + pane.ovl = null; + moved = true; + }; if (moved) pane.nsel_snap = 0; // Saved regex-preview offsets name the old flat text. if (failed) { const message = "terminal edit position reset: out of memory"; @@ -1211,7 +1228,7 @@ pub fn commandOutput(pane: *Pane, gpa: std.mem.Allocator, max_rows: usize) !Comm .whole = whole, }; } else true; - return .{ .text = try gpa.dupeZ(u8, ""), .whole = whole }; + return .{ .text = try gpa.dupeSentinel(u8, "", 0), .whole = whole }; } /// At a prompt with nothing typed on its line: no input left of the @@ -2813,7 +2830,7 @@ pub fn redo(p: *Pardes, pane: *Pane) void { pane.ensureCursorVisible(); } -pub fn ptyReport(handler: *ghostty_vt.TerminalStream.Handler, data: [:0]const u8) void { +pub fn ptyReport(handler: *ghostty_vt.TerminalStream.Handler, data: []const u8) void { const state: *State = @alignCast(@fieldParentPtr("vt", handler.terminal)); const room = state.reply.len - state.reply_len; const n = @min(room, data.len); @@ -2968,7 +2985,8 @@ test "a program that asked for focus reports hears CSI I and CSI O as its pane t /// over two cells). inline fn kittyTransmit(comptime extra: []const u8) []const u8 { return comptime blk: { - const pixels = [_]u8{ 255, 0, 0, 255, 0, 0, 0, 0, 255, 0, 0, 255 } ** 2; + const row = [_]u8{ 255, 0, 0, 255, 0, 0, 0, 0, 255, 0, 0, 255 }; + const pixels = row ++ row; var buf: [std.base64.standard.Encoder.calcSize(pixels.len)]u8 = undefined; const b64 = std.base64.standard.Encoder.encode(&buf, &pixels)[0..buf.len].*; break :blk "\x1b_Ga=T,f=24,s=4,v=2,i=7," ++ extra ++ ";" ++ b64 ++ "\x1b\\"; diff --git a/src/tty/tty.zig b/src/tty/tty.zig index ca2cb939..82cb40bd 100644 --- a/src/tty/tty.zig +++ b/src/tty/tty.zig @@ -129,7 +129,7 @@ fn readInput(loop: *Loop, tty: anytype, cache: *vaxis.GraphemeCache) !void { var parser: vaxis.Parser = .{}; var buf: [1024]u8 = undefined; var carried: usize = 0; - while (!loop.should_quit) { + while (true) { // stopInput cancels the task; the read then fails with Canceled if (carried == buf.len) return error.InputSequenceTooLong; const received = try tty.read(buf[carried..]); if (received == 0) return; @@ -295,7 +295,7 @@ test "terminal input preserves fragmented keys queries paste and text after EOF" fn getWinsize(_: *@This()) !vaxis.Winsize { return .{ .rows = 24, .cols = 80, .x_pixel = 0, .y_pixel = 0 }; } - fn inputFollows(self: *@This(), _: u32) bool { + pub fn inputFollows(self: *@This(), _: u32) bool { return self.next < self.parts.len; } fn read(self: *@This(), buf: []u8) !usize { @@ -380,7 +380,7 @@ test "terminal replies and malformed sequences never become typed text" { fn getWinsize(_: *@This()) !vaxis.Winsize { return .{ .rows = 24, .cols = 80, .x_pixel = 0, .y_pixel = 0 }; } - fn inputFollows(self: *@This(), _: u32) bool { + pub fn inputFollows(self: *@This(), _: u32) bool { return self.next < self.parts.len; } fn read(self: *@This(), buf: []u8) !usize { @@ -465,7 +465,7 @@ test "terminal input split at every byte with a gap reads as it does whole" { fn getWinsize(_: *@This()) !vaxis.Winsize { return .{ .rows = 24, .cols = 80, .x_pixel = 0, .y_pixel = 0 }; } - fn inputFollows(self: *@This(), ms: u32) bool { + pub fn inputFollows(self: *@This(), ms: u32) bool { return self.next < self.parts.len and self.gap_ms <= ms; } fn read(self: *@This(), buf: []u8) !usize { @@ -561,7 +561,7 @@ test "an ESC read by itself is the Escape key at once" { fn getWinsize(_: *@This()) !vaxis.Winsize { return .{ .rows = 24, .cols = 80, .x_pixel = 0, .y_pixel = 0 }; } - fn inputFollows(self: *@This(), _: u32) bool { + pub fn inputFollows(self: *@This(), _: u32) bool { self.asked = true; return self.next < self.parts.len; } @@ -609,7 +609,7 @@ test "a frame's answer is taken wherever the reads cut it, and never typed" { fn getWinsize(_: *@This()) !vaxis.Winsize { return .{ .rows = 24, .cols = 80, .x_pixel = 0, .y_pixel = 0 }; } - fn inputFollows(self: *@This(), _: u32) bool { + pub fn inputFollows(self: *@This(), _: u32) bool { return self.next < self.parts.len; } fn read(self: *@This(), buf: []u8) !usize { @@ -701,7 +701,7 @@ test "terminal input cancellation joins blocked reads and queued EOF" { fn getWinsize(_: *@This()) !vaxis.Winsize { return .{ .rows = 24, .cols = 80, .x_pixel = 0, .y_pixel = 0 }; } - fn inputFollows(_: *@This(), _: u32) bool { + pub fn inputFollows(_: *@This(), _: u32) bool { return false; } fn read(self: *@This(), buf: []u8) !usize { @@ -2332,7 +2332,7 @@ test "a terminal pane gets function keys as their sequences and lone modifiers n fn getWinsize(_: *@This()) !vaxis.Winsize { return .{ .rows = 24, .cols = 80, .x_pixel = 0, .y_pixel = 0 }; } - fn inputFollows(self: *@This(), _: u32) bool { + pub fn inputFollows(self: *@This(), _: u32) bool { return self.next < self.parts.len; } fn read(self: *@This(), buf: []u8) !usize { @@ -3033,7 +3033,7 @@ test "a jump leaves a trail of a few cells behind the cursor that fades in 120 m const gpa = std.testing.allocator; const core = try pardes.Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 }); defer core.deinit(); - _ = try core.setTestFile("some text on a line\n" ** 20); + _ = try core.setTestFile(std.mem.asBytes(&@as([20][20]u8, @splat("some text on a line\n".*)))); try std.testing.expect(core.executeBuiltinLine(0, "Theme forge")); core.settings.jump_trail = true; for (0..40) |_| core.update(.tick); @@ -3078,7 +3078,7 @@ test "a notice chip casts a cell's shadow right and down, inside its body, off t const gpa = std.testing.allocator; const core = try pardes.Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 }); defer core.deinit(); - _ = try core.setTestFile("some text on a line\n" ** 20); + _ = try core.setTestFile(std.mem.asBytes(&@as([20][20]u8, @splat("some text on a line\n".*)))); try std.testing.expect(core.executeBuiltinLine(0, "Theme forge")); core.settings.chip_shadow = true; try std.testing.expect(core.executeBuiltinLine(0, "Msg a notice")); @@ -3114,7 +3114,7 @@ test "a scrolled pane's thumb brightens and fades back in 250 ms" { const gpa = std.testing.allocator; const core = try pardes.Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 }); defer core.deinit(); - const pane = try core.setTestFile("some text on a line\n" ** 200); + const pane = try core.setTestFile(std.mem.asBytes(&@as([200][20]u8, @splat("some text on a line\n".*)))); try std.testing.expect(core.executeBuiltinLine(0, "Theme forge")); core.settings.thumb_flash = true; for (0..40) |_| core.update(.tick); |
