diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Buffer.zig | 15 | ||||
| -rw-r--r-- | src/Config.zig | 16 | ||||
| -rw-r--r-- | src/key_state.zig | 2 |
3 files changed, 32 insertions, 1 deletions
diff --git a/src/Buffer.zig b/src/Buffer.zig index cb89935..f105c55 100644 --- a/src/Buffer.zig +++ b/src/Buffer.zig | |||
| @@ -291,6 +291,13 @@ pub fn insertChar(self: *Buffer, char: u8) !void { | |||
| 291 | self.dirty = true; | 291 | self.dirty = true; |
| 292 | } | 292 | } |
| 293 | 293 | ||
| 294 | pub fn insertNChars(self: *Buffer, char: u8, count: usize) !void { | ||
| 295 | var remaining = count; | ||
| 296 | while (remaining > 0) : (remaining -= 1) { | ||
| 297 | try self.insertChar(char); | ||
| 298 | } | ||
| 299 | } | ||
| 300 | |||
| 294 | pub fn insertNewline(self: *Buffer) !void { | 301 | pub fn insertNewline(self: *Buffer) !void { |
| 295 | self.dirty = true; | 302 | self.dirty = true; |
| 296 | 303 | ||
| @@ -331,6 +338,14 @@ pub fn insertRow(self: *Buffer, at: usize, data: []const u8) !void { | |||
| 331 | self.dirty = true; | 338 | self.dirty = true; |
| 332 | } | 339 | } |
| 333 | 340 | ||
| 341 | pub fn insertTab(self: *Buffer) !void { | ||
| 342 | if (self.config.hard_tabs) { | ||
| 343 | return self.insertChar('\t'); | ||
| 344 | } else { | ||
| 345 | return self.insertNChars(' ', self.config.tab_stop - self.cx % self.config.tab_stop); | ||
| 346 | } | ||
| 347 | } | ||
| 348 | |||
| 334 | pub fn killLine(self: *Buffer) !void { | 349 | pub fn killLine(self: *Buffer) !void { |
| 335 | return self.deleteRow(self.cy); | 350 | return self.deleteRow(self.cy); |
| 336 | } | 351 | } |
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); |
diff --git a/src/key_state.zig b/src/key_state.zig index 0ea30cb..d477094 100644 --- a/src/key_state.zig +++ b/src/key_state.zig | |||
| @@ -77,6 +77,8 @@ pub fn defaultState(editor: *Editor, buf: *Buffer, key: Key) Error!void { | |||
| 77 | 77 | ||
| 78 | // TODO: C-h help | 78 | // TODO: C-h help |
| 79 | 79 | ||
| 80 | // tab | ||
| 81 | Key.ctrl('i') => try buf.insertTab(), | ||
| 80 | // line feed | 82 | // line feed |
| 81 | Key.ctrl('j') => try buf.insertNewline(), | 83 | Key.ctrl('j') => try buf.insertNewline(), |
| 82 | Key.ctrl('k') => try buf.killLine(), | 84 | Key.ctrl('k') => try buf.killLine(), |