summaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
authorGravatar Uko Kokņevičs2021-12-21 05:56:41 +0200
committerGravatar Uko Kokņevičs2021-12-21 05:56:41 +0200
commit2d2278364b6186c6cdf0f0497b0498431dfe7dd1 (patch)
tree8f2329afbc90817c855f5c5154a547a58a9458aa /src/main.zig
downloades-2d2278364b6186c6cdf0f0497b0498431dfe7dd1.tar.gz
es-2d2278364b6186c6cdf0f0497b0498431dfe7dd1.tar.xz
es-2d2278364b6186c6cdf0f0497b0498431dfe7dd1.zip
Initial config
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/main.zig b/src/main.zig
new file mode 100644
index 0000000..9c81776
--- /dev/null
+++ b/src/main.zig
@@ -0,0 +1,40 @@
1const std = @import("std");
2
3const Allocator = std.mem.Allocator;
4const Editor = @import("Editor.zig");
5const GPA = std.heap.GeneralPurposeAllocator(.{});
6const RawMode = @import("RawMode.zig");
7
8pub fn main() !void {
9 var gpa = GPA{};
10 defer _ = gpa.deinit();
11 const allocator = gpa.allocator();
12
13 const raw_mode = try RawMode.init();
14 defer raw_mode.deinit();
15
16 var editor = try Editor.init(allocator);
17 defer editor.deinit();
18
19 try processCommandLineArgs(allocator, &editor);
20
21 try editor.setStatusMessage("C-x C-s = Save | C-x C-c = Quit | C-s = Search", .{});
22
23 while (!editor.should_exit) {
24 try editor.refreshScreen();
25 try editor.processKeypress();
26 }
27}
28
29fn processCommandLineArgs(allocator: Allocator, editor: *Editor) !void {
30 const args = try std.process.argsAlloc(allocator);
31 defer std.process.argsFree(allocator, args);
32 if (args.len <= 1) {
33 // Do nothing
34 } else if (args.len == 2) {
35 try editor.open(args[1]);
36 } else {
37 std.log.err("What am I to do with {} arguments?", .{args.len});
38 return error.CommandLineArgs;
39 }
40}