diff options
| author | 2021-12-31 21:02:23 +0200 | |
|---|---|---|
| committer | 2021-12-31 21:02:23 +0200 | |
| commit | 758a0611d098876ca93ae49179148f5ef5cf1b06 (patch) | |
| tree | f9bc54241f95b7e8647c5c5a1836d7fe86a5c14e /src/Config.zig | |
| parent | Some changes (diff) | |
| download | es-758a0611d098876ca93ae49179148f5ef5cf1b06.tar.gz es-758a0611d098876ca93ae49179148f5ef5cf1b06.tar.xz es-758a0611d098876ca93ae49179148f5ef5cf1b06.zip | |
Now can do soft tabs yay
Diffstat (limited to 'src/Config.zig')
| -rw-r--r-- | src/Config.zig | 16 |
1 files changed, 15 insertions, 1 deletions
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(); | |||
| 9 | 9 | ||
| 10 | const config_path = "arkta/es/es.ini"; | 10 | const config_path = "arkta/es/es.ini"; |
| 11 | 11 | ||
| 12 | hard_tabs: bool = conf.default_hard_tabs, | ||
| 12 | line_limit: usize = conf.default_line_limit, | 13 | line_limit: usize = conf.default_line_limit, |
| 13 | page_overlap: usize = conf.default_page_overlap, | 14 | page_overlap: usize = conf.default_page_overlap, |
| 14 | tab_stop: usize = conf.default_tab_stop, | 15 | tab_stop: usize = conf.default_tab_stop, |
| @@ -42,6 +43,17 @@ pub fn readConfig(allocator: Allocator) !Config { | |||
| 42 | return config; | 43 | return config; |
| 43 | } | 44 | } |
| 44 | 45 | ||
| 46 | fn parseBool(str: []const u8) !bool { | ||
| 47 | if (std.mem.eql(u8, str, "true")) { | ||
| 48 | return true; | ||
| 49 | } else if (std.mem.eql(u8, str, "false")) { | ||
| 50 | return false; | ||
| 51 | } else { | ||
| 52 | std.log.err("How to interpret '{s}' as a bool?", .{str}); | ||
| 53 | return error.MalformedConfig; | ||
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 45 | fn readConfigInBaseDir(allocator: Allocator, config: *Config, base_dir: []const u8) !void { | 57 | fn readConfigInBaseDir(allocator: Allocator, config: *Config, base_dir: []const u8) !void { |
| 46 | const filename = try std.fs.path.join(allocator, &.{ base_dir, config_path }); | 58 | const filename = try std.fs.path.join(allocator, &.{ base_dir, config_path }); |
| 47 | defer allocator.free(filename); | 59 | defer allocator.free(filename); |
| @@ -67,7 +79,9 @@ fn readConfigInBaseDir(allocator: Allocator, config: *Config, base_dir: []const | |||
| 67 | 79 | ||
| 68 | const key = std.mem.trimRight(u8, line[0..split], &std.ascii.spaces); | 80 | const key = std.mem.trimRight(u8, line[0..split], &std.ascii.spaces); |
| 69 | const value = std.mem.trimLeft(u8, line[(split + 1)..], &std.ascii.spaces); | 81 | const value = std.mem.trimLeft(u8, line[(split + 1)..], &std.ascii.spaces); |
| 70 | if (std.mem.eql(u8, key, "line-limit")) { | 82 | if (std.mem.eql(u8, key, "hard-tabs")) { |
| 83 | config.hard_tabs = try parseBool(value); | ||
| 84 | } else if (std.mem.eql(u8, key, "line-limit")) { | ||
| 71 | config.line_limit = try std.fmt.parseUnsigned(usize, value, 0); | 85 | config.line_limit = try std.fmt.parseUnsigned(usize, value, 0); |
| 72 | } else if (std.mem.eql(u8, key, "page-overlap")) { | 86 | } else if (std.mem.eql(u8, key, "page-overlap")) { |
| 73 | config.page_overlap = try std.fmt.parseUnsigned(usize, value, 0); | 87 | config.page_overlap = try std.fmt.parseUnsigned(usize, value, 0); |