mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 08:16:13 +03:00
cli/list-fonts: don't use arrayhashmap
This commit is contained in:
@ -49,7 +49,8 @@ fn runArgs(alloc_gpa: Allocator, argsIter: anytype) !u8 {
|
|||||||
|
|
||||||
// We'll be putting our fonts into a list categorized by family
|
// We'll be putting our fonts into a list categorized by family
|
||||||
// so it is easier to read the output.
|
// so it is easier to read the output.
|
||||||
var map = std.StringArrayHashMap(std.ArrayListUnmanaged([]const u8)).init(alloc);
|
var families = std.ArrayList([]const u8).init(alloc);
|
||||||
|
var map = std.StringHashMap(std.ArrayListUnmanaged([]const u8)).init(alloc);
|
||||||
|
|
||||||
// Look up all available fonts
|
// Look up all available fonts
|
||||||
var disco = font.Discover.init();
|
var disco = font.Discover.init();
|
||||||
@ -59,44 +60,43 @@ fn runArgs(alloc_gpa: Allocator, argsIter: anytype) !u8 {
|
|||||||
while (try disco_it.next()) |face| {
|
while (try disco_it.next()) |face| {
|
||||||
var buf: [1024]u8 = undefined;
|
var buf: [1024]u8 = undefined;
|
||||||
|
|
||||||
const family = face.familyName(&buf) catch |err| {
|
const family_buf = face.familyName(&buf) catch |err| {
|
||||||
log.err("failed to get font family name: {}", .{err});
|
log.err("failed to get font family name: {}", .{err});
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
const family = try alloc.dupe(u8, family_buf);
|
||||||
|
|
||||||
const gop = try map.getOrPut(try alloc.dupe(u8, family));
|
const full_name_buf = face.name(&buf) catch |err| {
|
||||||
if (!gop.found_existing) {
|
|
||||||
gop.value_ptr.* = .{};
|
|
||||||
}
|
|
||||||
|
|
||||||
const full_name = face.name(&buf) catch |err| {
|
|
||||||
log.err("failed to get font name: {}", .{err});
|
log.err("failed to get font name: {}", .{err});
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
try gop.value_ptr.append(alloc, try alloc.dupe(u8, full_name));
|
const full_name = try alloc.dupe(u8, full_name_buf);
|
||||||
|
|
||||||
|
try families.append(family);
|
||||||
|
const gop = try map.getOrPut(family);
|
||||||
|
if (!gop.found_existing) gop.value_ptr.* = .{};
|
||||||
|
try gop.value_ptr.append(alloc, full_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort our keys.
|
// Sort our keys.
|
||||||
std.mem.sortUnstable([]const u8, map.keys(), {}, struct {
|
std.mem.sortUnstable([]const u8, families.items, {}, struct {
|
||||||
fn lessThan(_: void, lhs: []const u8, rhs: []const u8) bool {
|
fn lessThan(_: void, lhs: []const u8, rhs: []const u8) bool {
|
||||||
return std.mem.order(u8, lhs, rhs) == .lt;
|
return std.mem.order(u8, lhs, rhs) == .lt;
|
||||||
}
|
}
|
||||||
}.lessThan);
|
}.lessThan);
|
||||||
try map.reIndex(); // Have to reindex since keys changed
|
|
||||||
|
|
||||||
// Output each
|
// Output each
|
||||||
var it = map.iterator();
|
for (families.items) |family| {
|
||||||
while (it.next()) |entry| {
|
const list = map.get(family) orelse continue;
|
||||||
var items = entry.value_ptr.items;
|
if (list.items.len == 0) continue;
|
||||||
if (items.len == 0) continue;
|
std.mem.sortUnstable([]const u8, list.items, {}, struct {
|
||||||
std.mem.sortUnstable([]const u8, items, {}, struct {
|
|
||||||
fn lessThan(_: void, lhs: []const u8, rhs: []const u8) bool {
|
fn lessThan(_: void, lhs: []const u8, rhs: []const u8) bool {
|
||||||
return std.mem.order(u8, lhs, rhs) == .lt;
|
return std.mem.order(u8, lhs, rhs) == .lt;
|
||||||
}
|
}
|
||||||
}.lessThan);
|
}.lessThan);
|
||||||
|
|
||||||
try stdout.print("{s}\n", .{entry.key_ptr.*});
|
try stdout.print("{s}\n", .{family});
|
||||||
for (items) |item| try stdout.print(" {s}\n", .{item});
|
for (list.items) |item| try stdout.print(" {s}\n", .{item});
|
||||||
try stdout.print("\n", .{});
|
try stdout.print("\n", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user