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; } }