mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-07-29 03:47:54 +00:00
style: use decl literals
This commit changes a LOT of areas of the code to use decl literals instead of redundantly referring to the type. These changes were mostly driven by some regex searches and then manual adjustment on a case-by-case basis. I almost certainly missed quite a few places where decl literals could be used, but this is a good first step in converting things, and other instances can be addressed when they're discovered. I tested GLFW+Metal and building the framework on macOS and tested a GTK build on Linux, so I'm 99% sure I didn't introduce any syntax errors or other problems with this. (fingers crossed)
This commit is contained in:
@@ -37,7 +37,7 @@ collection: Collection,
|
||||
|
||||
/// The set of statuses and whether they're enabled or not. This defaults
|
||||
/// to true. This can be changed at runtime with no ill effect.
|
||||
styles: StyleStatus = StyleStatus.initFill(true),
|
||||
styles: StyleStatus = .initFill(true),
|
||||
|
||||
/// If discovery is available, we'll look up fonts where we can't find
|
||||
/// the codepoint. This can be set after initialization.
|
||||
@@ -140,7 +140,7 @@ pub fn getIndex(
|
||||
// handle this.
|
||||
if (self.sprite) |sprite| {
|
||||
if (sprite.hasCodepoint(cp, p)) {
|
||||
return Collection.Index.initSpecial(.sprite);
|
||||
return .initSpecial(.sprite);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -388,7 +388,7 @@ test getIndex {
|
||||
|
||||
{
|
||||
errdefer c.deinit(alloc);
|
||||
_ = try c.add(alloc, .regular, .{ .loaded = try Face.init(
|
||||
_ = try c.add(alloc, .regular, .{ .loaded = try .init(
|
||||
lib,
|
||||
testFont,
|
||||
.{ .size = .{ .points = 12, .xdpi = 96, .ydpi = 96 } },
|
||||
@@ -398,7 +398,7 @@ test getIndex {
|
||||
_ = try c.add(
|
||||
alloc,
|
||||
.regular,
|
||||
.{ .loaded = try Face.init(
|
||||
.{ .loaded = try .init(
|
||||
lib,
|
||||
testEmoji,
|
||||
.{ .size = .{ .points = 12 } },
|
||||
@@ -408,7 +408,7 @@ test getIndex {
|
||||
_ = try c.add(
|
||||
alloc,
|
||||
.regular,
|
||||
.{ .loaded = try Face.init(
|
||||
.{ .loaded = try .init(
|
||||
lib,
|
||||
testEmojiText,
|
||||
.{ .size = .{ .points = 12 } },
|
||||
@@ -467,17 +467,17 @@ test "getIndex disabled font style" {
|
||||
var c = Collection.init();
|
||||
c.load_options = .{ .library = lib };
|
||||
|
||||
_ = try c.add(alloc, .regular, .{ .loaded = try Face.init(
|
||||
_ = try c.add(alloc, .regular, .{ .loaded = try .init(
|
||||
lib,
|
||||
testFont,
|
||||
.{ .size = .{ .points = 12, .xdpi = 96, .ydpi = 96 } },
|
||||
) });
|
||||
_ = try c.add(alloc, .bold, .{ .loaded = try Face.init(
|
||||
_ = try c.add(alloc, .bold, .{ .loaded = try .init(
|
||||
lib,
|
||||
testFont,
|
||||
.{ .size = .{ .points = 12, .xdpi = 96, .ydpi = 96 } },
|
||||
) });
|
||||
_ = try c.add(alloc, .italic, .{ .loaded = try Face.init(
|
||||
_ = try c.add(alloc, .italic, .{ .loaded = try .init(
|
||||
lib,
|
||||
testFont,
|
||||
.{ .size = .{ .points = 12, .xdpi = 96, .ydpi = 96 } },
|
||||
|
||||
@@ -55,7 +55,7 @@ load_options: ?LoadOptions = null,
|
||||
pub fn init() Collection {
|
||||
// Initialize our styles array, preallocating some space that is
|
||||
// likely to be used.
|
||||
return .{ .faces = StyleArray.initFill(.{}) };
|
||||
return .{ .faces = .initFill(.{}) };
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Collection, alloc: Allocator) void {
|
||||
@@ -707,7 +707,7 @@ test "add full" {
|
||||
defer c.deinit(alloc);
|
||||
|
||||
for (0..Index.Special.start - 1) |_| {
|
||||
_ = try c.add(alloc, .regular, .{ .loaded = try Face.init(
|
||||
_ = try c.add(alloc, .regular, .{ .loaded = try .init(
|
||||
lib,
|
||||
testFont,
|
||||
.{ .size = .{ .points = 12 } },
|
||||
@@ -755,7 +755,7 @@ test getFace {
|
||||
var c = init();
|
||||
defer c.deinit(alloc);
|
||||
|
||||
const idx = try c.add(alloc, .regular, .{ .loaded = try Face.init(
|
||||
const idx = try c.add(alloc, .regular, .{ .loaded = try .init(
|
||||
lib,
|
||||
testFont,
|
||||
.{ .size = .{ .points = 12, .xdpi = 96, .ydpi = 96 } },
|
||||
@@ -779,7 +779,7 @@ test getIndex {
|
||||
var c = init();
|
||||
defer c.deinit(alloc);
|
||||
|
||||
_ = try c.add(alloc, .regular, .{ .loaded = try Face.init(
|
||||
_ = try c.add(alloc, .regular, .{ .loaded = try .init(
|
||||
lib,
|
||||
testFont,
|
||||
.{ .size = .{ .points = 12, .xdpi = 96, .ydpi = 96 } },
|
||||
@@ -811,7 +811,7 @@ test completeStyles {
|
||||
defer c.deinit(alloc);
|
||||
c.load_options = .{ .library = lib };
|
||||
|
||||
_ = try c.add(alloc, .regular, .{ .loaded = try Face.init(
|
||||
_ = try c.add(alloc, .regular, .{ .loaded = try .init(
|
||||
lib,
|
||||
testFont,
|
||||
.{ .size = .{ .points = 12, .xdpi = 96, .ydpi = 96 } },
|
||||
@@ -838,7 +838,7 @@ test setSize {
|
||||
defer c.deinit(alloc);
|
||||
c.load_options = .{ .library = lib };
|
||||
|
||||
_ = try c.add(alloc, .regular, .{ .loaded = try Face.init(
|
||||
_ = try c.add(alloc, .regular, .{ .loaded = try .init(
|
||||
lib,
|
||||
testFont,
|
||||
.{ .size = .{ .points = 12, .xdpi = 96, .ydpi = 96 } },
|
||||
@@ -861,7 +861,7 @@ test hasCodepoint {
|
||||
defer c.deinit(alloc);
|
||||
c.load_options = .{ .library = lib };
|
||||
|
||||
const idx = try c.add(alloc, .regular, .{ .loaded = try Face.init(
|
||||
const idx = try c.add(alloc, .regular, .{ .loaded = try .init(
|
||||
lib,
|
||||
testFont,
|
||||
.{ .size = .{ .points = 12, .xdpi = 96, .ydpi = 96 } },
|
||||
@@ -885,7 +885,7 @@ test "hasCodepoint emoji default graphical" {
|
||||
defer c.deinit(alloc);
|
||||
c.load_options = .{ .library = lib };
|
||||
|
||||
const idx = try c.add(alloc, .regular, .{ .loaded = try Face.init(
|
||||
const idx = try c.add(alloc, .regular, .{ .loaded = try .init(
|
||||
lib,
|
||||
testEmoji,
|
||||
.{ .size = .{ .points = 12, .xdpi = 96, .ydpi = 96 } },
|
||||
@@ -908,7 +908,7 @@ test "metrics" {
|
||||
defer c.deinit(alloc);
|
||||
c.load_options = .{ .library = lib };
|
||||
|
||||
_ = try c.add(alloc, .regular, .{ .loaded = try Face.init(
|
||||
_ = try c.add(alloc, .regular, .{ .loaded = try .init(
|
||||
lib,
|
||||
testFont,
|
||||
.{ .size = .{ .points = 12, .xdpi = 96, .ydpi = 96 } },
|
||||
|
||||
@@ -254,7 +254,7 @@ fn loadWebCanvas(
|
||||
opts: font.face.Options,
|
||||
) !Face {
|
||||
const wc = self.wc.?;
|
||||
return try Face.initNamed(wc.alloc, wc.font_str, opts, wc.presentation);
|
||||
return try .initNamed(wc.alloc, wc.font_str, opts, wc.presentation);
|
||||
}
|
||||
|
||||
/// Returns true if this face can satisfy the given codepoint and
|
||||
|
||||
@@ -319,7 +319,7 @@ fn testGrid(mode: TestMode, alloc: Allocator, lib: Library) !SharedGrid {
|
||||
|
||||
switch (mode) {
|
||||
.normal => {
|
||||
_ = try c.add(alloc, .regular, .{ .loaded = try Face.init(
|
||||
_ = try c.add(alloc, .regular, .{ .loaded = try .init(
|
||||
lib,
|
||||
testFont,
|
||||
.{ .size = .{ .points = 12, .xdpi = 96, .ydpi = 96 } },
|
||||
|
||||
@@ -126,7 +126,7 @@ pub fn ref(
|
||||
.ref = 1,
|
||||
};
|
||||
|
||||
grid.* = try SharedGrid.init(self.alloc, resolver: {
|
||||
grid.* = try .init(self.alloc, resolver: {
|
||||
// Build our collection. This is the expensive operation that
|
||||
// involves finding fonts, loading them (maybe, some are deferred),
|
||||
// etc.
|
||||
@@ -258,7 +258,7 @@ fn collection(
|
||||
_ = try c.add(
|
||||
self.alloc,
|
||||
.regular,
|
||||
.{ .fallback_loaded = try Face.init(
|
||||
.{ .fallback_loaded = try .init(
|
||||
self.font_lib,
|
||||
font.embedded.regular,
|
||||
load_options.faceOptions(),
|
||||
@@ -267,7 +267,7 @@ fn collection(
|
||||
_ = try c.add(
|
||||
self.alloc,
|
||||
.bold,
|
||||
.{ .fallback_loaded = try Face.init(
|
||||
.{ .fallback_loaded = try .init(
|
||||
self.font_lib,
|
||||
font.embedded.bold,
|
||||
load_options.faceOptions(),
|
||||
@@ -276,7 +276,7 @@ fn collection(
|
||||
_ = try c.add(
|
||||
self.alloc,
|
||||
.italic,
|
||||
.{ .fallback_loaded = try Face.init(
|
||||
.{ .fallback_loaded = try .init(
|
||||
self.font_lib,
|
||||
font.embedded.italic,
|
||||
load_options.faceOptions(),
|
||||
@@ -285,7 +285,7 @@ fn collection(
|
||||
_ = try c.add(
|
||||
self.alloc,
|
||||
.bold_italic,
|
||||
.{ .fallback_loaded = try Face.init(
|
||||
.{ .fallback_loaded = try .init(
|
||||
self.font_lib,
|
||||
font.embedded.bold_italic,
|
||||
load_options.faceOptions(),
|
||||
@@ -318,7 +318,7 @@ fn collection(
|
||||
_ = try c.add(
|
||||
self.alloc,
|
||||
.regular,
|
||||
.{ .fallback_loaded = try Face.init(
|
||||
.{ .fallback_loaded = try .init(
|
||||
self.font_lib,
|
||||
font.embedded.emoji,
|
||||
load_options.faceOptions(),
|
||||
@@ -327,7 +327,7 @@ fn collection(
|
||||
_ = try c.add(
|
||||
self.alloc,
|
||||
.regular,
|
||||
.{ .fallback_loaded = try Face.init(
|
||||
.{ .fallback_loaded = try .init(
|
||||
self.font_lib,
|
||||
font.embedded.emoji_text,
|
||||
load_options.faceOptions(),
|
||||
@@ -391,7 +391,7 @@ fn discover(self: *SharedGridSet) !?*Discover {
|
||||
// If we initialized, use it
|
||||
if (self.font_discover) |*v| return v;
|
||||
|
||||
self.font_discover = Discover.init();
|
||||
self.font_discover = .init();
|
||||
return &self.font_discover.?;
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ pub const Face = struct {
|
||||
errdefer if (comptime harfbuzz_shaper) hb_font.destroy();
|
||||
|
||||
const color: ?ColorState = if (traits.color_glyphs)
|
||||
try ColorState.init(ct_font)
|
||||
try .init(ct_font)
|
||||
else
|
||||
null;
|
||||
errdefer if (color) |v| v.deinit();
|
||||
|
||||
@@ -30,7 +30,7 @@ fn genMap() Map {
|
||||
// Initialize to no converter
|
||||
var i: usize = 0;
|
||||
while (i < freetype.c.FT_PIXEL_MODE_MAX) : (i += 1) {
|
||||
result[i] = AtlasArray.initFill(null);
|
||||
result[i] = .initFill(null);
|
||||
}
|
||||
|
||||
// Map our converters
|
||||
|
||||
@@ -191,7 +191,7 @@ pub const Shaper = struct {
|
||||
// Create the CF release thread.
|
||||
var cf_release_thread = try alloc.create(CFReleaseThread);
|
||||
errdefer alloc.destroy(cf_release_thread);
|
||||
cf_release_thread.* = try CFReleaseThread.init(alloc);
|
||||
cf_release_thread.* = try .init(alloc);
|
||||
errdefer cf_release_thread.deinit();
|
||||
|
||||
// Start the CF release thread.
|
||||
@@ -1768,7 +1768,7 @@ fn testShaperWithFont(alloc: Allocator, font_req: TestFont) !TestShaper {
|
||||
c.load_options = .{ .library = lib };
|
||||
|
||||
// Setup group
|
||||
_ = try c.add(alloc, .regular, .{ .loaded = try Face.init(
|
||||
_ = try c.add(alloc, .regular, .{ .loaded = try .init(
|
||||
lib,
|
||||
testFont,
|
||||
.{ .size = .{ .points = 12 } },
|
||||
@@ -1776,7 +1776,7 @@ fn testShaperWithFont(alloc: Allocator, font_req: TestFont) !TestShaper {
|
||||
|
||||
if (font.options.backend != .coretext) {
|
||||
// Coretext doesn't support Noto's format
|
||||
_ = try c.add(alloc, .regular, .{ .loaded = try Face.init(
|
||||
_ = try c.add(alloc, .regular, .{ .loaded = try .init(
|
||||
lib,
|
||||
testEmoji,
|
||||
.{ .size = .{ .points = 12 } },
|
||||
@@ -1795,7 +1795,7 @@ fn testShaperWithFont(alloc: Allocator, font_req: TestFont) !TestShaper {
|
||||
errdefer face.deinit();
|
||||
_ = try c.add(alloc, .regular, .{ .deferred = face });
|
||||
}
|
||||
_ = try c.add(alloc, .regular, .{ .loaded = try Face.init(
|
||||
_ = try c.add(alloc, .regular, .{ .loaded = try .init(
|
||||
lib,
|
||||
testEmojiText,
|
||||
.{ .size = .{ .points = 12 } },
|
||||
@@ -1803,7 +1803,7 @@ fn testShaperWithFont(alloc: Allocator, font_req: TestFont) !TestShaper {
|
||||
|
||||
const grid_ptr = try alloc.create(SharedGrid);
|
||||
errdefer alloc.destroy(grid_ptr);
|
||||
grid_ptr.* = try SharedGrid.init(alloc, .{ .collection = c });
|
||||
grid_ptr.* = try .init(alloc, .{ .collection = c });
|
||||
errdefer grid_ptr.*.deinit(alloc);
|
||||
|
||||
var shaper = try Shaper.init(alloc, .{});
|
||||
|
||||
@@ -21,7 +21,7 @@ pub const Feature = struct {
|
||||
pub fn fromString(str: []const u8) ?Feature {
|
||||
var fbs = std.io.fixedBufferStream(str);
|
||||
const reader = fbs.reader();
|
||||
return Feature.fromReader(reader);
|
||||
return .fromReader(reader);
|
||||
}
|
||||
|
||||
/// Parse a single font feature setting from a std.io.Reader, with a version
|
||||
|
||||
@@ -1227,7 +1227,7 @@ fn testShaperWithFont(alloc: Allocator, font_req: TestFont) !TestShaper {
|
||||
c.load_options = .{ .library = lib };
|
||||
|
||||
// Setup group
|
||||
_ = try c.add(alloc, .regular, .{ .loaded = try Face.init(
|
||||
_ = try c.add(alloc, .regular, .{ .loaded = try .init(
|
||||
lib,
|
||||
testFont,
|
||||
.{ .size = .{ .points = 12 } },
|
||||
@@ -1235,7 +1235,7 @@ fn testShaperWithFont(alloc: Allocator, font_req: TestFont) !TestShaper {
|
||||
|
||||
if (comptime !font.options.backend.hasCoretext()) {
|
||||
// Coretext doesn't support Noto's format
|
||||
_ = try c.add(alloc, .regular, .{ .loaded = try Face.init(
|
||||
_ = try c.add(alloc, .regular, .{ .loaded = try .init(
|
||||
lib,
|
||||
testEmoji,
|
||||
.{ .size = .{ .points = 12 } },
|
||||
@@ -1254,7 +1254,7 @@ fn testShaperWithFont(alloc: Allocator, font_req: TestFont) !TestShaper {
|
||||
errdefer face.deinit();
|
||||
_ = try c.add(alloc, .regular, .{ .deferred = face });
|
||||
}
|
||||
_ = try c.add(alloc, .regular, .{ .loaded = try Face.init(
|
||||
_ = try c.add(alloc, .regular, .{ .loaded = try .init(
|
||||
lib,
|
||||
testEmojiText,
|
||||
.{ .size = .{ .points = 12 } },
|
||||
@@ -1262,7 +1262,7 @@ fn testShaperWithFont(alloc: Allocator, font_req: TestFont) !TestShaper {
|
||||
|
||||
const grid_ptr = try alloc.create(SharedGrid);
|
||||
errdefer alloc.destroy(grid_ptr);
|
||||
grid_ptr.* = try SharedGrid.init(alloc, .{ .collection = c });
|
||||
grid_ptr.* = try .init(alloc, .{ .collection = c });
|
||||
errdefer grid_ptr.*.deinit(alloc);
|
||||
|
||||
var shaper = try Shaper.init(alloc, .{});
|
||||
|
||||
@@ -150,7 +150,7 @@ pub const Canvas = struct {
|
||||
|
||||
/// Acquires a z2d drawing context, caller MUST deinit context.
|
||||
pub fn getContext(self: *Canvas) z2d.Context {
|
||||
return z2d.Context.init(self.alloc, &self.sfc);
|
||||
return .init(self.alloc, &self.sfc);
|
||||
}
|
||||
|
||||
/// Draw and fill a single pixel
|
||||
|
||||
Reference in New Issue
Block a user