From 7fc66f3851f947ef1e80655d4cb61129bcc553ff Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 23 Sep 2023 22:42:09 -0700 Subject: [PATCH] cli: dedicated directory --- src/cli.zig | 5 +++++ src/{cli_action.zig => cli/action.zig} | 25 ++++++++----------------- src/cli/list_fonts.zig | 3 +++ src/cli/version.zig | 17 +++++++++++++++++ src/main.zig | 8 ++++---- 5 files changed, 37 insertions(+), 21 deletions(-) create mode 100644 src/cli.zig rename src/{cli_action.zig => cli/action.zig} (84%) create mode 100644 src/cli/list_fonts.zig create mode 100644 src/cli/version.zig diff --git a/src/cli.zig b/src/cli.zig new file mode 100644 index 000000000..88c6f298e --- /dev/null +++ b/src/cli.zig @@ -0,0 +1,5 @@ +pub const Action = @import("cli/action.zig").Action; + +test { + @import("std").testing.refAllDecls(@This()); +} diff --git a/src/cli_action.zig b/src/cli/action.zig similarity index 84% rename from src/cli_action.zig rename to src/cli/action.zig index e62b3bfd5..26b3988be 100644 --- a/src/cli_action.zig +++ b/src/cli/action.zig @@ -1,9 +1,8 @@ const std = @import("std"); -const builtin = @import("builtin"); -const xev = @import("xev"); const Allocator = std.mem.Allocator; -const build_config = @import("build_config.zig"); -const renderer = @import("renderer.zig"); + +const list_fonts = @import("list_fonts.zig"); +const version = @import("version.zig"); /// Special commands that can be invoked via CLI flags. These are all /// invoked by using `+` as a CLI flag. The only exception is @@ -12,6 +11,9 @@ pub const Action = enum { /// Output the version and exit version, + /// List available fonts + @"list-fonts", + pub const Error = error{ /// Multiple actions were detected. You can specify at most one /// action on the CLI otherwise the behavior desired is ambiguous. @@ -49,23 +51,12 @@ pub const Action = enum { pub fn run(self: Action, alloc: Allocator) !u8 { _ = alloc; return switch (self) { - .version => try runVersion(), + .version => try version.run(), + .@"list-fonts" => try list_fonts.run(), }; } }; -fn runVersion() !u8 { - const stdout = std.io.getStdOut().writer(); - try stdout.print("Ghostty {s}\n\n", .{build_config.version_string}); - try stdout.print("Build Config\n", .{}); - try stdout.print(" - build mode : {}\n", .{builtin.mode}); - try stdout.print(" - app runtime: {}\n", .{build_config.app_runtime}); - try stdout.print(" - font engine: {}\n", .{build_config.font_backend}); - try stdout.print(" - renderer : {}\n", .{renderer.Renderer}); - try stdout.print(" - libxev : {}\n", .{xev.backend}); - return 0; -} - test "parse action none" { const testing = std.testing; const alloc = testing.allocator; diff --git a/src/cli/list_fonts.zig b/src/cli/list_fonts.zig new file mode 100644 index 000000000..eced0f472 --- /dev/null +++ b/src/cli/list_fonts.zig @@ -0,0 +1,3 @@ +pub fn run() !u8 { + return 0; +} diff --git a/src/cli/version.zig b/src/cli/version.zig new file mode 100644 index 000000000..b3395f4cd --- /dev/null +++ b/src/cli/version.zig @@ -0,0 +1,17 @@ +const std = @import("std"); +const builtin = @import("builtin"); +const build_config = @import("../build_config.zig"); +const xev = @import("xev"); +const renderer = @import("../renderer.zig"); + +pub fn run() !u8 { + const stdout = std.io.getStdOut().writer(); + try stdout.print("Ghostty {s}\n\n", .{build_config.version_string}); + try stdout.print("Build Config\n", .{}); + try stdout.print(" - build mode : {}\n", .{builtin.mode}); + try stdout.print(" - app runtime: {}\n", .{build_config.app_runtime}); + try stdout.print(" - font engine: {}\n", .{build_config.font_backend}); + try stdout.print(" - renderer : {}\n", .{renderer.Renderer}); + try stdout.print(" - libxev : {}\n", .{xev.backend}); + return 0; +} diff --git a/src/main.zig b/src/main.zig index bd0a25bd6..e44c3f9d1 100644 --- a/src/main.zig +++ b/src/main.zig @@ -6,7 +6,7 @@ const options = @import("build_options"); const glfw = @import("glfw"); const macos = @import("macos"); const tracy = @import("tracy"); -const cli_action = @import("cli_action.zig"); +const cli = @import("cli.zig"); const internal_os = @import("os/main.zig"); const xev = @import("xev"); const fontconfig = @import("fontconfig"); @@ -171,7 +171,7 @@ pub const GlobalState = struct { gpa: ?GPA, alloc: std.mem.Allocator, tracy: if (tracy.enabled) ?tracy.Allocator(null) else void, - action: ?cli_action.Action, + action: ?cli.Action, logging: Logging, /// Where logging should go @@ -226,7 +226,7 @@ pub const GlobalState = struct { }; // We first try to parse any action that we may be executing. - self.action = try cli_action.Action.detectCLI(self.alloc); + self.action = try cli.Action.detectCLI(self.alloc); // If we have an action executing, we disable logging by default // since we write to stderr we don't want logs messing up our @@ -290,7 +290,7 @@ test { _ = @import("renderer.zig"); _ = @import("termio.zig"); _ = @import("input.zig"); - _ = @import("cli_action.zig"); + _ = @import("cli.zig"); // Libraries _ = @import("segmented_pool.zig");