aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/src/benchmark/cli.zig
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/benchmark/cli.zig
parent55c138263e190a1e79d4b997bfb9397306c0ec1f (diff)
feat: finish ghostty pane backend integration
Diffstat (limited to 'vendor/libghostty-vt/src/benchmark/cli.zig')
-rw-r--r--vendor/libghostty-vt/src/benchmark/cli.zig100
1 files changed, 100 insertions, 0 deletions
diff --git a/vendor/libghostty-vt/src/benchmark/cli.zig b/vendor/libghostty-vt/src/benchmark/cli.zig
new file mode 100644
index 00000000..13f07077
--- /dev/null
+++ b/vendor/libghostty-vt/src/benchmark/cli.zig
@@ -0,0 +1,100 @@
+const std = @import("std");
+const Allocator = std.mem.Allocator;
+const cli = @import("../cli.zig");
+
+/// The available actions for the CLI. This is the list of available
+/// benchmarks. View docs for each individual one in the predictably
+/// named files.
+pub const Action = enum {
+ @"codepoint-width",
+ @"grapheme-break",
+ @"screen-clone",
+ @"terminal-parser",
+ @"terminal-stream",
+ @"is-symbol",
+ @"osc-parser",
+
+ /// Returns the struct associated with the action. The struct
+ /// should have a few decls:
+ ///
+ /// - `const Options`: The CLI options for the action.
+ /// - `fn create`: Create a new instance of the action from options.
+ /// - `fn benchmark`: Returns a `Benchmark` instance for the action.
+ ///
+ /// See TerminalStream for an example.
+ pub fn Struct(comptime action: Action) type {
+ return switch (action) {
+ .@"screen-clone" => @import("ScreenClone.zig"),
+ .@"terminal-stream" => @import("TerminalStream.zig"),
+ .@"codepoint-width" => @import("CodepointWidth.zig"),
+ .@"grapheme-break" => @import("GraphemeBreak.zig"),
+ .@"terminal-parser" => @import("TerminalParser.zig"),
+ .@"is-symbol" => @import("IsSymbol.zig"),
+ .@"osc-parser" => @import("OscParser.zig"),
+ };
+ }
+};
+
+/// An entrypoint for the benchmark CLI.
+pub fn main() !void {
+ const alloc = std.heap.c_allocator;
+ const action_ = try cli.action.detectArgs(Action, alloc);
+ const action = action_ orelse return error.NoAction;
+ try mainAction(alloc, action, .cli);
+}
+
+/// Arguments that can be passed to the benchmark.
+pub const Args = union(enum) {
+ /// The arguments passed to the CLI via argc/argv.
+ cli,
+
+ /// Simple string arguments, parsed via std.process.ArgIteratorGeneral.
+ string: []const u8,
+};
+
+pub fn mainAction(
+ alloc: Allocator,
+ action: Action,
+ args: Args,
+) !void {
+ switch (action) {
+ inline else => |comptime_action| {
+ const BenchmarkImpl = Action.Struct(comptime_action);
+ try mainActionImpl(BenchmarkImpl, alloc, args);
+ },
+ }
+}
+
+fn mainActionImpl(
+ comptime BenchmarkImpl: type,
+ alloc: Allocator,
+ args: Args,
+) !void {
+ // First, parse our CLI options.
+ const Options = BenchmarkImpl.Options;
+ var opts: Options = .{};
+ defer if (@hasDecl(Options, "deinit")) opts.deinit();
+ switch (args) {
+ .cli => {
+ var iter = try cli.args.argsIterator(alloc);
+ defer iter.deinit();
+ try cli.args.parse(Options, alloc, &opts, &iter);
+ },
+ .string => |str| {
+ var iter = try std.process.ArgIteratorGeneral(.{}).init(
+ alloc,
+ str,
+ );
+ defer iter.deinit();
+ try cli.args.parse(Options, alloc, &opts, &iter);
+ },
+ }
+
+ // Create our implementation
+ const impl = try BenchmarkImpl.create(alloc, opts);
+ defer impl.destroy(alloc);
+
+ // Initialize our benchmark
+ const b = impl.benchmark();
+ _ = try b.run(.once);
+}