config: add background-opacity and float parsing for config

This commit is contained in:
Mitchell Hashimoto
2023-07-03 17:50:45 -07:00
parent 68b57f1001
commit 8756090266
2 changed files with 25 additions and 0 deletions

View File

@ -144,6 +144,11 @@ fn parseIntoField(
0,
),
f64 => try std.fmt.parseFloat(
f64,
value orelse return error.ValueRequired,
),
else => unreachable,
};
@ -298,6 +303,20 @@ test "parseIntoField: unsigned numbers" {
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" {
const testing = std.testing;
var arena = ArenaAllocator.init(testing.allocator);

View File

@ -63,6 +63,10 @@ pub const Config = struct {
/// The color of the cursor. If this is not set, a default will be chosen.
@"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,
/// 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:
@ -754,6 +758,7 @@ pub const Config = struct {
switch (@typeInfo(T)) {
inline .Bool,
.Int,
.Float,
=> return src,
.Optional => |info| return try cloneValue(
@ -879,6 +884,7 @@ fn equal(comptime T: type, old: T, new: T) bool {
inline .Bool,
.Int,
.Float,
.Enum,
=> return old == new,