summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Buffer.zig17
-rw-r--r--src/Config.zig10
-rw-r--r--src/Editor.zig23
-rw-r--r--src/RawMode.zig19
-rw-r--r--src/Row.zig9
-rw-r--r--src/Syntax/makefile.zig4
-rw-r--r--src/Syntax/zig.zig3
-rw-r--r--src/key_state.zig10
-rw-r--r--src/main.zig16
-rw-r--r--src/search.zig9
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 @@
1const conf = @import("es-config"); 1const es = @import("root");
2const std = @import("std"); 2const std = @import("std");
3 3
4const Allocator = std.mem.Allocator; 4const Allocator = std.mem.Allocator;
5const ArrayList = std.ArrayList; 5const ArrayList = std.ArrayList;
6const Buffer = @This(); 6const Buffer = @This();
7const Config = @import("Config.zig"); 7const Config = es.Config;
8const File = std.fs.File; 8const File = std.fs.File;
9const files = @import("files.zig"); 9const Editor = es.Editor;
10const Editor = @import("Editor.zig"); 10const Highlight = es.Highlight;
11const Highlight = @import("highlight.zig").Highlight; 11const Row = es.Row;
12const Row = @import("Row.zig"); 12const Syntax = es.Syntax;
13const Syntax = @import("Syntax.zig");
14 13
15allocator: Allocator, 14allocator: 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
3const conf = @import("es-config"); 3const es = @import("root");
4const std = @import("std"); 4const std = @import("std");
5 5
6const Allocator = std.mem.Allocator; 6const Allocator = std.mem.Allocator;
@@ -9,10 +9,10 @@ const Config = @This();
9 9
10const config_path = "arkta/es/es.ini"; 10const config_path = "arkta/es/es.ini";
11 11
12hard_tabs: bool = conf.default_hard_tabs, 12hard_tabs: bool = es.conf.default_hard_tabs,
13line_limit: usize = conf.default_line_limit, 13line_limit: usize = es.conf.default_line_limit,
14page_overlap: usize = conf.default_page_overlap, 14page_overlap: usize = es.conf.default_page_overlap,
15tab_stop: usize = conf.default_tab_stop, 15tab_stop: usize = es.conf.default_tab_stop,
16 16
17pub fn readConfig(allocator: Allocator) !Config { 17pub 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 @@
1const linux = std.os.linux; 1const es = @import("root");
2const std = @import("std"); 2const std = @import("std");
3 3
4const Allocator = std.mem.Allocator; 4const Allocator = std.mem.Allocator;
5const ArrayList = std.ArrayList; 5const ArrayList = std.ArrayList;
6const Buffer = @import("Buffer.zig"); 6const Buffer = es.Buffer;
7const Editor = @This(); 7const Editor = @This();
8const files = @import("files.zig"); 8const Key = es.Key;
9const Key = @import("key.zig").Key; 9const KeyState = es.key_state.KeyState;
10const key_state = @import("key_state.zig"); 10const StringBuilder = es.StringBuilder;
11const KeyState = key_state.KeyState;
12const STDIN_FILENO = std.os.STDIN_FILENO;
13const StringBuilder = @import("StringBuilder.zig");
14const StringHashMap = std.StringHashMap; 11const StringHashMap = std.StringHashMap;
15 12
16allocator: Allocator, 13allocator: 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
152pub fn open(self: *Editor, name: []const u8) !void { 149pub 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
413fn getWindowSize(rows: *usize, cols: *usize) !void { 410fn 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 @@
1const linux = std.os.linux; 1const linux = std.os.linux;
2const std = @import("std"); 2const std = @import("std");
3 3
4const STDIN_FILENO = std.os.STDIN_FILENO;
5const RawMode = @This(); 4const RawMode = @This();
6const tcflag_t = linux.tcflag_t;
7const tcgetattr = std.os.tcgetattr;
8const tcsetattr = std.os.tcsetattr;
9const termios = std.os.termios; 5const termios = std.os.termios;
10 6
11orig: termios, 7orig: termios,
12 8
13pub fn init() !RawMode { 9pub 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
34pub fn deinit(self: RawMode) void { 33pub 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 @@
1const es = @import("root");
1const std = @import("std"); 2const std = @import("std");
2 3
3const Allocator = std.mem.Allocator; 4const Allocator = std.mem.Allocator;
4const ArrayList = std.ArrayList; 5const ArrayList = std.ArrayList;
5const Buffer = @import("Buffer.zig"); 6const Buffer = es.Buffer;
6const Config = @import("Config.zig"); 7const Config = es.Config;
7const Highlight = @import("highlight.zig").Highlight; 8const Highlight = es.Highlight;
8const Row = @This(); 9const Row = @This();
9const StringBuilder = @import("StringBuilder.zig"); 10const StringBuilder = es.StringBuilder;
10 11
11allocator: Allocator, 12allocator: 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
3const Syntax = @import("../Syntax.zig"); 3const es = @import("root");
4
5const Syntax = es.Syntax;
4 6
5pub const syntax = Syntax{ 7pub 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
3const es = @import("root");
3const std = @import("std"); 4const std = @import("std");
4 5
5const Syntax = @import("../Syntax.zig"); 6const Syntax = es.Syntax;
6 7
7// TODO: Add support for the multiline string \\ 8// TODO: Add support for the multiline string \\
8pub const syntax = Syntax{ 9pub 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 @@
1const es = @import("root");
1const std = @import("std"); 2const std = @import("std");
2 3
3const Buffer = @import("Buffer.zig"); 4const Buffer = es.Buffer;
4const Editor = @import("Editor.zig"); 5const Editor = es.Editor;
5const Key = @import("key.zig").Key; 6const Key = es.Key;
6const search = @import("search.zig").search;
7 7
8pub const Error = error{ 8pub 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 @@
1pub const Buffer = @import("Buffer.zig");
2pub const conf = @import("es-config");
3pub const Config = @import("Config.zig");
4pub const Editor = @import("Editor.zig");
5pub const files = @import("files.zig");
6pub const Highlight = @import("highlight.zig").Highlight;
7pub const key_state = @import("key_state.zig");
8pub const Key = @import("key.zig").Key;
9pub const RawMode = @import("RawMode.zig");
10pub const Row = @import("Row.zig");
11pub const search = @import("search.zig").search;
12pub const StringBuilder = @import("StringBuilder.zig");
13pub const Syntax = @import("Syntax.zig");
14
1const std = @import("std"); 15const std = @import("std");
2 16
3const Allocator = std.mem.Allocator; 17const Allocator = std.mem.Allocator;
4const Editor = @import("Editor.zig");
5const File = std.fs.File; 18const File = std.fs.File;
6const GPA = std.heap.GeneralPurposeAllocator(.{}); 19const GPA = std.heap.GeneralPurposeAllocator(.{});
7const RawMode = @import("RawMode.zig");
8 20
9var log_file: ?File = null; 21var 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 @@
1const es = @import("root");
1const std = @import("std"); 2const std = @import("std");
2 3
3const Allocator = std.mem.Allocator; 4const Allocator = std.mem.Allocator;
4const ArrayList = std.ArrayList; 5const ArrayList = std.ArrayList;
5const Buffer = @import("Buffer.zig"); 6const Buffer = es.Buffer;
6const Editor = @import("Editor.zig"); 7const Editor = es.Editor;
7const Highlight = @import("highlight.zig").Highlight; 8const Highlight = es.Highlight;
8const Key = @import("key.zig").Key; 9const Key = es.Key;
9 10
10const CallbackData = struct { 11const CallbackData = struct {
11 allocator: Allocator, 12 allocator: Allocator,