mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-24 04:36:10 +03:00
config: add background-opacity and float parsing for config
This commit is contained in:
@ -144,6 +144,11 @@ fn parseIntoField(
|
|||||||
0,
|
0,
|
||||||
),
|
),
|
||||||
|
|
||||||
|
f64 => try std.fmt.parseFloat(
|
||||||
|
f64,
|
||||||
|
value orelse return error.ValueRequired,
|
||||||
|
),
|
||||||
|
|
||||||
else => unreachable,
|
else => unreachable,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -298,6 +303,20 @@ test "parseIntoField: unsigned numbers" {
|
|||||||
try testing.expectEqual(@as(u8, 1), data.u8);
|
try testing.expectEqual(@as(u8, 1), data.u8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "parseIntoField: floats" {
|
||||||
|
const testing = std.testing;
|
||||||
|
var arena = ArenaAllocator.init(testing.allocator);
|
||||||
|
defer arena.deinit();
|
||||||
|
const alloc = arena.allocator();
|
||||||
|
|
||||||
|
var data: struct {
|
||||||
|
f64: f64,
|
||||||
|
} = undefined;
|
||||||
|
|
||||||
|
try parseIntoField(@TypeOf(data), alloc, &data, "f64", "1");
|
||||||
|
try testing.expectEqual(@as(f64, 1.0), data.f64);
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
@ -63,6 +63,10 @@ pub const Config = struct {
|
|||||||
/// The color of the cursor. If this is not set, a default will be chosen.
|
/// The color of the cursor. If this is not set, a default will be chosen.
|
||||||
@"cursor-color": ?Color = null,
|
@"cursor-color": ?Color = null,
|
||||||
|
|
||||||
|
/// The opacity level (opposite of transparency) of the background.
|
||||||
|
/// A value of 1 is fully opaque and a value of 0 is fully transparent.
|
||||||
|
@"background-opacity": f64 = 1.0,
|
||||||
|
|
||||||
/// The command to run, usually a shell. If this is not an absolute path,
|
/// The command to run, usually a shell. If this is not an absolute path,
|
||||||
/// it'll be looked up in the PATH. If this is not set, a default will
|
/// it'll be looked up in the PATH. If this is not set, a default will
|
||||||
/// be looked up from your system. The rules for the default lookup are:
|
/// be looked up from your system. The rules for the default lookup are:
|
||||||
@ -754,6 +758,7 @@ pub const Config = struct {
|
|||||||
switch (@typeInfo(T)) {
|
switch (@typeInfo(T)) {
|
||||||
inline .Bool,
|
inline .Bool,
|
||||||
.Int,
|
.Int,
|
||||||
|
.Float,
|
||||||
=> return src,
|
=> return src,
|
||||||
|
|
||||||
.Optional => |info| return try cloneValue(
|
.Optional => |info| return try cloneValue(
|
||||||
@ -879,6 +884,7 @@ fn equal(comptime T: type, old: T, new: T) bool {
|
|||||||
|
|
||||||
inline .Bool,
|
inline .Bool,
|
||||||
.Int,
|
.Int,
|
||||||
|
.Float,
|
||||||
.Enum,
|
.Enum,
|
||||||
=> return old == new,
|
=> return old == new,
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user