mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 00:06:09 +03:00
cli/list-fonts: dumb implementation
This commit is contained in:
@ -49,10 +49,9 @@ pub const Action = enum {
|
|||||||
|
|
||||||
/// Run the action. This returns the exit code to exit with.
|
/// Run the action. This returns the exit code to exit with.
|
||||||
pub fn run(self: Action, alloc: Allocator) !u8 {
|
pub fn run(self: Action, alloc: Allocator) !u8 {
|
||||||
_ = alloc;
|
|
||||||
return switch (self) {
|
return switch (self) {
|
||||||
.version => try version.run(),
|
.version => try version.run(),
|
||||||
.@"list-fonts" => try list_fonts.run(),
|
.@"list-fonts" => try list_fonts.run(alloc),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -55,7 +55,7 @@ pub fn parse(comptime T: type, alloc: Allocator, dst: *T, iter: anytype) !void {
|
|||||||
break :arena dst._arena.?.allocator();
|
break :arena dst._arena.?.allocator();
|
||||||
} else fail: {
|
} else fail: {
|
||||||
// Note: this is... not safe...
|
// Note: this is... not safe...
|
||||||
var fail = std.testing.FailingAllocator.init(alloc, 0);
|
var fail = std.testing.FailingAllocator.init(alloc, .{});
|
||||||
break :fail fail.allocator();
|
break :fail fail.allocator();
|
||||||
};
|
};
|
||||||
errdefer if (arena_available and arena_owned) {
|
errdefer if (arena_available and arena_owned) {
|
||||||
|
@ -1,3 +1,61 @@
|
|||||||
pub fn run() !u8 {
|
const std = @import("std");
|
||||||
|
const Allocator = std.mem.Allocator;
|
||||||
|
const ArenaAllocator = std.heap.ArenaAllocator;
|
||||||
|
const args = @import("args.zig");
|
||||||
|
const font = @import("../font/main.zig");
|
||||||
|
|
||||||
|
const log = std.log.scoped(.list_fonts);
|
||||||
|
|
||||||
|
pub const Config = struct {
|
||||||
|
/// This is set by the CLI parser for deinit.
|
||||||
|
_arena: ?ArenaAllocator = null,
|
||||||
|
|
||||||
|
pub fn deinit(self: *Config) void {
|
||||||
|
if (self._arena) |arena| arena.deinit();
|
||||||
|
self.* = undefined;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn run(alloc: Allocator) !u8 {
|
||||||
|
var iter = try std.process.argsWithAllocator(alloc);
|
||||||
|
defer iter.deinit();
|
||||||
|
return try runArgs(alloc, &iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn runArgs(alloc: Allocator, argsIter: anytype) !u8 {
|
||||||
|
var config: Config = .{};
|
||||||
|
defer config.deinit();
|
||||||
|
try args.parse(Config, alloc, &config, argsIter);
|
||||||
|
|
||||||
|
// Its possible to build Ghostty without font discovery!
|
||||||
|
if (comptime font.Discover == void) {
|
||||||
|
const stderr = std.io.getStdErr().writer();
|
||||||
|
try stderr.print(
|
||||||
|
\\Ghostty was built without a font discovery mechanism. This is a compile-time
|
||||||
|
\\option. Please review how Ghostty was built from source, contact the
|
||||||
|
\\maintainer to enable a font discovery mechanism, and try again.
|
||||||
|
,
|
||||||
|
.{},
|
||||||
|
);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const stdout = std.io.getStdOut().writer();
|
||||||
|
|
||||||
|
var disco = font.Discover.init();
|
||||||
|
defer disco.deinit();
|
||||||
|
|
||||||
|
// Look up all available fonts
|
||||||
|
var disco_it = try disco.discover(.{});
|
||||||
|
defer disco_it.deinit();
|
||||||
|
while (try disco_it.next()) |face| {
|
||||||
|
var buf: [1024]u8 = undefined;
|
||||||
|
const name = face.name(&buf) catch |err| {
|
||||||
|
log.err("failed to get font name: {}", .{err});
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
try stdout.print("{s}\n", .{name});
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user