diff options
| author | 2022-01-02 00:17:47 +0200 | |
|---|---|---|
| committer | 2022-01-02 00:17:47 +0200 | |
| commit | bd3101517b7b2d0d81f2014eb3c2613e82b25def (patch) | |
| tree | 72cffbbcdc2be0f22987e1a4cb20892fbc3db052 | |
| parent | changes (diff) | |
| download | es-bd3101517b7b2d0d81f2014eb3c2613e82b25def.tar.gz es-bd3101517b7b2d0d81f2014eb3c2613e82b25def.tar.xz es-bd3101517b7b2d0d81f2014eb3c2613e82b25def.zip | |
hierarchy changes
| -rw-r--r-- | src/Buffer.zig | 17 | ||||
| -rw-r--r-- | src/Config.zig | 10 | ||||
| -rw-r--r-- | src/Editor.zig | 23 | ||||
| -rw-r--r-- | src/RawMode.zig | 19 | ||||
| -rw-r--r-- | src/Row.zig | 9 | ||||
| -rw-r--r-- | src/Syntax/makefile.zig | 4 | ||||
| -rw-r--r-- | src/Syntax/zig.zig | 3 | ||||
| -rw-r--r-- | src/key_state.zig | 10 | ||||
| -rw-r--r-- | src/main.zig | 16 | ||||
| -rw-r--r-- | src/search.zig | 9 |
10 files changed, 66 insertions, 54 deletions
diff --git a/src/Buffer.zig b/src/Buffer.zig index 0c95e6e..7f6e7d7 100644 --- a/src/Buffer.zig +++ b/src/Buffer.zig | |||
| @@ -1,16 +1,15 @@ | |||
| 1 | const conf = @import("es-config"); | 1 | const es = @import("root"); |
| 2 | const std = @import("std"); | 2 | const std = @import("std"); |
| 3 | 3 | ||
| 4 | const Allocator = std.mem.Allocator; | 4 | const Allocator = std.mem.Allocator; |
| 5 | const ArrayList = std.ArrayList; | 5 | const ArrayList = std.ArrayList; |
| 6 | const Buffer = @This(); | 6 | const Buffer = @This(); |
| 7 | const Config = @import("Config.zig"); | 7 | const Config = es.Config; |
| 8 | const File = std.fs.File; | 8 | const File = std.fs.File; |
| 9 | const files = @import("files.zig"); | 9 | const Editor = es.Editor; |
| 10 | const Editor = @import("Editor.zig"); | 10 | const Highlight = es.Highlight; |
| 11 | const Highlight = @import("highlight.zig").Highlight; | 11 | const Row = es.Row; |
| 12 | const Row = @import("Row.zig"); | 12 | const Syntax = es.Syntax; |
| 13 | const Syntax = @import("Syntax.zig"); | ||
| 14 | 13 | ||
| 15 | allocator: Allocator, | 14 | allocator: Allocator, |
| 16 | 15 | ||
| @@ -200,7 +199,7 @@ pub fn drawRows(self: Buffer, writer: anytype, screenrows: usize, screencols: us | |||
| 200 | const welcome_data = try std.fmt.allocPrint( | 199 | const welcome_data = try std.fmt.allocPrint( |
| 201 | self.allocator, | 200 | self.allocator, |
| 202 | "ES -- version {}", | 201 | "ES -- version {}", |
| 203 | .{conf.es_version}, | 202 | .{es.conf.es_version}, |
| 204 | ); | 203 | ); |
| 205 | defer self.allocator.free(welcome_data); | 204 | defer self.allocator.free(welcome_data); |
| 206 | var welcome = welcome_data; | 205 | var welcome = welcome_data; |
| @@ -435,7 +434,7 @@ pub fn save(self: *Buffer, editor: *Editor) !void { | |||
| 435 | const fname = (try editor.prompt("Save as")) orelse { return; }; | 434 | const fname = (try editor.prompt("Save as")) orelse { return; }; |
| 436 | defer self.allocator.free(fname); | 435 | defer self.allocator.free(fname); |
| 437 | 436 | ||
| 438 | const file_path = try files.resolvePath(self.allocator, fname); | 437 | const file_path = try es.files.resolvePath(self.allocator, fname); |
| 439 | errdefer self.allocator.free(file_path); | 438 | errdefer self.allocator.free(file_path); |
| 440 | 439 | ||
| 441 | const file_name = std.fs.path.basename(file_path); | 440 | const file_name = std.fs.path.basename(file_path); |
diff --git a/src/Config.zig b/src/Config.zig index 071c31b..2e6c388 100644 --- a/src/Config.zig +++ b/src/Config.zig | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | // TODO: Change this to proper TOML in the future :) | 1 | // TODO: Change this to proper TOML in the future :) |
| 2 | 2 | ||
| 3 | const conf = @import("es-config"); | 3 | const es = @import("root"); |
| 4 | const std = @import("std"); | 4 | const std = @import("std"); |
| 5 | 5 | ||
| 6 | const Allocator = std.mem.Allocator; | 6 | const Allocator = std.mem.Allocator; |
| @@ -9,10 +9,10 @@ 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 | hard_tabs: bool = es.conf.default_hard_tabs, |
| 13 | line_limit: usize = conf.default_line_limit, | 13 | line_limit: usize = es.conf.default_line_limit, |
| 14 | page_overlap: usize = conf.default_page_overlap, | 14 | page_overlap: usize = es.conf.default_page_overlap, |
| 15 | tab_stop: usize = conf.default_tab_stop, | 15 | tab_stop: usize = es.conf.default_tab_stop, |
| 16 | 16 | ||
| 17 | pub fn readConfig(allocator: Allocator) !Config { | 17 | pub fn readConfig(allocator: Allocator) !Config { |
| 18 | var config = Config{}; | 18 | var config = Config{}; |
diff --git a/src/Editor.zig b/src/Editor.zig index 42b5619..4b563ad 100644 --- a/src/Editor.zig +++ b/src/Editor.zig | |||
| @@ -1,16 +1,13 @@ | |||
| 1 | const linux = std.os.linux; | 1 | const es = @import("root"); |
| 2 | const std = @import("std"); | 2 | const std = @import("std"); |
| 3 | 3 | ||
| 4 | const Allocator = std.mem.Allocator; | 4 | const Allocator = std.mem.Allocator; |
| 5 | const ArrayList = std.ArrayList; | 5 | const ArrayList = std.ArrayList; |
| 6 | const Buffer = @import("Buffer.zig"); | 6 | const Buffer = es.Buffer; |
| 7 | const Editor = @This(); | 7 | const Editor = @This(); |
| 8 | const files = @import("files.zig"); | 8 | const Key = es.Key; |
| 9 | const Key = @import("key.zig").Key; | 9 | const KeyState = es.key_state.KeyState; |
| 10 | const key_state = @import("key_state.zig"); | 10 | const StringBuilder = es.StringBuilder; |
| 11 | const KeyState = key_state.KeyState; | ||
| 12 | const STDIN_FILENO = std.os.STDIN_FILENO; | ||
| 13 | const StringBuilder = @import("StringBuilder.zig"); | ||
| 14 | const StringHashMap = std.StringHashMap; | 11 | const StringHashMap = std.StringHashMap; |
| 15 | 12 | ||
| 16 | allocator: Allocator, | 13 | allocator: Allocator, |
| @@ -42,7 +39,7 @@ pub fn init(allocator: Allocator) !Editor { | |||
| 42 | .statusmsg = null, | 39 | .statusmsg = null, |
| 43 | .statusmsg_time = 0, | 40 | .statusmsg_time = 0, |
| 44 | 41 | ||
| 45 | .current_state = key_state.defaultState, | 42 | .current_state = es.key_state.defaultState, |
| 46 | 43 | ||
| 47 | .key_buffer = ArrayList(Key).init(allocator), | 44 | .key_buffer = ArrayList(Key).init(allocator), |
| 48 | .should_exit = false, | 45 | .should_exit = false, |
| @@ -150,7 +147,7 @@ pub fn killCurrentBuffer(self: *Editor) !bool { | |||
| 150 | } | 147 | } |
| 151 | 148 | ||
| 152 | pub fn open(self: *Editor, name: []const u8) !void { | 149 | pub fn open(self: *Editor, name: []const u8) !void { |
| 153 | const file_path = try files.resolvePath(self.allocator, name); | 150 | const file_path = try es.files.resolvePath(self.allocator, name); |
| 154 | defer self.allocator.free(file_path); | 151 | defer self.allocator.free(file_path); |
| 155 | 152 | ||
| 156 | if (self.getBufferByPath(file_path)) |buffer| { | 153 | if (self.getBufferByPath(file_path)) |buffer| { |
| @@ -411,9 +408,9 @@ fn getCursorPosition(row: *usize, col: *usize) !void { | |||
| 411 | } | 408 | } |
| 412 | 409 | ||
| 413 | fn getWindowSize(rows: *usize, cols: *usize) !void { | 410 | fn getWindowSize(rows: *usize, cols: *usize) !void { |
| 414 | var ws: linux.winsize = undefined; | 411 | var ws: std.os.linux.winsize = undefined; |
| 415 | const rc = linux.ioctl(STDIN_FILENO, linux.T.IOCGWINSZ, @ptrToInt(&ws)); | 412 | const rc = std.os.linux.ioctl(std.os.STDIN_FILENO, std.os.linux.T.IOCGWINSZ, @ptrToInt(&ws)); |
| 416 | switch (linux.getErrno(rc)) { | 413 | switch (std.os.linux.getErrno(rc)) { |
| 417 | .SUCCESS => { | 414 | .SUCCESS => { |
| 418 | cols.* = ws.ws_col; | 415 | cols.* = ws.ws_col; |
| 419 | rows.* = ws.ws_row; | 416 | rows.* = ws.ws_row; |
diff --git a/src/RawMode.zig b/src/RawMode.zig index ed71819..7298922 100644 --- a/src/RawMode.zig +++ b/src/RawMode.zig | |||
| @@ -1,38 +1,37 @@ | |||
| 1 | const linux = std.os.linux; | 1 | const linux = std.os.linux; |
| 2 | const std = @import("std"); | 2 | const std = @import("std"); |
| 3 | 3 | ||
| 4 | const STDIN_FILENO = std.os.STDIN_FILENO; | ||
| 5 | const RawMode = @This(); | 4 | const RawMode = @This(); |
| 6 | const tcflag_t = linux.tcflag_t; | ||
| 7 | const tcgetattr = std.os.tcgetattr; | ||
| 8 | const tcsetattr = std.os.tcsetattr; | ||
| 9 | const termios = std.os.termios; | 5 | const termios = std.os.termios; |
| 10 | 6 | ||
| 11 | orig: termios, | 7 | orig: termios, |
| 12 | 8 | ||
| 13 | pub fn init() !RawMode { | 9 | pub fn init() !RawMode { |
| 14 | const orig = try tcgetattr(STDIN_FILENO); | 10 | const orig = try std.os.tcgetattr(std.os.STDIN_FILENO); |
| 15 | const self = RawMode{ .orig = orig }; | 11 | const self = RawMode{ .orig = orig }; |
| 16 | errdefer self.deinit(); | 12 | errdefer self.deinit(); |
| 17 | 13 | ||
| 18 | var raw = orig; | 14 | var raw = orig; |
| 19 | 15 | ||
| 20 | raw.iflag &= ~@as(tcflag_t, linux.BRKINT | linux.ICRNL | linux.INPCK | linux.ISTRIP | linux.IXON); | 16 | raw.iflag &= ~@as( |
| 21 | raw.lflag &= ~@as(tcflag_t, linux.ECHO | linux.ICANON | linux.IEXTEN | linux.ISIG); | 17 | linux.tcflag_t, |
| 22 | raw.oflag &= ~@as(tcflag_t, linux.OPOST); | 18 | linux.BRKINT | linux.ICRNL | linux.INPCK | linux.ISTRIP | linux.IXON, |
| 19 | ); | ||
| 20 | raw.lflag &= ~@as(linux.tcflag_t, linux.ECHO | linux.ICANON | linux.IEXTEN | linux.ISIG); | ||
| 21 | raw.oflag &= ~@as(linux.tcflag_t, linux.OPOST); | ||
| 23 | 22 | ||
| 24 | raw.cflag |= linux.CS8; | 23 | raw.cflag |= linux.CS8; |
| 25 | 24 | ||
| 26 | raw.cc[linux.V.MIN] = 0; | 25 | raw.cc[linux.V.MIN] = 0; |
| 27 | raw.cc[linux.V.TIME] = 1; | 26 | raw.cc[linux.V.TIME] = 1; |
| 28 | 27 | ||
| 29 | try tcsetattr(STDIN_FILENO, .FLUSH, raw); | 28 | try std.os.tcsetattr(std.os.STDIN_FILENO, .FLUSH, raw); |
| 30 | 29 | ||
| 31 | return self; | 30 | return self; |
| 32 | } | 31 | } |
| 33 | 32 | ||
| 34 | pub fn deinit(self: RawMode) void { | 33 | pub fn deinit(self: RawMode) void { |
| 35 | tcsetattr(STDIN_FILENO, .FLUSH, self.orig) catch |err| { | 34 | std.os.tcsetattr(std.os.STDIN_FILENO, .FLUSH, self.orig) catch |err| { |
| 36 | std.log.err("Failed to reset termios: {}", .{err}); | 35 | std.log.err("Failed to reset termios: {}", .{err}); |
| 37 | }; | 36 | }; |
| 38 | } | 37 | } |
diff --git a/src/Row.zig b/src/Row.zig index a542160..38fb72b 100644 --- a/src/Row.zig +++ b/src/Row.zig | |||
| @@ -1,12 +1,13 @@ | |||
| 1 | const es = @import("root"); | ||
| 1 | const std = @import("std"); | 2 | const std = @import("std"); |
| 2 | 3 | ||
| 3 | const Allocator = std.mem.Allocator; | 4 | const Allocator = std.mem.Allocator; |
| 4 | const ArrayList = std.ArrayList; | 5 | const ArrayList = std.ArrayList; |
| 5 | const Buffer = @import("Buffer.zig"); | 6 | const Buffer = es.Buffer; |
| 6 | const Config = @import("Config.zig"); | 7 | const Config = es.Config; |
| 7 | const Highlight = @import("highlight.zig").Highlight; | 8 | const Highlight = es.Highlight; |
| 8 | const Row = @This(); | 9 | const Row = @This(); |
| 9 | const StringBuilder = @import("StringBuilder.zig"); | 10 | const StringBuilder = es.StringBuilder; |
| 10 | 11 | ||
| 11 | allocator: Allocator, | 12 | allocator: Allocator, |
| 12 | 13 | ||
diff --git a/src/Syntax/makefile.zig b/src/Syntax/makefile.zig index caf1317..5c93df4 100644 --- a/src/Syntax/makefile.zig +++ b/src/Syntax/makefile.zig | |||
| @@ -1,6 +1,8 @@ | |||
| 1 | // zig fmt: off | 1 | // zig fmt: off |
| 2 | 2 | ||
| 3 | const Syntax = @import("../Syntax.zig"); | 3 | const es = @import("root"); |
| 4 | |||
| 5 | const Syntax = es.Syntax; | ||
| 4 | 6 | ||
| 5 | pub const syntax = Syntax{ | 7 | pub const syntax = Syntax{ |
| 6 | .name = "Makefile", | 8 | .name = "Makefile", |
diff --git a/src/Syntax/zig.zig b/src/Syntax/zig.zig index 9519c74..4826bfb 100644 --- a/src/Syntax/zig.zig +++ b/src/Syntax/zig.zig | |||
| @@ -1,8 +1,9 @@ | |||
| 1 | // zig fmt: off | 1 | // zig fmt: off |
| 2 | 2 | ||
| 3 | const es = @import("root"); | ||
| 3 | const std = @import("std"); | 4 | const std = @import("std"); |
| 4 | 5 | ||
| 5 | const Syntax = @import("../Syntax.zig"); | 6 | const Syntax = es.Syntax; |
| 6 | 7 | ||
| 7 | // TODO: Add support for the multiline string \\ | 8 | // TODO: Add support for the multiline string \\ |
| 8 | pub const syntax = Syntax{ | 9 | pub const syntax = Syntax{ |
diff --git a/src/key_state.zig b/src/key_state.zig index f1880ae..ce20071 100644 --- a/src/key_state.zig +++ b/src/key_state.zig | |||
| @@ -1,9 +1,9 @@ | |||
| 1 | const es = @import("root"); | ||
| 1 | const std = @import("std"); | 2 | const std = @import("std"); |
| 2 | 3 | ||
| 3 | const Buffer = @import("Buffer.zig"); | 4 | const Buffer = es.Buffer; |
| 4 | const Editor = @import("Editor.zig"); | 5 | const Editor = es.Editor; |
| 5 | const Key = @import("key.zig").Key; | 6 | const Key = es.Key; |
| 6 | const search = @import("search.zig").search; | ||
| 7 | 7 | ||
| 8 | pub const Error = error{ | 8 | pub const Error = error{ |
| 9 | MalformedConfig, | 9 | MalformedConfig, |
| @@ -93,7 +93,7 @@ pub fn defaultState(editor: *Editor, buf: *Buffer, key: Key) Error!void { | |||
| 93 | Key.ctrl('m') => try buf.insertNewline(), | 93 | Key.ctrl('m') => try buf.insertNewline(), |
| 94 | Key.ctrl('n'), Key.down => buf.nextLine(), | 94 | Key.ctrl('n'), Key.down => buf.nextLine(), |
| 95 | Key.ctrl('p'), Key.up => buf.previousLine(), | 95 | Key.ctrl('p'), Key.up => buf.previousLine(), |
| 96 | Key.ctrl('s') => try search(editor, buf), | 96 | Key.ctrl('s') => try es.search(editor, buf), |
| 97 | 97 | ||
| 98 | // TODO: C-q quotedInsert | 98 | // TODO: C-q quotedInsert |
| 99 | 99 | ||
diff --git a/src/main.zig b/src/main.zig index 7a4aaa4..eae3b8b 100644 --- a/src/main.zig +++ b/src/main.zig | |||
| @@ -1,10 +1,22 @@ | |||
| 1 | pub const Buffer = @import("Buffer.zig"); | ||
| 2 | pub const conf = @import("es-config"); | ||
| 3 | pub const Config = @import("Config.zig"); | ||
| 4 | pub const Editor = @import("Editor.zig"); | ||
| 5 | pub const files = @import("files.zig"); | ||
| 6 | pub const Highlight = @import("highlight.zig").Highlight; | ||
| 7 | pub const key_state = @import("key_state.zig"); | ||
| 8 | pub const Key = @import("key.zig").Key; | ||
| 9 | pub const RawMode = @import("RawMode.zig"); | ||
| 10 | pub const Row = @import("Row.zig"); | ||
| 11 | pub const search = @import("search.zig").search; | ||
| 12 | pub const StringBuilder = @import("StringBuilder.zig"); | ||
| 13 | pub const Syntax = @import("Syntax.zig"); | ||
| 14 | |||
| 1 | const std = @import("std"); | 15 | const std = @import("std"); |
| 2 | 16 | ||
| 3 | const Allocator = std.mem.Allocator; | 17 | const Allocator = std.mem.Allocator; |
| 4 | const Editor = @import("Editor.zig"); | ||
| 5 | const File = std.fs.File; | 18 | const File = std.fs.File; |
| 6 | const GPA = std.heap.GeneralPurposeAllocator(.{}); | 19 | const GPA = std.heap.GeneralPurposeAllocator(.{}); |
| 7 | const RawMode = @import("RawMode.zig"); | ||
| 8 | 20 | ||
| 9 | var log_file: ?File = null; | 21 | var log_file: ?File = null; |
| 10 | 22 | ||
diff --git a/src/search.zig b/src/search.zig index 557b030..321f948 100644 --- a/src/search.zig +++ b/src/search.zig | |||
| @@ -1,11 +1,12 @@ | |||
| 1 | const es = @import("root"); | ||
| 1 | const std = @import("std"); | 2 | const std = @import("std"); |
| 2 | 3 | ||
| 3 | const Allocator = std.mem.Allocator; | 4 | const Allocator = std.mem.Allocator; |
| 4 | const ArrayList = std.ArrayList; | 5 | const ArrayList = std.ArrayList; |
| 5 | const Buffer = @import("Buffer.zig"); | 6 | const Buffer = es.Buffer; |
| 6 | const Editor = @import("Editor.zig"); | 7 | const Editor = es.Editor; |
| 7 | const Highlight = @import("highlight.zig").Highlight; | 8 | const Highlight = es.Highlight; |
| 8 | const Key = @import("key.zig").Key; | 9 | const Key = es.Key; |
| 9 | 10 | ||
| 10 | const CallbackData = struct { | 11 | const CallbackData = struct { |
| 11 | allocator: Allocator, | 12 | allocator: Allocator, |