From 5567564dd0b37da47db6252d04f6f1b05ddb9305 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 29 Sep 2022 13:14:20 -0700 Subject: [PATCH] cli args fix stage1 miscompilation, add font families --- src/Grid.zig | 33 +++++++++++++++++++++++++++++++-- src/cli_args.zig | 11 ++++++++--- src/config.zig | 6 ++++++ 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/Grid.zig b/src/Grid.zig index 8d100b33a..1f393cbc6 100644 --- a/src/Grid.zig +++ b/src/Grid.zig @@ -174,8 +174,10 @@ pub fn init( .size = font_size.points, }); defer disco_it.deinit(); - if (try disco_it.next()) |face| + if (try disco_it.next()) |face| { + log.debug("font regular: {s}", .{try face.name()}); try group.addFace(alloc, .regular, face); + } } { var disco_it = try disco.discover(.{ @@ -184,8 +186,35 @@ pub fn init( .bold = true, }); defer disco_it.deinit(); - if (try disco_it.next()) |face| + if (try disco_it.next()) |face| { + log.debug("font bold: {s}", .{try face.name()}); try group.addFace(alloc, .bold, face); + } + } + { + var disco_it = try disco.discover(.{ + .family = "Fira Code", + .size = font_size.points, + .italic = true, + }); + defer disco_it.deinit(); + if (try disco_it.next()) |face| { + log.debug("font italic: {s}", .{try face.name()}); + try group.addFace(alloc, .italic, face); + } + } + { + var disco_it = try disco.discover(.{ + .family = "Fira Code", + .size = font_size.points, + .bold = true, + .italic = true, + }); + defer disco_it.deinit(); + if (try disco_it.next()) |face| { + log.debug("font bold+italic: {s}", .{try face.name()}); + try group.addFace(alloc, .bold_italic, face); + } } } diff --git a/src/cli_args.zig b/src/cli_args.zig index 080cdbfb7..75cbfb5be 100644 --- a/src/cli_args.zig +++ b/src/cli_args.zig @@ -110,15 +110,20 @@ fn parseIntoField( // No parseCLI, magic the value based on the type @field(dst, field.name) = switch (Field) { - []const u8 => if (value) |slice| value: { + []const u8 => value: { + const slice = value orelse return error.ValueRequired; const buf = try alloc.alloc(u8, slice.len); mem.copy(u8, buf, slice); break :value buf; - } else return error.ValueRequired, + }, bool => try parseBool(value orelse "t"), - u8 => try std.fmt.parseInt(u8, value orelse return error.ValueRequired, 0), + u8 => try std.fmt.parseInt( + u8, + value orelse return error.ValueRequired, + 0, + ), else => unreachable, }; diff --git a/src/config.zig b/src/config.zig index a1adb6bb0..d93f86783 100644 --- a/src/config.zig +++ b/src/config.zig @@ -6,6 +6,12 @@ const inputpkg = @import("input.zig"); /// Config is the main config struct. These fields map directly to the /// CLI flag names hence we use a lot of `@""` syntax to support hyphens. pub const Config = struct { + /// The font families to use. + @"font-family": ?[]const u8 = null, + @"font-family-bold": ?[]const u8 = null, + @"font-family-italic": ?[]const u8 = null, + @"font-family-bold-italic": ?[]const u8 = null, + /// Font size in points @"font-size": u8 = 12,