summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-10 11:30:01 -0300
committerGabriel Schneider <[email protected]>2026-11-11 18:57:59 -0300
commit1497cf19f852a5b38bc3e2f3641a81a077ba8a32 (patch)
tree4939a6ec709529a57bd75c29f50d0cf956014cd3
parent6b3df3071d16153bd554462c4f54ebb88f3ed50e (diff)
downloadpardes-1497cf19f852a5b38bc3e2f3641a81a077ba8a32.tar.gz
pardes-1497cf19f852a5b38bc3e2f3641a81a077ba8a32.zip
zstbi: upstream's main, the fork pinned before being gone: Pivok7/zstbi (zig-gamedev/zstbi PR #16, the Zig 0.17 port the manifest waited on) is deleted and a fresh checkout could not fetch it, while upstream has since ported itself (6b9bea1f); its init takes no Io and can fail, and its resize can fail, so TerminalImages.start takes the allocator alone (a start refused leaves PNGs refused, as before one) and a resize that fails is an undecodable PNG; host_io.startWorkers and tape.replayMain lose the Io they only handed on; build.zig's patch of zstbi.c applies unchanged (the file is the same); test: kitty: a PNG longer than 1280 pixels on a side is kept at 1280 (the one path through zstbi, which no case walked: a 1300-pixel one-bit PNG built in the test, its row stored); kitty-test 45 of 45; the changelog says so
-rw-r--r--build.zig.zon8
-rw-r--r--src/CHANGELOG.md3
-rw-r--r--src/TerminalImages.zig7
-rw-r--r--src/gui/gui.zig4
-rw-r--r--src/host_io.zig4
-rw-r--r--src/macos.zig2
-rw-r--r--src/main.zig2
-rw-r--r--src/tape.zig4
-rw-r--r--src/tui/tui.zig4
-rw-r--r--test/kitty.zig56
10 files changed, 76 insertions, 18 deletions
diff --git a/build.zig.zon b/build.zig.zon
index 360adbd9..6e0dc973 100644
--- a/build.zig.zon
+++ b/build.zig.zon
@@ -39,11 +39,11 @@
.hash = "uucode-0.2.0-ZZjBPoGFVgCiflJNFc6Io8xzC67B6PA5bUkk4LT0kCxg",
.lazy = true,
},
- // Pivok7's fork: zig-gamedev/zstbi PR #16, "Upgrade to zig 0.17.0"
- // (two lines of build.zig). Back to upstream once it is merged.
+ // Upstream's main, which builds with Zig 0.17 since its own update
+ // (the fork pinned before, Pivok7's PR #16, is deleted).
.zstbi = .{
- .url = "git+https://github.com/Pivok7/zstbi#bc96f28d341f9c7fb9cbc5dc65aa4c5cf0c8f007",
- .hash = "zstbi-0.11.0-dev-L0Ea_3GWBwCpNHVwGU4MPR_oDd0FoQOYNrGodwvJ6Z45",
+ .url = "git+https://github.com/zig-gamedev/zstbi#6b9bea1fd13eb7c8299f23605b4c6b04fccd9aa7",
+ .hash = "zstbi-0.11.0-dev-L0Ea_wGXBwCvXIzUWRNZe-6FpofI_nz4uAOQ4O0Fuxko",
.lazy = true,
},
// SDL3 (castholm/SDL zig bindings, its release-3.4.x branch for Zig
diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md
index 750b3744..633687e8 100644
--- a/src/CHANGELOG.md
+++ b/src/CHANGELOG.md
@@ -2,6 +2,9 @@
## Unreleased
+- zstbi is upstream's again (zig-gamedev/zstbi, its main): the fork pinned
+ for Zig 0.17 was deleted, and a fresh checkout could not fetch it.
+
- pardes's syntax is a library: a Zig package that depends on pardes is
given the `pardes-syntax` module (`src/lib_syntax.zig`), with the
grammars, highlighting, declarations, syntax tree and themes as the
diff --git a/src/TerminalImages.zig b/src/TerminalImages.zig
index c352c2a4..f8fed78e 100644
--- a/src/TerminalImages.zig
+++ b/src/TerminalImages.zig
@@ -123,8 +123,9 @@ const max_dim: u32 = 1280;
var started = false;
/// Once at startup and exit, with what the resize allocates from.
-pub fn start(io: std.Io, gpa: std.mem.Allocator) void {
- zstbi.init(io, gpa);
+pub fn start(gpa: std.mem.Allocator) void {
+ // Refused only when started twice with a resize still alive: PNGs then stay refused.
+ zstbi.init(gpa) catch return;
started = true;
}
pub fn stop() void {
@@ -149,7 +150,7 @@ fn decodePng(gpa: std.mem.Allocator, bytes: []const u8) ghostty_vt.sys.DecodeErr
if (longest <= max_dim) return .{ .width = got.width, .height = got.height, .data = got.data };
defer gpa.free(got.data);
const img: zstbi.Image = .{ .data = got.data, .width = got.width, .height = got.height, .num_components = 4, .bytes_per_component = 1, .bytes_per_row = got.width * 4, .is_hdr = false };
- var scaled = img.resize(@intCast(@max(1, @as(u64, got.width) * max_dim / longest)), @intCast(@max(1, @as(u64, got.height) * max_dim / longest)));
+ var scaled = img.resize(@intCast(@max(1, @as(u64, got.width) * max_dim / longest)), @intCast(@max(1, @as(u64, got.height) * max_dim / longest))) catch return error.InvalidData;
defer scaled.deinit();
return .{ .width = scaled.width, .height = scaled.height, .data = gpa.dupe(u8, scaled.data) catch return error.InvalidData };
}
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index e16d0576..537271f1 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -1310,7 +1310,7 @@ fn localSession(
const gpa = init.gpa;
const allocs = pardes.memory.init(gpa);
defer pardes.memory.deinit();
- host_io.startWorkers(io, allocs);
+ host_io.startWorkers(allocs);
defer host_io.stopWorkers();
var opts = opts_in;
opts.addons = pardes.Addon.scan();
@@ -1649,7 +1649,7 @@ fn remoteSession(init: std.process.Init, g: *Gui, opts_in: pardes.Options, test_
const have: ?*replica.Have = if (far) &have_store else null;
const allocs = pardes.memory.init(gpa);
defer pardes.memory.deinit();
- pardes.TerminalImages.start(io, allocs.image);
+ pardes.TerminalImages.start(allocs.image);
pardes.Kind.heap = allocs.addon;
pardes.syntax.start(allocs.tree_sitter);
defer {
diff --git a/src/host_io.zig b/src/host_io.zig
index be741020..3141ff64 100644
--- a/src/host_io.zig
+++ b/src/host_io.zig
@@ -172,8 +172,8 @@ pub fn testClock() ?u64 {
/// on `allocs` (pardes.memory.init), and what kinds keep past a call (their
/// heap, `pa_api.heap`: the pdf addon's documents and pages). `stopWorkers`
/// is its defer.
-pub fn startWorkers(io: std.Io, allocs: pardes.memory.Allocators) void {
- pardes.TerminalImages.start(io, allocs.image);
+pub fn startWorkers(allocs: pardes.memory.Allocators) void {
+ pardes.TerminalImages.start(allocs.image);
pardes.Kind.heap = allocs.addon;
pardes.syntax.start(allocs.tree_sitter);
}
diff --git a/src/macos.zig b/src/macos.zig
index c0d1c69c..254cf2a7 100644
--- a/src/macos.zig
+++ b/src/macos.zig
@@ -340,7 +340,7 @@ fn initCore(runtime: ?*const Runtime, cols_arg: u16, rows_arg: u16) !void {
if (found.dir) |d| crash.setDir(d);
}
- pardes.TerminalImages.start(io, allocs.image);
+ pardes.TerminalImages.start(allocs.image);
pardes.Kind.heap = allocs.addon;
// Its addons are compiled in (no loader runs here): image and PDF panes.
opts.addons = pardes.Addon.scan();
diff --git a/src/main.zig b/src/main.zig
index 03bed908..ed20dceb 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -363,7 +363,7 @@ fn nativeMain(std_init: std.process.Init) !void {
var init = std_init;
if (builtin.mode != .debug) init.gpa = pardes.memory.host(std.heap.c_allocator);
// A recorded session's tape replayed, no session of its own (src/tape.zig).
- if (init.environ_map.get("PARDES_REPLAY")) |tape| std.process.exit(pardes.tape.replayMain(init.io, tape));
+ if (init.environ_map.get("PARDES_REPLAY")) |tape| std.process.exit(pardes.tape.replayMain(tape));
var stderr_probe: [64]u8 = undefined;
_ = std.debug.lockStderr(&stderr_probe);
std.debug.unlockStderr();
diff --git a/src/tape.zig b/src/tape.zig
index 4db78b86..c617f2a2 100644
--- a/src/tape.zig
+++ b/src/tape.zig
@@ -1244,10 +1244,10 @@ pub fn startFromEnv() void {
/// `PARDES_REPLAY=<tape>`: the tape replayed into three replicas, each
/// digest checked; 0 when none diverged.
-pub fn replayMain(io: std.Io, path: []const u8) u8 {
+pub fn replayMain(path: []const u8) u8 {
const gpa = std.heap.c_allocator;
// What a shell starts before its core (tui.zig's localSession).
- pardes.TerminalImages.start(io, gpa);
+ pardes.TerminalImages.start(gpa);
pardes.syntax.start(gpa);
const bytes = std.Io.Dir.cwd().readFileAlloc(std.Io.Threaded.global_single_threaded.io(), path, gpa, .unlimited) catch |err| {
std.debug.print("replay: cannot read {s}: {t}\n", .{ path, err });
diff --git a/src/tui/tui.zig b/src/tui/tui.zig
index 73103046..0daac14b 100644
--- a/src/tui/tui.zig
+++ b/src/tui/tui.zig
@@ -685,7 +685,7 @@ pub fn remote(init: std.process.Init, opts: pardes.Options, path: []const u8, se
const have: ?*replica.Have = if (far) &have_store else null;
const allocs = pardes.memory.init(gpa);
defer pardes.memory.deinit();
- pardes.TerminalImages.start(io, allocs.image);
+ pardes.TerminalImages.start(allocs.image);
pardes.Kind.heap = allocs.addon;
pardes.syntax.start(allocs.tree_sitter);
defer {
@@ -978,7 +978,7 @@ fn localSession(
options.tree_sitter_allocator = allocs.tree_sitter;
options.frame_allocator = allocs.frame;
- host_io.startWorkers(io, allocs);
+ host_io.startWorkers(allocs);
defer host_io.stopWorkers();
options.addons = pardes.Addon.scan();
diff --git a/test/kitty.zig b/test/kitty.zig
index ad70f453..ac407e1a 100644
--- a/test/kitty.zig
+++ b/test/kitty.zig
@@ -66,7 +66,7 @@ const Rig = struct {
fn init(shells: u8) !Rig {
// f=100 decodes through wuffs, its resize through stb_image_resize,
// which the shells start at launch.
- pardes.TerminalImages.start(std.testing.io, gpa);
+ pardes.TerminalImages.start(gpa);
// ghostty warns of every refused command; the refusals are the point.
std.testing.log_level = .err;
// A core boots one shell or the classic three.
@@ -211,6 +211,60 @@ test "kitty: quiet levels: q=1 drops the OK, q=2 the errors too" {
}
}
+/// A one-row, one-bit grayscale PNG `width` pixels wide, its row stored
+/// uncompressed: a few hundred bytes however wide.
+fn widePng(arena: std.mem.Allocator, width: u32) ![]const u8 {
+ var out: std.ArrayList(u8) = .empty;
+ try out.appendSlice(arena, "\x89PNG\r\n\x1a\n");
+ const chunk = struct {
+ fn add(list: *std.ArrayList(u8), a: std.mem.Allocator, kind: *const [4]u8, data: []const u8) !void {
+ var word: [4]u8 = undefined;
+ std.mem.writeInt(u32, &word, @intCast(data.len), .big);
+ try list.appendSlice(a, &word);
+ const from = list.items.len;
+ try list.appendSlice(a, kind);
+ try list.appendSlice(a, data);
+ std.mem.writeInt(u32, &word, std.hash.Crc32.hash(list.items[from..]), .big);
+ try list.appendSlice(a, &word);
+ }
+ }.add;
+ var ihdr: [13]u8 = .{ 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0 };
+ std.mem.writeInt(u32, ihdr[0..4], width, .big);
+ try chunk(&out, arena, "IHDR", &ihdr);
+ // The filter byte and the row, in one stored deflate block.
+ const row = try arena.alloc(u8, 1 + (width + 7) / 8);
+ @memset(row, 0);
+ var idat: std.ArrayList(u8) = .empty;
+ try idat.appendSlice(arena, &.{ 0x78, 0x01, 0x01 });
+ var len: [2]u8 = undefined;
+ std.mem.writeInt(u16, &len, @intCast(row.len), .little);
+ try idat.appendSlice(arena, &len);
+ std.mem.writeInt(u16, &len, ~@as(u16, @intCast(row.len)), .little);
+ try idat.appendSlice(arena, &len);
+ try idat.appendSlice(arena, row);
+ var sum: [4]u8 = undefined;
+ std.mem.writeInt(u32, &sum, std.hash.Adler32.hash(row), .big);
+ try idat.appendSlice(arena, &sum);
+ try chunk(&out, arena, "IDAT", idat.items);
+ try chunk(&out, arena, "IEND", "");
+ return out.items;
+}
+
+test "kitty: a PNG longer than 1280 pixels on a side is kept at 1280" {
+ var r = try Rig.init(1);
+ defer r.deinit();
+ const arena = r.frame.allocator();
+ const png = try widePng(arena, 1300);
+ const payload = try arena.alloc(u8, std.base64.standard.Encoder.calcSize(png.len));
+ _ = std.base64.standard.Encoder.encode(payload, png);
+ r.feed(0, try std.fmt.allocPrint(arena, "\x1b_Ga=T,i=1,f=100,c=2,r=1;{s}\x1b\\", .{payload}));
+ try std.testing.expectEqualStrings(reply("i=1", "OK"), try r.take(0));
+ // Decoded by wuffs at 1300, brought down by stb_image_resize (zstbi).
+ const img = r.storage(0).imageById(1) orelse return error.NotStored;
+ try std.testing.expectEqual(@as(u32, 1280), img.width);
+ try std.testing.expectEqual(@as(u32, 1), img.height);
+}
+
test "kitty: RGB, RGBA, PNG and zlib-compressed RGB all draw the same pixels" {
const Case = struct { control: []const u8, payload: []const u8 };
const cases = [_]Case{