aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/src/synthetic/cli
diff options
context:
space:
mode:
authorCan Celik <ogulcancelik@gmail.com>2026-04-04 19:22:04 +0300
committerCan Celik <ogulcancelik@gmail.com>2026-04-05 01:23:06 +0300
commit41dd733ca7123c9ac4bfc6c781697a660e95b052 (patch)
tree3fc91815ca139ef2e0b281bba0abda4ef15175f4 /vendor/libghostty-vt/src/synthetic/cli
parent55c138263e190a1e79d4b997bfb9397306c0ec1f (diff)
feat: finish ghostty pane backend integration
Diffstat (limited to 'vendor/libghostty-vt/src/synthetic/cli')
-rw-r--r--vendor/libghostty-vt/src/synthetic/cli/Ascii.zig68
-rw-r--r--vendor/libghostty-vt/src/synthetic/cli/Osc.zig82
-rw-r--r--vendor/libghostty-vt/src/synthetic/cli/Utf8.zig58
3 files changed, 208 insertions, 0 deletions
diff --git a/vendor/libghostty-vt/src/synthetic/cli/Ascii.zig b/vendor/libghostty-vt/src/synthetic/cli/Ascii.zig
new file mode 100644
index 00000000..d416189c
--- /dev/null
+++ b/vendor/libghostty-vt/src/synthetic/cli/Ascii.zig
@@ -0,0 +1,68 @@
+const Ascii = @This();
+
+const std = @import("std");
+const assert = std.debug.assert;
+const Allocator = std.mem.Allocator;
+const Bytes = @import("../Bytes.zig");
+
+const log = std.log.scoped(.@"terminal-stream-bench");
+
+pub const Options = struct {};
+
+fn checkAsciiAlphabet(c: u8) bool {
+ return switch (c) {
+ ' ' => false,
+ else => std.ascii.isPrint(c),
+ };
+}
+
+pub const ascii = Bytes.generateAlphabet(checkAsciiAlphabet);
+
+/// Create a new terminal stream handler for the given arguments.
+pub fn create(
+ alloc: Allocator,
+ _: Options,
+) !*Ascii {
+ const ptr = try alloc.create(Ascii);
+ errdefer alloc.destroy(ptr);
+ return ptr;
+}
+
+pub fn destroy(self: *Ascii, alloc: Allocator) void {
+ alloc.destroy(self);
+}
+
+pub fn run(_: *Ascii, writer: *std.Io.Writer, rand: std.Random) !void {
+ var gen: Bytes = .{
+ .rand = rand,
+ .alphabet = ascii,
+ .min_len = 1024,
+ .max_len = 1024,
+ };
+
+ while (true) {
+ _ = gen.write(writer) catch |err| {
+ const Error = error{ WriteFailed, BrokenPipe } || @TypeOf(err);
+ switch (@as(Error, err)) {
+ error.BrokenPipe => return, // stdout closed
+ error.WriteFailed => return, // fixed buffer full
+ else => return err,
+ }
+ };
+ }
+}
+
+test Ascii {
+ const testing = std.testing;
+ const alloc = testing.allocator;
+
+ const impl: *Ascii = try .create(alloc, .{});
+ defer impl.destroy(alloc);
+
+ var prng = std.Random.DefaultPrng.init(1);
+ const rand = prng.random();
+
+ var buf: [1024]u8 = undefined;
+ var writer: std.Io.Writer = .fixed(&buf);
+ try impl.run(&writer, rand);
+}
diff --git a/vendor/libghostty-vt/src/synthetic/cli/Osc.zig b/vendor/libghostty-vt/src/synthetic/cli/Osc.zig
new file mode 100644
index 00000000..686563fc
--- /dev/null
+++ b/vendor/libghostty-vt/src/synthetic/cli/Osc.zig
@@ -0,0 +1,82 @@
+const Osc = @This();
+
+const std = @import("std");
+const assert = std.debug.assert;
+const Allocator = std.mem.Allocator;
+const synthetic = @import("../main.zig");
+
+const log = std.log.scoped(.@"terminal-stream-bench");
+
+pub const Options = struct {
+ /// Probability of generating a valid value.
+ @"p-valid": f64 = 0.5,
+
+ style: enum {
+ /// Write all OSC data, including ESC ] and ST for end-to-end tests
+ streaming,
+ /// Only write data, prefixed with a length, used for testing just the
+ /// OSC parser.
+ parser,
+ } = .streaming,
+};
+
+opts: Options,
+
+/// Create a new terminal stream handler for the given arguments.
+pub fn create(
+ alloc: Allocator,
+ opts: Options,
+) !*Osc {
+ const ptr = try alloc.create(Osc);
+ errdefer alloc.destroy(ptr);
+ ptr.* = .{ .opts = opts };
+ return ptr;
+}
+
+pub fn destroy(self: *Osc, alloc: Allocator) void {
+ alloc.destroy(self);
+}
+
+pub fn run(self: *Osc, writer: *std.Io.Writer, rand: std.Random) !void {
+ var gen: synthetic.Osc = .{
+ .rand = rand,
+ .p_valid = self.opts.@"p-valid",
+ };
+
+ var buf: [1024]u8 = undefined;
+ while (true) {
+ var fixed: std.Io.Writer = .fixed(&buf);
+ try gen.next(&fixed, buf.len);
+ const data = fixed.buffered();
+ switch (self.opts.style) {
+ .streaming => {
+ writer.writeAll(data) catch |err| switch (err) {
+ error.WriteFailed => return,
+ };
+ },
+ .parser => {
+ writer.writeInt(usize, data.len - 3, .little) catch |err| switch (err) {
+ error.WriteFailed => return,
+ };
+ writer.writeAll(data[2 .. data.len - 1]) catch |err| switch (err) {
+ error.WriteFailed => return,
+ };
+ },
+ }
+ }
+}
+
+test Osc {
+ const testing = std.testing;
+ const alloc = testing.allocator;
+
+ const impl: *Osc = try .create(alloc, .{});
+ defer impl.destroy(alloc);
+
+ var prng = std.Random.DefaultPrng.init(1);
+ const rand = prng.random();
+
+ var buf: [1024]u8 = undefined;
+ var writer: std.Io.Writer = .fixed(&buf);
+ try impl.run(&writer, rand);
+}
diff --git a/vendor/libghostty-vt/src/synthetic/cli/Utf8.zig b/vendor/libghostty-vt/src/synthetic/cli/Utf8.zig
new file mode 100644
index 00000000..63570475
--- /dev/null
+++ b/vendor/libghostty-vt/src/synthetic/cli/Utf8.zig
@@ -0,0 +1,58 @@
+const Utf8 = @This();
+
+const std = @import("std");
+const assert = std.debug.assert;
+const Allocator = std.mem.Allocator;
+const synthetic = @import("../main.zig");
+
+const log = std.log.scoped(.@"terminal-stream-bench");
+
+pub const Options = struct {};
+
+/// Create a new terminal stream handler for the given arguments.
+pub fn create(
+ alloc: Allocator,
+ _: Options,
+) !*Utf8 {
+ const ptr = try alloc.create(Utf8);
+ errdefer alloc.destroy(ptr);
+ return ptr;
+}
+
+pub fn destroy(self: *Utf8, alloc: Allocator) void {
+ alloc.destroy(self);
+}
+
+pub fn run(self: *Utf8, writer: *std.Io.Writer, rand: std.Random) !void {
+ _ = self;
+
+ var gen: synthetic.Utf8 = .{
+ .rand = rand,
+ };
+
+ while (true) {
+ gen.next(writer, 1024) catch |err| {
+ const Error = error{ WriteFailed, BrokenPipe } || @TypeOf(err);
+ switch (@as(Error, err)) {
+ error.BrokenPipe => return, // stdout closed
+ error.WriteFailed => return, // fixed buffer full
+ else => return err,
+ }
+ };
+ }
+}
+
+test Utf8 {
+ const testing = std.testing;
+ const alloc = testing.allocator;
+
+ const impl: *Utf8 = try .create(alloc, .{});
+ defer impl.destroy(alloc);
+
+ var prng = std.Random.DefaultPrng.init(1);
+ const rand = prng.random();
+
+ var buf: [1024]u8 = undefined;
+ var writer: std.Io.Writer = .fixed(&buf);
+ try impl.run(&writer, rand);
+}