diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-06 12:40:11 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-06 14:56:36 -0300 |
| commit | 80f4398f1fed8d46d73cab8045005c02189b34fc (patch) | |
| tree | ad60d6e83a1ba08d9869012ac819ff58ca826248 /src/wire.zig | |
| parent | a864ef66736d3cfbdffed8b98a3c46be7985db74 (diff) | |
| download | pardes-80f4398f1fed8d46d73cab8045005c02189b34fc.tar.gz pardes-80f4398f1fed8d46d73cab8045005c02189b34fc.zip | |
idioms #14, the rest: wire's has_cell_pixels (@hasField on a struct that always has the field) goes with its comptime branches, syntax's predicate ops are a stringToEnum switch, the public surfaces of sam_edit, locations, Names, Macro, selection_pipe, recent and builtins_json name their sets (OutOfMemory, Writer.Error), and std.fs.path and max_path_bytes are std.Io.Dir's
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/wire.zig')
| -rw-r--r-- | src/wire.zig | 26 |
1 files changed, 6 insertions, 20 deletions
diff --git a/src/wire.zig b/src/wire.zig index e39e25b4..65b93bf1 100644 --- a/src/wire.zig +++ b/src/wire.zig @@ -396,11 +396,6 @@ fn clientTag(msg: ClientMsg) ClientTag { }; } -/// Does the build this frontend was compiled with carry pixel dimensions in a -/// resize? The FIELD is comptime-conditional (pardes.zig `CellPixels`); the -/// WIRE is not. -const has_cell_pixels = @hasField(pardes.CellPixels, "w"); - fn putMetrics(w: *std.Io.Writer, metrics: ?pardes.RowMetrics) Error!void { try w.writeByte(@intFromBool(metrics != null)); if (metrics) |m| { @@ -525,11 +520,8 @@ pub fn encodeClient(out: []u8, msg: ClientMsg) Error![]const u8 { .resize => |rs| { try w.writeInt(u16, rs.cols, .little); try w.writeInt(u16, rs.rows, .little); - // The conventional 1:2 cell aspect when this build has no - // pixels of its own, which is the same default the field - // carries where it exists. - try w.writeInt(u16, if (comptime has_cell_pixels) rs.cell_pixels.w else 8, .little); - try w.writeInt(u16, if (comptime has_cell_pixels) rs.cell_pixels.h else 16, .little); + try w.writeInt(u16, rs.cell_pixels.w, .little); + try w.writeInt(u16, rs.cell_pixels.h, .little); try putMetrics(&w, rs.row_metrics); }, .paste => |b| try putSlice32(&w, b), @@ -605,10 +597,7 @@ pub fn decodeClient(tag: u8, payload: []const u8) Error!ClientMsg { .resize => blk: { var ev: pardes.Event = .{ .resize = .{ .cols = try getCols(&r), .rows = try getRows(&r) } }; const px_w = try r.takeInt(u16, .little); - const px_h = try r.takeInt(u16, .little); - // Read either way — the bytes are on the wire — and kept only by a - // build that has somewhere to keep them. - if (comptime has_cell_pixels) ev.resize.cell_pixels = .{ .w = px_w, .h = px_h }; + ev.resize.cell_pixels = .{ .w = px_w, .h = try r.takeInt(u16, .little) }; ev.resize.row_metrics = try getMetrics(&r); break :blk .{ .event = ev }; }, @@ -727,12 +716,9 @@ test "detached wire: every Event variant round-trips" { const got = (try roundClient(&buf, .{ .event = .{ .resize = .{ .cols = 56, .rows = 14 } } })).event.resize; try testing.expectEqual(@as(u16, 56), got.cols); try testing.expectEqual(@as(u16, 14), got.rows); - // Pixels travel whether or not this build has them; where it does, the - // conventional 1:2 default survives the trip. - if (comptime has_cell_pixels) { - try testing.expectEqual(@as(u16, 8), got.cell_pixels.w); - try testing.expectEqual(@as(u16, 16), got.cell_pixels.h); - } + // The conventional 1:2 default survives the trip. + try testing.expectEqual(@as(u16, 8), got.cell_pixels.w); + try testing.expectEqual(@as(u16, 16), got.cell_pixels.h); } try testing.expectEqualStrings("clip", (try roundClient(&buf, .{ .event = .{ .paste = "clip" } })).event.paste); try testing.expectEqualStrings("Look /x", (try roundClient(&buf, .{ .event = .{ .command = "Look /x" } })).event.command); |
