From 758a0611d098876ca93ae49179148f5ef5cf1b06 Mon Sep 17 00:00:00 2001 From: Uko Kokņevičs Date: Fri, 31 Dec 2021 21:02:23 +0200 Subject: Now can do soft tabs yay --- src/Config.zig | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/Config.zig') diff --git a/src/Config.zig b/src/Config.zig index 16b4043..071c31b 100644 --- a/src/Config.zig +++ b/src/Config.zig @@ -9,6 +9,7 @@ const Config = @This(); const config_path = "arkta/es/es.ini"; +hard_tabs: bool = conf.default_hard_tabs, line_limit: usize = conf.default_line_limit, page_overlap: usize = conf.default_page_overlap, tab_stop: usize = conf.default_tab_stop, @@ -42,6 +43,17 @@ pub fn readConfig(allocator: Allocator) !Config { return config; } +fn parseBool(str: []const u8) !bool { + if (std.mem.eql(u8, str, "true")) { + return true; + } else if (std.mem.eql(u8, str, "false")) { + return false; + } else { + std.log.err("How to interpret '{s}' as a bool?", .{str}); + return error.MalformedConfig; + } +} + fn readConfigInBaseDir(allocator: Allocator, config: *Config, base_dir: []const u8) !void { const filename = try std.fs.path.join(allocator, &.{ base_dir, config_path }); defer allocator.free(filename); @@ -67,7 +79,9 @@ fn readConfigInBaseDir(allocator: Allocator, config: *Config, base_dir: []const const key = std.mem.trimRight(u8, line[0..split], &std.ascii.spaces); const value = std.mem.trimLeft(u8, line[(split + 1)..], &std.ascii.spaces); - if (std.mem.eql(u8, key, "line-limit")) { + if (std.mem.eql(u8, key, "hard-tabs")) { + config.hard_tabs = try parseBool(value); + } else if (std.mem.eql(u8, key, "line-limit")) { config.line_limit = try std.fmt.parseUnsigned(usize, value, 0); } else if (std.mem.eql(u8, key, "page-overlap")) { config.page_overlap = try std.fmt.parseUnsigned(usize, value, 0); -- cgit v1.2.3