summaryrefslogtreecommitdiff
path: root/src/locations_config.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-15 18:41:15 -0300
committerGabriel Schneider <[email protected]>2026-10-01 00:12:14 -0300
commit02ea4db25f9802e76112f3b4e69aa75e5a9464dc (patch)
treedaa17ec75135e055a60eff982d97057dcd109c25 /src/locations_config.zig
parent505dedb2459e7b51cbdb0c066698c6e5596d19dd (diff)
downloadpardes-02ea4db25f9802e76112f3b4e69aa75e5a9464dc.tar.gz
pardes-02ea4db25f9802e76112f3b4e69aa75e5a9464dc.zip
Default location results to stacked addresses and source previews
Diffstat (limited to 'src/locations_config.zig')
-rw-r--r--src/locations_config.zig8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/locations_config.zig b/src/locations_config.zig
index ed67f990..6b23575a 100644
--- a/src/locations_config.zig
+++ b/src/locations_config.zig
@@ -1,9 +1,11 @@
const std = @import("std");
pub const Config = struct {
+ pub const Layout = enum { @"inline", stacked };
context: u16 = 0,
tscontext: bool = false,
tslocations: bool = true,
+ layout: Layout = .stacked,
/// Apply only supplied fields. A malformed token rejects the whole update.
/// Repeating a field uses its last supplied value.
@@ -20,6 +22,7 @@ pub const Config = struct {
@field(result, field.name) = switch (@typeInfo(field.type)) {
.bool => if (std.mem.eql(u8, value, "on")) true else if (std.mem.eql(u8, value, "off")) false else return error.ExpectedOnOrOff,
.int => std.fmt.parseInt(field.type, value, 10) catch return error.InvalidContext,
+ .@"enum" => std.meta.stringToEnum(field.type, value) orelse return error.InvalidLayout,
else => @compileError("unsupported location setting type"),
};
found = true;
@@ -38,6 +41,7 @@ pub const Config = struct {
switch (@typeInfo(field.type)) {
.bool => try writer.writeAll(if (value) "on" else "off"),
.int => try writer.print("{d}", .{value}),
+ .@"enum" => try writer.writeAll(@tagName(value)),
else => @compileError("unsupported location setting type"),
}
}
@@ -52,10 +56,11 @@ test "LocationsConfig reflection round trip and partial updates" {
var out: std.Io.Writer.Allocating = .init(std.testing.allocator);
defer out.deinit();
try config.write(&out.writer);
- try std.testing.expectEqualStrings("context:5 tscontext:on tslocations:off", out.written());
+ try std.testing.expectEqualStrings("context:5 tscontext:on tslocations:off layout:stacked", out.written());
try std.testing.expectEqual(config, try (Config{}).parse(out.written()));
try std.testing.expectEqual(config, try config.parse(" \n\t"));
try std.testing.expectEqual(@as(u16, 2), (try config.parse("context:1 context:2")).context);
+ try std.testing.expectEqual(Config.Layout.@"inline", (try config.parse("layout:inline")).layout);
}
test "LocationsConfig rejects invalid updates atomically" {
@@ -63,6 +68,7 @@ test "LocationsConfig rejects invalid updates atomically" {
try std.testing.expectError(error.UnknownLocationSetting, config.parse("context:5 unknown:on"));
try std.testing.expectError(error.ExpectedOnOrOff, config.parse("context:5 tscontext:true"));
try std.testing.expectError(error.ExpectedKeyValue, config.parse("context"));
+ try std.testing.expectError(error.InvalidLayout, config.parse("context:5 layout:sideways"));
for ([_][]const u8{ "context:", "context:-1", "context:65536", "context:five" }) |input|
try std.testing.expectError(error.InvalidContext, config.parse(input));
try std.testing.expectEqual(@as(u16, 3), config.context);