summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-29 19:09:26 -0300
committerGabriel Schneider <[email protected]>2026-10-29 21:13:33 -0300
commit2eb8860b2ca05c426f3962661441aaee13d3be44 (patch)
tree8d363280576cc86db7209ef37c6210a0d5b75c8e
parente4cfd57bc41c5740e3a823a8f05d70d3e87b68ca (diff)
downloadpardes-2eb8860b2ca05c426f3962661441aaee13d3be44.tar.gz
pardes-2eb8860b2ca05c426f3962661441aaee13d3be44.zip
web: the browser shell builds again and loads a dump of a native build: a theme by its name, a field compiled out passed over, no disk asked; touch.dump replaces the hand-written ZON fixture
Fixed for wasm32-freestanding: counts as usize, no threads, stb_image, tape or host stat there. touch.mjs follows the renderer's 13 tag-layer fields, helix's retuned colours and the tag column. Co-Authored-By: Claude Opus 5.5 <[email protected]>
-rw-r--r--build.zig12
-rw-r--r--build/snap.zig2
-rw-r--r--docs/web.md4
-rw-r--r--src/FrameStats.zig2
-rw-r--r--src/Store.zig2
-rw-r--r--src/Stream.zig2
-rw-r--r--src/dump.zig23
-rw-r--r--src/exec.zig2
-rw-r--r--src/image.zig22
-rw-r--r--src/tape.zig4
-rw-r--r--src/terminal.zig4
-rw-r--r--src/walk.zig38
-rw-r--r--test/web-snapshots/README.md2
-rw-r--r--test/web-snapshots/touch-fixture.zig58
-rw-r--r--test/web-snapshots/touch.dumpbin0 -> 96576 bytes
-rw-r--r--test/web-snapshots/touch.dump.zon73
-rw-r--r--test/web-snapshots/touch.mjs21
-rw-r--r--tools/web_fixture.py34
18 files changed, 186 insertions, 119 deletions
diff --git a/build.zig b/build.zig
index 962b6322..097fb1bf 100644
--- a/build.zig
+++ b/build.zig
@@ -108,7 +108,7 @@ pub fn build(b: *std.Build) void {
const target = if (platform == .esp32p4) b.resolveTargetQuery(esp32p4_target) else requested_target;
const requested_optimize = b.standardOptimizeOption(.{});
const static = b.option(bool, "static", "statically link") orelse false;
- const dump_path = b.option([]const u8, "dump", "dump .zon embedded into the web shell (-Dplatform=web)");
+ const dump_path = b.option([]const u8, "dump", "a Dump (a .dump file) embedded into the web shell (-Dplatform=web)");
// one substring, because that is what a dev loop needs: see the unit-test
// step for why the whole-binary run is worth narrowing
const test_filters: []const []const u8 = if (b.option([]const u8, "test-filter", "run only tests whose name contains this")) |f|
@@ -196,7 +196,7 @@ pub fn build(b: *std.Build) void {
// The browser shell is a freestanding wasm core plus ordinary web files.
// JavaScript owns the loop and IO; HTML/CSS own rendering.
- const web_step = b.step("web", "build the DOM browser shell into zig-out/web (-Dplatform=web -Dtarget=wasm32-freestanding -Ddump=<dump.zon>)");
+ const web_step = b.step("web", "build the DOM browser shell into zig-out/web (-Dplatform=web -Dtarget=wasm32-freestanding -Ddump=<file.dump>)");
const mupdf_check = b.step("mupdf-check", "compile, link, render, and search docs/design.pdf with MuPDF");
const pdf_bench_step = b.step("pdf-bench", "benchmark real MuPDF page rendering (-- [--json] [--reps N] [--warmup N] [--path FILE] [--page N] [--pages N])");
const pdf_sections_bench_step = b.step("pdf-sections-bench", "benchmark PDF outline/sections paths in ReleaseFast (-Doptimize=ReleaseFast -- [--json] [--reps N] [--warmup N])");
@@ -224,7 +224,7 @@ pub fn build(b: *std.Build) void {
if (is_web and !is_web_target) return failBuild(b, web_step, "-Dplatform=web requires -Dtarget=wasm32-freestanding");
if (!is_web and (is_web_target or target.result.os.tag == .emscripten)) return failBuild(b, web_step, "wasm browser targets require -Dplatform=web");
- if (platform == .web and dump_path == null) return failBuild(b, web_step, "-Dplatform=web requires -Ddump=<dump.zon> (the browser has no ptys; state replays from an embedded dump)");
+ if (platform == .web and dump_path == null) return failBuild(b, web_step, "-Dplatform=web requires -Ddump=<file.dump> (the browser has no ptys; state replays from an embedded dump)");
if (enable_mupdf and is_web) return failBuild(b, web_step, "-Dmupdf=true is supported only by the native tty/Kitty and gui/SDL backends");
// The board's target is pinned (`target` above), so what is asked of
// -Dtarget is checked, not what was resolved: another arch is refused,
@@ -1140,7 +1140,7 @@ pub fn build(b: *std.Build) void {
const obj = b.addObject(.{ .name = "pardes-esp32p4", .root_module = root_mod });
b.getInstallStep().dependOn(&b.addInstallFile(obj.getEmittedBin(), "pardes-esp32p4.o").step);
- web_step.dependOn(&b.addFail("web needs -Dplatform=web -Dtarget=wasm32-freestanding -Ddump=<dump.zon>").step);
+ web_step.dependOn(&b.addFail("web needs -Dplatform=web -Dtarget=wasm32-freestanding -Ddump=<file.dump>").step);
} else if (platform == .macos) {
const header = b.addTranslateC(.{
.root_source_file = b.path("src/macos/pardes.h"),
@@ -1308,7 +1308,7 @@ pub fn build(b: *std.Build) void {
run_unit.has_side_effects = true;
unit_step.dependOn(&run_unit.step);
if (testMatch(b, unit_profile, test_filters, unit_step)) |check| check.addArtifactArg(unit_tests);
- web_step.dependOn(&b.addFail("web needs -Dplatform=web -Dtarget=wasm32-freestanding -Ddump=<dump.zon>").step);
+ web_step.dependOn(&b.addFail("web needs -Dplatform=web -Dtarget=wasm32-freestanding -Ddump=<file.dump>").step);
} else {
var exe_name: []const u8 = if (platform == .gui) "pardes-gui" else "pardes";
if (target.result.os.tag != .linux or target.result.cpu.arch != .x86_64)
@@ -1344,7 +1344,7 @@ pub fn build(b: *std.Build) void {
const iso_step = b.step("run-isolated", "descend to a pardes with no host but the terminal");
iso_step.dependOn(&run_iso.step);
}
- web_step.dependOn(&b.addFail("web needs -Dplatform=web -Dtarget=wasm32-freestanding -Ddump=<dump.zon>").step);
+ web_step.dependOn(&b.addFail("web needs -Dplatform=web -Dtarget=wasm32-freestanding -Ddump=<file.dump>").step);
snap_build.addTty(b, .{
.exe = exe,
diff --git a/build/snap.zig b/build/snap.zig
index c1a26e64..dad23c53 100644
--- a/build/snap.zig
+++ b/build/snap.zig
@@ -118,7 +118,7 @@ pub fn addWeb(b: *std.Build) void {
"-Dplatform=web",
"-Dtarget=wasm32-freestanding",
"-Dtree-sitter=zig",
- "-Ddump=test/web-snapshots/touch.dump.zon",
+ "-Ddump=test/web-snapshots/touch.dump",
"-p",
"zig-out/web-snap-test",
});
diff --git a/docs/web.md b/docs/web.md
index 0a9783c9..b9d03b13 100644
--- a/docs/web.md
+++ b/docs/web.md
@@ -57,7 +57,7 @@ zig build web \
-Dplatform=web \
-Dtarget=wasm32-freestanding \
-Dtree-sitter=zig \
- -Ddump=test/web-snapshots/touch.dump.zon
+ -Ddump=test/web-snapshots/touch.dump
```
The output is in `zig-out/web`. Serve that directory over HTTP; browsers do not
@@ -133,7 +133,7 @@ zig build web-harness \
-Dplatform=web \
-Dtarget=wasm32-freestanding \
-Dtree-sitter=zig \
- -Ddump=test/web-snapshots/touch.dump.zon
+ -Ddump=test/web-snapshots/touch.dump
# Real headless Chrome, DOM rendering, and browser touch input.
zig build web-e2e
diff --git a/src/FrameStats.zig b/src/FrameStats.zig
index 2287002e..c27e74af 100644
--- a/src/FrameStats.zig
+++ b/src/FrameStats.zig
@@ -173,7 +173,7 @@ pub fn record(stats: *FrameStats, end_ns: u64, moving: bool, skipped: bool) void
if (stats.armed and @as(u64, gap) * std.time.ns_per_us * 2 > stats.period_ns * 3) stats.jank += 1;
if (@as(u64, frame.update_us + frame.render_us + frame.present_us) * std.time.ns_per_us > stats.period_ns) stats.over_budget += 1;
if (skipped) stats.skipped += 1;
- stats.ring[stats.count % capacity] = frame;
+ stats.ring[@intCast(stats.count % capacity)] = frame;
stats.count += 1;
stats.last_end_ns = end_ns;
stats.armed = moving;
diff --git a/src/Store.zig b/src/Store.zig
index 95f5368f..36215234 100644
--- a/src/Store.zig
+++ b/src/Store.zig
@@ -78,7 +78,7 @@ cap: u64 = max_bytes,
session: u64 = 0,
pid: i32 = 0,
/// The file as read so far: its inode, generation and how far.
-inode: std.Io.File.INode = 0,
+inode: std.Io.File.INode = std.mem.zeroes(std.Io.File.INode),
gen: u64 = 0,
end: u64 = 0,
/// Its length when first read whole: a file past twice that (and 1 MiB)
diff --git a/src/Stream.zig b/src/Stream.zig
index 8d9663dd..665241df 100644
--- a/src/Stream.zig
+++ b/src/Stream.zig
@@ -512,7 +512,7 @@ pub fn parseFor(p: *Pardes, id: usize) void {
// Here and now: a small text, a host with no workers.
var got: Collect = .{ .gpa = p.gpa };
defer got.batches.deinit(p.gpa);
- parseWork(std.Io.Threaded.global_single_threaded.io(), job, &got, Collect.take);
+ parseWork(if (comptime pardes.hosted) std.Io.Threaded.global_single_threaded.io() else std.Io.failing, job, &got, Collect.take);
for (got.batches.items) |*b| {
receive(p, b);
b.deinit(p.gpa);
diff --git a/src/dump.zig b/src/dump.zig
index abc52f5a..c33ac02c 100644
--- a/src/dump.zig
+++ b/src/dump.zig
@@ -142,11 +142,13 @@ pub fn defaultDirectory(buf: []u8) ?[]const u8 {
/// A session's dump: its core, everything it is but what is the host's,
/// the frame's or worked out again (`replica` in each type, src/walk.zig),
-/// then its 9P mounts, which live with the 9P server's own state, and which
-/// of its panes' files were on disk when it was made (one gone by its load
-/// is said deleted: its text is nowhere else now).
-const Session = walk.Dump(&.{ Pardes, []const filesystem.Mount, OnDisk });
-const SessionLoad = walk.Load(&.{ Pardes, []const filesystem.Mount, OnDisk });
+/// then its 9P mounts, which live with the 9P server's own state, which of
+/// its panes' files were on disk when it was made (one gone by its load is
+/// said deleted: its text is nowhere else now), and its theme's name: the
+/// setting is a place in this build's ring of themes, another build's
+/// ring is another.
+const Session = walk.Dump(&.{ Pardes, []const filesystem.Mount, OnDisk, []const u8 });
+const SessionLoad = walk.Load(&.{ Pardes, []const filesystem.Mount, OnDisk, []const u8 });
const OnDisk = [MAX_PANES]bool;
fn onDisk(pane: *const pardes.panes.Pane) bool {
@@ -176,6 +178,8 @@ pub fn dumpBytes(p: *Pardes) ![]u8 {
on.* = onDisk(pane);
};
try d.put(OnDisk, &on_disk);
+ const theme: []const u8 = colors.themes[@min(p.settings.theme, colors.themes.len - 1)].name;
+ try d.put([]const u8, &theme);
return d.finish();
}
@@ -233,6 +237,12 @@ fn loadKnowing(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes:
}
const was = try l.get(OnDisk);
if (on_disk) |out| out.* = was;
+ const theme = try l.get([]const u8);
+ defer gpa.free(theme);
+ // This build's place for that theme; one it has not, its first.
+ p.settings.theme = for (colors.themes, 0..) |t, i| {
+ if (std.mem.eql(u8, t.name, theme)) break i;
+ } else if (p.settings.theme < colors.themes.len) p.settings.theme else 0;
// A mount this process was started with stands; one of the same name
// to elsewhere is refused, never silently put over it.
for (mounts) |m| {
@@ -411,7 +421,8 @@ fn revivePane(p: *Pardes, id: usize, pane: *pardes.panes.Pane, was_on_disk: bool
// Its file gone from disk since the dump: its text is nowhere else, so
// it is said deleted, and Del, Exit and Restore ask first. One never on
// disk (a name not yet saved) comes back as it was.
- if (was_on_disk and !onDisk(pane)) pardes.panes.File.deleted(p, @intCast(id));
+ // (A host with no disk of its own, the web's, asks nothing.)
+ if (comptime pardes.hosted) if (was_on_disk and !onDisk(pane)) pardes.panes.File.deleted(p, @intCast(id));
}
// ---- one pane to and from a dump: the store's, a handover's ----
diff --git a/src/exec.zig b/src/exec.zig
index 8f84d2c6..df397b37 100644
--- a/src/exec.zig
+++ b/src/exec.zig
@@ -483,6 +483,8 @@ pub fn isFile(path: []const u8) bool {
/// What `path` is on this host, null when it is not there; the turn out
/// while it asks (it may be inside a mount this editor serves).
pub fn kindOf(path: []const u8) ?std.Io.File.Kind {
+ // A freestanding build has no host to ask.
+ if (comptime !pardes.hosted) return null;
var buf: [4096]u8 = undefined;
const z = std.fmt.bufPrintSentinel(&buf, "{s}", .{path}, 0) catch return null;
return pardes.tape.site(.kind, null, kindHost, .{z});
diff --git a/src/image.zig b/src/image.zig
index 8f193674..9163730d 100644
--- a/src/image.zig
+++ b/src/image.zig
@@ -755,6 +755,13 @@ var started = false;
extern fn stbi_info_from_memory(buffer: [*]const u8, len: c_int, x: *c_int, y: *c_int, comp: *c_int) c_int;
+/// stb_image's header reader; a freestanding build has no stb_image (its
+/// decoder is the shim in src/web/zstbi.zig), so no header reads as one.
+fn stbiInfo(bytes: []const u8, w: *c_int, h: *c_int, c: *c_int) bool {
+ if (comptime !pardes.hosted) return false;
+ return stbi_info_from_memory(bytes.ptr, @intCast(bytes.len), w, h, c) == 1;
+}
+
/// PNG and JPEG are ghostty's decoders (wuffs, which ghostty-vt links for
/// kitty graphics) wherever ghostty-vt is in the build; stb_image is then
/// compiled without them, and without the inflate only its PNG used
@@ -787,7 +794,7 @@ fn headerSize(bytes: []const u8) ?Size {
var iw: c_int = 0;
var ih: c_int = 0;
var ic: c_int = 0;
- if (stbi_info_from_memory(bytes.ptr, @intCast(bytes.len), &iw, &ih, &ic) != 1) return null;
+ if (!stbiInfo(bytes, &iw, &ih, &ic)) return null;
return .{ .w = @intCast(@max(0, iw)), .h = @intCast(@max(0, ih)) };
}
@@ -828,7 +835,7 @@ pub fn readable(bytes: []const u8) bool {
var c: c_int = 0;
if (!started) return true; // ponytail: no stb_image yet (a unit test), so no judging
if (comptime wuffs_images) if (format(bytes) != .other) return headerSize(bytes) != null;
- return stbi_info_from_memory(bytes.ptr, @intCast(bytes.len), &w, &h, &c) == 1;
+ return stbiInfo(bytes, &w, &h, &c);
}
/// decode + downscale to RGBA, gpa-owned. Returns null on any failure — the
@@ -929,6 +936,9 @@ const GridKey = struct {
ascii: bool = true,
};
+/// A host's thread; a freestanding build has none to have.
+const Decoder = if (pardes.hosted) std.Thread else void;
+
pub const State = struct {
/// What the replay digest leaves out (src/walk.zig): the picture as
/// decoded from its bytes, off the loop as the render first wants it,
@@ -947,12 +957,12 @@ pub const State = struct {
grid: GlyphArt.Grid = .{ .cells = &.{}, .cols = 0, .rows = 0 },
grid_key: GridKey = .{},
/// The decode under way off the loop (ensureDecoded), and its answer.
- decoder: ?std.Thread = null,
+ decoder: ?Decoder = null,
decoded: std.atomic.Value(bool) = .init(false),
answer: ?Decoded = null,
pub fn deinit(state: *State, gpa: std.mem.Allocator) void {
- if (state.decoder) |t| t.join();
+ if (comptime pardes.hosted) if (state.decoder) |t| t.join();
if (state.answer) |a| gpa.free(a.rgba);
gpa.free(state.path);
if (state.rgba.len > 0) gpa.free(state.rgba);
@@ -1026,11 +1036,11 @@ pub fn tagPrefix(arena: std.mem.Allocator, state: *const State, glyphs: bool) ![
/// docs' screenshot: all of it once on the frame before).
/// ponytail: a thread a picture; a pool if many open at once.
fn ensureDecoded(p: *pardes.Pardes, state: *State) void {
- if (state.decoder) |t| {
+ if (comptime pardes.hosted) if (state.decoder) |t| {
if (!state.decoded.load(.acquire)) return;
t.join();
state.decoder = null;
- }
+ };
if (state.answer) |decoded| {
state.answer = null;
state.rgba = decoded.rgba;
diff --git a/src/tape.zig b/src/tape.zig
index d4fb7756..84bdce29 100644
--- a/src/tape.zig
+++ b/src/tape.zig
@@ -163,6 +163,7 @@ pub const Tape = struct {
}
fn flush(t: *Tape) void {
+ if (comptime !pardes.hosted) return;
// A tape in memory (a replica's, an authority's stream) is taken
// by whoever holds it.
if (t.fd < 0) return;
@@ -710,6 +711,8 @@ pub fn value(comptime s: Site, comptime f: anytype, args: anytype) @typeInfo(@Ty
fn call(comptime s: Site, a: ?std.mem.Allocator, comptime f: anytype, args: anytype, comptime yields: bool) @typeInfo(@TypeOf(f)).@"fn".return_type.? {
const R = @typeInfo(@TypeOf(f)).@"fn".return_type.?;
+ // No tape where there is no host to record or replay one.
+ if (comptime !pardes.hosted) return if (yields) out(f, args) else @call(.auto, f, args);
const t = on orelse return if (yields) out(f, args) else @call(.auto, f, args);
const id: u16 = @as(u16, host_fns.len) + @backingInt(s);
if (t.replay) {
@@ -928,6 +931,7 @@ pub fn digestOf(p: *const Pardes) u64 {
/// PARDES_RECORD set: the tape is written from the session's first call.
pub fn startFromEnv() void {
+ if (comptime !pardes.hosted) return;
if (on != null) return;
const prefix = std.mem.span(libc.getenv("PARDES_RECORD") orelse return);
if (prefix.len == 0) return;
diff --git a/src/terminal.zig b/src/terminal.zig
index ad35784f..bcb70110 100644
--- a/src/terminal.zig
+++ b/src/terminal.zig
@@ -254,7 +254,7 @@ pub const State = struct {
return;
}
if (bytes.len < 8) return error.EndOfDump;
- const n = std.mem.bytesToValue(u64, bytes[0..8]);
+ const n = std.math.cast(usize, std.mem.bytesToValue(u64, bytes[0..8])) orelse return error.EndOfDump;
if (bytes.len - 8 < n) return error.EndOfDump;
var arena: std.heap.ArenaAllocator = .init(gpa);
defer arena.deinit();
@@ -797,7 +797,7 @@ pub fn create(gpa: std.mem.Allocator, cols: u16, rows: u16) !*Pane {
// defaults to direct alone, which `kitten icat` and timg detect and
// fall back from, base64 through the pty. What the program can read
// it could send itself: it runs as the user, under pardes.
- .kitty_image_loading_limits = if (images_enabled) .allWithTempDir(tempDir()) else .direct,
+ .kitty_image_loading_limits = if (images_enabled) .allWithTempDir(tempDir()) else if (@FieldType(ghostty_vt.Terminal.Options, "kitty_image_loading_limits") == void) {} else .direct,
});
state.stream = .init(.{ .handler = .{ .inner = state.vt.vtHandler() }, .allocator = gpa });
state.reply_len = 0;
diff --git a/src/walk.zig b/src/walk.zig
index 328557a7..6f9cc34b 100644
--- a/src/walk.zig
+++ b/src/walk.zig
@@ -843,6 +843,10 @@ fn allocOf(comptime T: type, comptime name: []const u8) ?[]const u8 {
return null;
}
+fn countOf(n: u64) DecodeError!usize {
+ return std.math.cast(usize, n) orelse error.BadDump;
+}
+
/// An allocation a load made: what a reference to it finds, and what a
/// failed load frees.
const Made = struct { bytes: []u8, alignment: std.mem.Alignment, gpa: std.mem.Allocator, dead: bool = false };
@@ -931,6 +935,11 @@ pub fn Load(comptime roots: []const type) type {
return std.mem.bytesToValue(T, try l.take(@sizeOf(T)));
}
+ /// A count, as this machine counts (a wasm32 one has 32 bits).
+ fn count(l: *Self) DecodeError!usize {
+ return countOf(try l.scalar(u64));
+ }
+
fn name(l: *Self) DecodeError![]const u8 {
return l.take(try l.scalar(u16));
}
@@ -962,9 +971,9 @@ pub fn Load(comptime roots: []const type) type {
},
.optional, .one, .slice, .prefix, .error_union => t.child = try l.scalar(u32),
.@"struct", .@"union" => {
- const count = try l.scalar(u32);
- if (count > l.bytes.len) return error.BadDump;
- const list = try a.alloc(SrcField, count);
+ const nfields = try l.scalar(u32);
+ if (nfields > l.bytes.len) return error.BadDump;
+ const list = try a.alloc(SrcField, nfields);
for (list) |*f| f.* = .{ .name = try l.name(), .ty = try l.scalar(u32) };
t.fields = list;
},
@@ -1073,6 +1082,14 @@ pub fn Load(comptime roots: []const type) type {
out.* = .{ .raw = raw };
return;
}
+ // A field this build compiles out (a PDF slot where there is no
+ // MuPDF): passed over, said only when it held something.
+ if (comptime kindOf(Canon(T)) == .void) if (!l.same and l.src[ty].kind != .void) {
+ const held = l.src[ty].kind != .optional or (l.at < l.bytes.len and l.bytes[l.at] != 0);
+ try l.skip(ty);
+ if (held) l.note("{s}: not in this build", .{l.field});
+ return;
+ };
if (!try l.kindMatches(T, ty)) return error.Incompatible;
const s = l.src[ty];
if (comptime isList(T)) {
@@ -1194,8 +1211,7 @@ pub fn Load(comptime roots: []const type) type {
} else out.* = try l.errorNamed(@typeInfo(T).error_union.error_set);
},
.custom => {
- const n = try l.scalar(u64);
- const bytes = try l.take(n);
+ const bytes = try l.take(try l.count());
T.dumpRead(out, l.gpa, bytes) catch |err| {
if (err == error.OutOfMemory) return error.OutOfMemory;
l.note("{s}: {t}", .{ l.field, err });
@@ -1204,7 +1220,7 @@ pub fn Load(comptime roots: []const type) type {
if (comptime @hasDecl(T, "dumpFree")) try l.customs.append(l.own, .{ .ptr = out, .gpa = l.gpa, .free = @ptrCast(&T.dumpFree) });
},
.bitset => {
- const bits = try l.scalar(u64);
+ const bits = try l.count();
out.* = try .initEmpty(l.gpa, bits);
const words = (bits + @bitSizeOf(usize) - 1) / @bitSizeOf(usize);
if (words > 0) @memcpy(std.mem.sliceAsBytes(out.masks[0..words]), try l.take(words * @sizeOf(usize)));
@@ -1232,7 +1248,7 @@ pub fn Load(comptime roots: []const type) type {
fn slice(l: *Self, comptime E: type, s: SrcType) DecodeError![]E {
if (try l.ref()) |again| return @as([*]E, @ptrCast(@alignCast(again.ptr)))[0 .. again.len / @max(1, @sizeOf(E))];
- const n = try l.scalar(u64);
+ const n = try l.count();
if (n == 0) return &.{};
if (n > l.bytes.len) return error.BadDump;
const many = try l.gpa.alloc(E, n);
@@ -1264,7 +1280,7 @@ pub fn Load(comptime roots: []const type) type {
// cannot be read is left out, not the array.
const droppable = comptime @typeInfo(E) == .optional and @typeInfo(@typeInfo(E).optional.child) == .pointer;
var failed = false;
- for (0..n) |i| {
+ for (0..try countOf(n)) |i| {
if (i >= keep) {
try l.skip(ty);
continue;
@@ -1394,8 +1410,8 @@ pub fn Load(comptime roots: []const type) type {
.error_union => if ((try l.take(1))[0] != 0) try l.skip(s.child) else {
_ = try l.name();
},
- .custom => _ = try l.take(try l.scalar(u64)),
- .bitset => _ = try l.take((try l.scalar(u64) + 63) / 64 * 8),
+ .custom => _ = try l.take(try l.count()),
+ .bitset => _ = try l.take((try l.count() + 63) / 64 * 8),
}
}
@@ -1407,7 +1423,7 @@ pub fn Load(comptime roots: []const type) type {
_ = try l.take(@intCast(n * size));
return;
}
- for (0..n) |_| try l.skip(ty);
+ for (0..try countOf(n)) |_| try l.skip(ty);
}
};
}
diff --git a/test/web-snapshots/README.md b/test/web-snapshots/README.md
index a7cd865e..999e8fad 100644
--- a/test/web-snapshots/README.md
+++ b/test/web-snapshots/README.md
@@ -1,6 +1,6 @@
# Browser interaction tests
-`zig build web-snap` loads `touch.dump.zon` and runs `touch.mjs` in Chromium.
+`zig build web-snap` loads `touch.dump` (`python3 -B tools/web_fixture.py <pardes> test/web-snapshots/touch.dump` makes it: a native session on `touch-fixture.zig` at 100x30, theme helix, Verbose off) and runs `touch.mjs` in Chromium.
The fixed source fixture exercises complete keyword styles, touch Look through
the self filesystem, separator resizing, and scrolling without another Look.
Assertions locate current pane geometry; no live project source or author paths
diff --git a/test/web-snapshots/touch-fixture.zig b/test/web-snapshots/touch-fixture.zig
new file mode 100644
index 00000000..b1d5d81e
--- /dev/null
+++ b/test/web-snapshots/touch-fixture.zig
@@ -0,0 +1,58 @@
+pub fn choose(value: u32) []const u8 {
+ if (value == 42) return "touch fixture";
+ return "/virtual/pane/1/body";
+}
+
+pub const rows = [_]u32{
+ 0,
+ 1,
+ 2,
+ 3,
+ 4,
+ 5,
+ 6,
+ 7,
+ 8,
+ 9,
+ 10,
+ 11,
+ 12,
+ 13,
+ 14,
+ 15,
+ 16,
+ 17,
+ 18,
+ 19,
+ 20,
+ 21,
+ 22,
+ 23,
+ 24,
+ 25,
+ 26,
+ 27,
+ 28,
+ 29,
+ 30,
+ 31,
+ 32,
+ 33,
+ 34,
+ 35,
+ 36,
+ 37,
+ 38,
+ 39,
+ 40,
+ 41,
+ 42,
+ 43,
+ 44,
+ 45,
+ 46,
+ 47,
+ 48,
+ 49,
+ 50,
+}; \ No newline at end of file
diff --git a/test/web-snapshots/touch.dump b/test/web-snapshots/touch.dump
new file mode 100644
index 00000000..bcc58352
--- /dev/null
+++ b/test/web-snapshots/touch.dump
Binary files differ
diff --git a/test/web-snapshots/touch.dump.zon b/test/web-snapshots/touch.dump.zon
deleted file mode 100644
index 230d29e7..00000000
--- a/test/web-snapshots/touch.dump.zon
+++ /dev/null
@@ -1,73 +0,0 @@
-.{
- .screen = .{ .cols = 100, .rows = 30 },
- .theme = "helix",
- .columns = .{.{ .panes = .{0} }},
- .panes = .{.{
- .kind = .file,
- .tag = "touch-fixture.zig",
- .body = "",
- .file = .{
- .path = "touch-fixture.zig",
- .content =
- \\pub fn choose(value: u32) []const u8 {
- \\ if (value == 42) return "touch fixture";
- \\ return "/virtual/pane/1/body";
- \\}
- \\
- \\pub const rows = [_]u32{
- \\ 0,
- \\ 1,
- \\ 2,
- \\ 3,
- \\ 4,
- \\ 5,
- \\ 6,
- \\ 7,
- \\ 8,
- \\ 9,
- \\ 10,
- \\ 11,
- \\ 12,
- \\ 13,
- \\ 14,
- \\ 15,
- \\ 16,
- \\ 17,
- \\ 18,
- \\ 19,
- \\ 20,
- \\ 21,
- \\ 22,
- \\ 23,
- \\ 24,
- \\ 25,
- \\ 26,
- \\ 27,
- \\ 28,
- \\ 29,
- \\ 30,
- \\ 31,
- \\ 32,
- \\ 33,
- \\ 34,
- \\ 35,
- \\ 36,
- \\ 37,
- \\ 38,
- \\ 39,
- \\ 40,
- \\ 41,
- \\ 42,
- \\ 43,
- \\ 44,
- \\ 45,
- \\ 46,
- \\ 47,
- \\ 48,
- \\ 49,
- \\ 50,
- \\};
- ,
- },
- }},
-}
diff --git a/test/web-snapshots/touch.mjs b/test/web-snapshots/touch.mjs
index 69f8a4a5..3793c0f9 100644
--- a/test/web-snapshots/touch.mjs
+++ b/test/web-snapshots/touch.mjs
@@ -1,8 +1,9 @@
import assert from "node:assert/strict";
function tags(frame) {
- // This fixture has workspace and column bars in its first two rows.
- return frame.styleRows.flatMap((cells, y) => y > 1 && /^\s{3}\S/.test(frame.lines[y]) && cells.some((cell) => cell[2] & 128) ? [y] : []);
+ // This fixture has workspace and column bars in its first two rows; a
+ // pane's tag text starts after the two-cell marker gutter.
+ return frame.styleRows.flatMap((cells, y) => y > 1 && /^\s{2}\S/.test(frame.lines[y]) && cells.some((cell) => cell[2] & 128) ? [y] : []);
}
function pane(frame, name) {
@@ -13,14 +14,17 @@ function pane(frame, name) {
return { top, bottom, lines: frame.lines.slice(top + 1, bottom) };
}
+// helix's keyword and string/number colours (src/themes/helix.zig).
+const KW = 0xd776f9, STR = 0xf3cd7a;
+
function styled(frame) {
const source = pane(frame, "touch-fixture.zig");
for (const [line, word, fg, bold] of [
- ["pub fn choose", "fn", 0xcf87e8, false],
+ ["pub fn choose", "fn", KW, false],
["pub fn choose", "choose", 0xbdbdbd, false],
- ["if (value", "if", 0xcf87e8, false],
- ["if (value", "42", 0xe3c78a, false],
- ["if (value", '"touch fixture"', 0xe3c78a, false],
+ ["if (value", "if", KW, false],
+ ["if (value", "42", STR, false],
+ ["if (value", '"touch fixture"', STR, false],
]) {
const row = source.lines.findIndex((text) => text.includes(line));
assert(row >= 0, `missing source line ${line}`);
@@ -35,7 +39,7 @@ function styled(frame) {
const number = /\b(\d+),/.exec(line);
if (!number) continue;
for (let x = number.index; x < number.index + number[1].length; x++) {
- assert.equal(frame.styleRows[source.top + 1 + row][x][0], 0xe3c78a, `row ${row} number foreground`);
+ assert.equal(frame.styleRows[source.top + 1 + row][x][0], STR, `row ${row} number foreground`);
}
}
}
@@ -79,7 +83,8 @@ export default async function ({ grid, touch, wait, stable, delay, evaluate, mou
renderer.render();
result.closedGapBorders=borders();
result.borderChangeInvalidates=renderer.layerRoot.firstChild!==withGap;
- const tagValues=[2,2,0,42,1,0,1,1,1,1,0x334455];
+ // The 13 fields of a tag layer: a one-line tag, its caret on line 0.
+ const tagValues=[2,2,0,42,1,0,1,1,1,1,0x334455,1,0];
wasm.pardes_tag_layer_limit=()=>1;
wasm.pardes_tag_layer_value=(_,field)=>tagValues[field];
wasm.pardes_tag_layer_cells=()=>1024;
diff --git a/tools/web_fixture.py b/tools/web_fixture.py
new file mode 100644
index 00000000..06fc54cd
--- /dev/null
+++ b/tools/web_fixture.py
@@ -0,0 +1,34 @@
+"""web_fixture.py PARDES OUT: the web shell's touch fixture as a dump of this
+build: one pane on touch-fixture.zig at 100x30, theme helix.
+
+ python3 -B tools/web_fixture.py <pardes> test/web-snapshots/touch.dump
+"""
+import os, sys, time, shutil, struct, fcntl, termios
+from pathlib import Path
+sys.path.insert(0, str(Path(__file__).resolve().parent.parent / 'test'))
+import fs # noqa: E402
+
+binary, out = sys.argv[1], sys.argv[2]
+root = Path('/tmp/pardes-web-fixture') # fixed: the dump names it
+shutil.rmtree(root, ignore_errors=True)
+root.mkdir(parents=True, mode=0o700)
+shutil.copy(Path(__file__).resolve().parent.parent / 'test' / 'web-snapshots' / 'touch-fixture.zig', root / 'touch-fixture.zig')
+# Set at startup, which announces nothing: a fixture with no message on
+# its pane.
+(root / 'config' / 'pardes').mkdir(parents=True)
+(root / 'config' / 'pardes' / 'init').write_text('Theme helix\nVerbose off\n')
+handles = {}
+with fs.session(binary, root, 'web', tty=True, file=root / 'touch-fixture.zig', inherited={'PARDES_DAEMON': 'off'}, terminal=handles) as (client, address):
+ fcntl.ioctl(handles['input_fd'], termios.TIOCSWINSZ, struct.pack('HHHH', 30, 100, 0, 0))
+ deadline = time.monotonic() + 10
+ while client.screen()['cols'] != 100:
+ assert time.monotonic() < deadline
+ time.sleep(.01)
+ client.write('/ctl', b'Dump\n')
+ while b'\ndump ' not in client.read('/log'):
+ assert time.monotonic() < deadline
+ time.sleep(.01)
+ print(client.read('/index').decode())
+ shutil.copy(root / 'web.dump.zon', out)
+shutil.rmtree(root, ignore_errors=True)
+print(os.path.getsize(out), 'bytes')