mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
cli: dedicated directory
This commit is contained in:
5
src/cli.zig
Normal file
5
src/cli.zig
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
pub const Action = @import("cli/action.zig").Action;
|
||||||
|
|
||||||
|
test {
|
||||||
|
@import("std").testing.refAllDecls(@This());
|
||||||
|
}
|
@ -1,9 +1,8 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const builtin = @import("builtin");
|
|
||||||
const xev = @import("xev");
|
|
||||||
const Allocator = std.mem.Allocator;
|
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
|
/// Special commands that can be invoked via CLI flags. These are all
|
||||||
/// invoked by using `+<action>` as a CLI flag. The only exception is
|
/// invoked by using `+<action>` as a CLI flag. The only exception is
|
||||||
@ -12,6 +11,9 @@ pub const Action = enum {
|
|||||||
/// Output the version and exit
|
/// Output the version and exit
|
||||||
version,
|
version,
|
||||||
|
|
||||||
|
/// List available fonts
|
||||||
|
@"list-fonts",
|
||||||
|
|
||||||
pub const Error = error{
|
pub const Error = error{
|
||||||
/// Multiple actions were detected. You can specify at most one
|
/// Multiple actions were detected. You can specify at most one
|
||||||
/// action on the CLI otherwise the behavior desired is ambiguous.
|
/// 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 {
|
pub fn run(self: Action, alloc: Allocator) !u8 {
|
||||||
_ = alloc;
|
_ = alloc;
|
||||||
return switch (self) {
|
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" {
|
test "parse action none" {
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
const alloc = testing.allocator;
|
const alloc = testing.allocator;
|
3
src/cli/list_fonts.zig
Normal file
3
src/cli/list_fonts.zig
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
pub fn run() !u8 {
|
||||||
|
return 0;
|
||||||
|
}
|
17
src/cli/version.zig
Normal file
17
src/cli/version.zig
Normal file
@ -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;
|
||||||
|
}
|
@ -6,7 +6,7 @@ const options = @import("build_options");
|
|||||||
const glfw = @import("glfw");
|
const glfw = @import("glfw");
|
||||||
const macos = @import("macos");
|
const macos = @import("macos");
|
||||||
const tracy = @import("tracy");
|
const tracy = @import("tracy");
|
||||||
const cli_action = @import("cli_action.zig");
|
const cli = @import("cli.zig");
|
||||||
const internal_os = @import("os/main.zig");
|
const internal_os = @import("os/main.zig");
|
||||||
const xev = @import("xev");
|
const xev = @import("xev");
|
||||||
const fontconfig = @import("fontconfig");
|
const fontconfig = @import("fontconfig");
|
||||||
@ -171,7 +171,7 @@ pub const GlobalState = struct {
|
|||||||
gpa: ?GPA,
|
gpa: ?GPA,
|
||||||
alloc: std.mem.Allocator,
|
alloc: std.mem.Allocator,
|
||||||
tracy: if (tracy.enabled) ?tracy.Allocator(null) else void,
|
tracy: if (tracy.enabled) ?tracy.Allocator(null) else void,
|
||||||
action: ?cli_action.Action,
|
action: ?cli.Action,
|
||||||
logging: Logging,
|
logging: Logging,
|
||||||
|
|
||||||
/// Where logging should go
|
/// Where logging should go
|
||||||
@ -226,7 +226,7 @@ pub const GlobalState = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// We first try to parse any action that we may be executing.
|
// 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
|
// If we have an action executing, we disable logging by default
|
||||||
// since we write to stderr we don't want logs messing up our
|
// since we write to stderr we don't want logs messing up our
|
||||||
@ -290,7 +290,7 @@ test {
|
|||||||
_ = @import("renderer.zig");
|
_ = @import("renderer.zig");
|
||||||
_ = @import("termio.zig");
|
_ = @import("termio.zig");
|
||||||
_ = @import("input.zig");
|
_ = @import("input.zig");
|
||||||
_ = @import("cli_action.zig");
|
_ = @import("cli.zig");
|
||||||
|
|
||||||
// Libraries
|
// Libraries
|
||||||
_ = @import("segmented_pool.zig");
|
_ = @import("segmented_pool.zig");
|
||||||
|
Reference in New Issue
Block a user