diff --git a/src/Grid.zig b/src/Grid.zig index 22eec614b..decdb3c3a 100644 --- a/src/Grid.zig +++ b/src/Grid.zig @@ -12,6 +12,7 @@ const Terminal = terminal.Terminal; const gl = @import("opengl.zig"); const gb = @import("gb_math.zig"); const trace = @import("tracy/tracy.zig").trace; +const Config = @import("config.zig").Config; const log = std.log.scoped(.grid); @@ -101,15 +102,15 @@ const GPUCell = struct { mode: u8, }; -pub fn init(alloc: Allocator) !Grid { +pub fn init(alloc: Allocator, config: *const Config) !Grid { // Initialize our font atlas. We will initially populate the // font atlas with all the visible ASCII characters since they are common. var atlas = try Atlas.init(alloc, 512); errdefer atlas.deinit(alloc); var fam = try font.Family.init(atlas); errdefer fam.deinit(alloc); - try fam.loadFaceFromMemory(.regular, face_ttf, 32); - try fam.loadFaceFromMemory(.bold, face_bold_ttf, 32); + try fam.loadFaceFromMemory(.regular, face_ttf, config.@"font-size"); + try fam.loadFaceFromMemory(.bold, face_bold_ttf, config.@"font-size"); // Load all visible ASCII characters and build our cell width based on // the widest character that we see. diff --git a/src/Window.zig b/src/Window.zig index d0c2a13b9..de451bdb5 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -148,7 +148,7 @@ pub fn create(alloc: Allocator, loop: libuv.Loop, config: *const Config) !*Windo // Create our terminal grid with the initial window size const window_size = try window.getSize(); - var grid = try Grid.init(alloc); + var grid = try Grid.init(alloc, config); try grid.setScreenSize(.{ .width = window_size.width, .height = window_size.height }); grid.background = .{ .r = config.background.r, diff --git a/src/cli_args.zig b/src/cli_args.zig index 11cdd4a26..a13b7880d 100644 --- a/src/cli_args.zig +++ b/src/cli_args.zig @@ -72,17 +72,23 @@ fn parseIntoField( const fieldInfo = @typeInfo(Field); // If the type implements a parse function, call that. - if (fieldInfo == .Struct and @hasDecl(Field, "parseCLI")) - break :field try Field.parseCLI(value); - - // Otherwise infer based on type - break :field switch (Field) { + // NOTE(mitchellh): this is a pretty nasty break statement. + // I split it into two at first and it failed with Zig as of + // July 21, 2022. I think stage2+ will fix this so lets clean + // this up when that comes out. + break :field if (fieldInfo == .Struct and @hasDecl(Field, "parseCLI")) + try Field.parseCLI(value) + else switch (Field) { []const u8 => if (value) |slice| value: { 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), + else => unreachable, }; }; @@ -177,6 +183,20 @@ test "parseIntoField: bool" { try testing.expectEqual(false, data.a); } +test "parseIntoField: unsigned numbers" { + const testing = std.testing; + var arena = ArenaAllocator.init(testing.allocator); + defer arena.deinit(); + const alloc = arena.allocator(); + + var data: struct { + @"u8": u8, + } = undefined; + + try parseIntoField(@TypeOf(data), alloc, &data, "u8", "1"); + try testing.expectEqual(@as(u8, 1), data.@"u8"); +} + test "parseIntoField: optional field" { const testing = std.testing; var arena = ArenaAllocator.init(testing.allocator); diff --git a/src/config.zig b/src/config.zig index bcd07dfbc..a77c1f1fe 100644 --- a/src/config.zig +++ b/src/config.zig @@ -2,6 +2,9 @@ const std = @import("std"); const ArenaAllocator = std.heap.ArenaAllocator; pub const Config = struct { + /// Font size + @"font-size": u8 = 14, + /// Background color for the window. background: Color = .{ .r = 0, .g = 0, .b = 0 }, diff --git a/test/cases/vttest/1_1.sh.ghostty.png b/test/cases/vttest/1_1.sh.ghostty.png index dbc04ed91..48b1343de 100644 Binary files a/test/cases/vttest/1_1.sh.ghostty.png and b/test/cases/vttest/1_1.sh.ghostty.png differ diff --git a/test/cases/vttest/launch.sh.ghostty.png b/test/cases/vttest/launch.sh.ghostty.png index c307ab7e2..1b54c6d36 100644 Binary files a/test/cases/vttest/launch.sh.ghostty.png and b/test/cases/vttest/launch.sh.ghostty.png differ