aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/src/terminal/snapshot/io.zig
diff options
context:
space:
mode:
authorCan Celik <ogulcancelik@gmail.com>2026-09-10 21:51:57 +0300
committerGitHub <noreply@github.com>2026-09-10 21:51:57 +0300
commit425c86179791cd32e2d4ce0ae7f269940b4b0663 (patch)
treee52c4383a6d69216cbe2a32638bf90841d7e2189 /vendor/libghostty-vt/src/terminal/snapshot/io.zig
parent90e947a6e26e02f10ec7f1694c4eb5b78a86406b (diff)
chore: upgrade libghostty and preserve terminal behavior (#3906)
Diffstat (limited to 'vendor/libghostty-vt/src/terminal/snapshot/io.zig')
-rw-r--r--vendor/libghostty-vt/src/terminal/snapshot/io.zig55
1 files changed, 55 insertions, 0 deletions
diff --git a/vendor/libghostty-vt/src/terminal/snapshot/io.zig b/vendor/libghostty-vt/src/terminal/snapshot/io.zig
new file mode 100644
index 00000000..d47f96cc
--- /dev/null
+++ b/vendor/libghostty-vt/src/terminal/snapshot/io.zig
@@ -0,0 +1,55 @@
+//! Wire-format I/O helpers.
+//!
+//! These are sometimes very thin layers over standard `std.Io.Writer`
+//! but its to help ensure consistency in our behavior and avoid some
+//! pitfalls.
+
+const std = @import("std");
+const testing = std.testing;
+
+/// writeInt ensures we write in little-endian since that is our
+/// standard form.
+pub fn writeInt(
+ writer: *std.Io.Writer,
+ comptime T: type,
+ value: T,
+) std.Io.Writer.Error!void {
+ try writer.writeInt(T, value, .little);
+}
+
+/// Read a little-endian integer.
+///
+/// This avoids `takeInt` because at the time of writing this the underlying
+/// implementation uses `takeArray` which asserts that the reader buffer
+/// is as large as T. Our approach works with caller-selected buffers that
+/// may be smaller.
+pub fn readInt(
+ reader: *std.Io.Reader,
+ comptime T: type,
+) std.Io.Reader.Error!T {
+ var buf: [@sizeOf(T)]u8 = undefined;
+ try reader.readSliceAll(&buf);
+ return std.mem.readInt(T, &buf, .little);
+}
+
+test "integer round trip with a one-byte reader buffer" {
+ var encoded: [6]u8 = undefined;
+ var writer: std.Io.Writer = .fixed(&encoded);
+ try writeInt(&writer, u16, 0x1234);
+ try writeInt(&writer, u32, 0x56789abc);
+
+ // Keep the reader buffer smaller than either integer to verify readInt
+ // does not inherit std.Io.Reader.takeInt's buffer-size requirement.
+ var source: std.Io.Reader = .fixed(&encoded);
+ var buf: [1]u8 = undefined;
+ var limited = source.limited(.unlimited, &buf);
+
+ try testing.expectEqual(
+ @as(u16, 0x1234),
+ try readInt(&limited.interface, u16),
+ );
+ try testing.expectEqual(
+ @as(u32, 0x56789abc),
+ try readInt(&limited.interface, u32),
+ );
+}