blob: 9c81776eb07e2844ae51638328e1391afbfa896f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
const std = @import("std");
const Allocator = std.mem.Allocator;
const Editor = @import("Editor.zig");
const GPA = std.heap.GeneralPurposeAllocator(.{});
const RawMode = @import("RawMode.zig");
pub fn main() !void {
var gpa = GPA{};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
const raw_mode = try RawMode.init();
defer raw_mode.deinit();
var editor = try Editor.init(allocator);
defer editor.deinit();
try processCommandLineArgs(allocator, &editor);
try editor.setStatusMessage("C-x C-s = Save | C-x C-c = Quit | C-s = Search", .{});
while (!editor.should_exit) {
try editor.refreshScreen();
try editor.processKeypress();
}
}
fn processCommandLineArgs(allocator: Allocator, editor: *Editor) !void {
const args = try std.process.argsAlloc(allocator);
defer std.process.argsFree(allocator, args);
if (args.len <= 1) {
// Do nothing
} else if (args.len == 2) {
try editor.open(args[1]);
} else {
std.log.err("What am I to do with {} arguments?", .{args.len});
return error.CommandLineArgs;
}
}
|