aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/src/synthetic/cli
diff options
context:
space:
mode:
authorOgulcan Celik <ogulcancelik@gmail.com>2026-07-16 23:28:05 +0300
committerOgulcan Celik <ogulcancelik@gmail.com>2026-07-16 23:29:28 +0300
commit4a3302d19a2baa3a33e910e0088c24e780905b90 (patch)
treedcaf76fae1c82102d933c9225b17ca7ac5d3a847 /vendor/libghostty-vt/src/synthetic/cli
parent550e9f8cc085f428429f5cf2da0bb2dba897e8b8 (diff)
chore: update vendored libghostty-vt
refs #276
Diffstat (limited to 'vendor/libghostty-vt/src/synthetic/cli')
-rw-r--r--vendor/libghostty-vt/src/synthetic/cli/Kitty.zig70
1 files changed, 70 insertions, 0 deletions
diff --git a/vendor/libghostty-vt/src/synthetic/cli/Kitty.zig b/vendor/libghostty-vt/src/synthetic/cli/Kitty.zig
new file mode 100644
index 00000000..99a92798
--- /dev/null
+++ b/vendor/libghostty-vt/src/synthetic/cli/Kitty.zig
@@ -0,0 +1,70 @@
+const Kitty = @This();
+
+const std = @import("std");
+const Allocator = std.mem.Allocator;
+const synthetic = @import("../main.zig");
+
+const log = std.log.scoped(.@"kitty-gen");
+
+pub const Options = struct {
+ /// The base64 payload length of each command in bytes, rounded
+ /// down to a multiple of four. Kitty clients typically chunk
+ /// payloads at 4096 bytes.
+ @"data-len": usize = 4096,
+};
+
+opts: Options,
+
+/// The buffer a single generated sequence is written into. Sized to
+/// the payload length plus room for the control data and terminator.
+buf: []u8,
+
+/// Create a new Kitty graphics sequence generator for the given arguments.
+pub fn create(
+ alloc: Allocator,
+ opts: Options,
+) !*Kitty {
+ const ptr = try alloc.create(Kitty);
+ errdefer alloc.destroy(ptr);
+
+ const buf = try alloc.alloc(u8, opts.@"data-len" + 128);
+ errdefer alloc.free(buf);
+
+ ptr.* = .{ .opts = opts, .buf = buf };
+ return ptr;
+}
+
+pub fn destroy(self: *Kitty, alloc: Allocator) void {
+ alloc.free(self.buf);
+ alloc.destroy(self);
+}
+
+pub fn run(self: *Kitty, writer: *std.Io.Writer, rand: std.Random) !void {
+ var gen: synthetic.Kitty = .{
+ .rand = rand,
+ .data_len = self.opts.@"data-len",
+ };
+
+ while (true) {
+ var fixed: std.Io.Writer = .fixed(self.buf);
+ try gen.next(&fixed, self.buf.len);
+ writer.writeAll(fixed.buffered()) catch |err| switch (err) {
+ error.WriteFailed => return,
+ };
+ }
+}
+
+test Kitty {
+ const testing = std.testing;
+ const alloc = testing.allocator;
+
+ const impl: *Kitty = try .create(alloc, .{});
+ defer impl.destroy(alloc);
+
+ var prng = std.Random.DefaultPrng.init(1);
+ const rand = prng.random();
+
+ var buf: [8192]u8 = undefined;
+ var writer: std.Io.Writer = .fixed(&buf);
+ try impl.run(&writer, rand);
+}