mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
add --font-size flag for font size in pixels
This commit is contained in:
@ -12,6 +12,7 @@ const Terminal = terminal.Terminal;
|
|||||||
const gl = @import("opengl.zig");
|
const gl = @import("opengl.zig");
|
||||||
const gb = @import("gb_math.zig");
|
const gb = @import("gb_math.zig");
|
||||||
const trace = @import("tracy/tracy.zig").trace;
|
const trace = @import("tracy/tracy.zig").trace;
|
||||||
|
const Config = @import("config.zig").Config;
|
||||||
|
|
||||||
const log = std.log.scoped(.grid);
|
const log = std.log.scoped(.grid);
|
||||||
|
|
||||||
@ -101,15 +102,15 @@ const GPUCell = struct {
|
|||||||
mode: u8,
|
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
|
// Initialize our font atlas. We will initially populate the
|
||||||
// font atlas with all the visible ASCII characters since they are common.
|
// font atlas with all the visible ASCII characters since they are common.
|
||||||
var atlas = try Atlas.init(alloc, 512);
|
var atlas = try Atlas.init(alloc, 512);
|
||||||
errdefer atlas.deinit(alloc);
|
errdefer atlas.deinit(alloc);
|
||||||
var fam = try font.Family.init(atlas);
|
var fam = try font.Family.init(atlas);
|
||||||
errdefer fam.deinit(alloc);
|
errdefer fam.deinit(alloc);
|
||||||
try fam.loadFaceFromMemory(.regular, face_ttf, 32);
|
try fam.loadFaceFromMemory(.regular, face_ttf, config.@"font-size");
|
||||||
try fam.loadFaceFromMemory(.bold, face_bold_ttf, 32);
|
try fam.loadFaceFromMemory(.bold, face_bold_ttf, config.@"font-size");
|
||||||
|
|
||||||
// Load all visible ASCII characters and build our cell width based on
|
// Load all visible ASCII characters and build our cell width based on
|
||||||
// the widest character that we see.
|
// the widest character that we see.
|
||||||
|
@ -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
|
// Create our terminal grid with the initial window size
|
||||||
const window_size = try window.getSize();
|
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 });
|
try grid.setScreenSize(.{ .width = window_size.width, .height = window_size.height });
|
||||||
grid.background = .{
|
grid.background = .{
|
||||||
.r = config.background.r,
|
.r = config.background.r,
|
||||||
|
@ -72,17 +72,23 @@ fn parseIntoField(
|
|||||||
const fieldInfo = @typeInfo(Field);
|
const fieldInfo = @typeInfo(Field);
|
||||||
|
|
||||||
// If the type implements a parse function, call that.
|
// If the type implements a parse function, call that.
|
||||||
if (fieldInfo == .Struct and @hasDecl(Field, "parseCLI"))
|
// NOTE(mitchellh): this is a pretty nasty break statement.
|
||||||
break :field try Field.parseCLI(value);
|
// 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
|
||||||
// Otherwise infer based on type
|
// this up when that comes out.
|
||||||
break :field switch (Field) {
|
break :field if (fieldInfo == .Struct and @hasDecl(Field, "parseCLI"))
|
||||||
|
try Field.parseCLI(value)
|
||||||
|
else switch (Field) {
|
||||||
[]const u8 => if (value) |slice| value: {
|
[]const u8 => if (value) |slice| value: {
|
||||||
const buf = try alloc.alloc(u8, slice.len);
|
const buf = try alloc.alloc(u8, slice.len);
|
||||||
mem.copy(u8, buf, slice);
|
mem.copy(u8, buf, slice);
|
||||||
break :value buf;
|
break :value buf;
|
||||||
} else return error.ValueRequired,
|
} else return error.ValueRequired,
|
||||||
|
|
||||||
bool => try parseBool(value orelse "t"),
|
bool => try parseBool(value orelse "t"),
|
||||||
|
|
||||||
|
u8 => try std.fmt.parseInt(u8, value orelse return error.ValueRequired, 0),
|
||||||
|
|
||||||
else => unreachable,
|
else => unreachable,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -177,6 +183,20 @@ test "parseIntoField: bool" {
|
|||||||
try testing.expectEqual(false, data.a);
|
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" {
|
test "parseIntoField: optional field" {
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
var arena = ArenaAllocator.init(testing.allocator);
|
var arena = ArenaAllocator.init(testing.allocator);
|
||||||
|
@ -2,6 +2,9 @@ const std = @import("std");
|
|||||||
const ArenaAllocator = std.heap.ArenaAllocator;
|
const ArenaAllocator = std.heap.ArenaAllocator;
|
||||||
|
|
||||||
pub const Config = struct {
|
pub const Config = struct {
|
||||||
|
/// Font size
|
||||||
|
@"font-size": u8 = 14,
|
||||||
|
|
||||||
/// Background color for the window.
|
/// Background color for the window.
|
||||||
background: Color = .{ .r = 0, .g = 0, .b = 0 },
|
background: Color = .{ .r = 0, .g = 0, .b = 0 },
|
||||||
|
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 10 KiB |
Binary file not shown.
Before Width: | Height: | Size: 89 KiB After Width: | Height: | Size: 38 KiB |
Reference in New Issue
Block a user