better repl logic
This commit is contained in:
parent
058bf8deb9
commit
88a73e64d8
1 changed files with 12 additions and 3 deletions
15
src/main.zig
15
src/main.zig
|
@ -39,9 +39,15 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void {
|
|||
|
||||
// TODO start a runner and keep it hot
|
||||
|
||||
// we keep
|
||||
// - a CommandList with the full commands we have right now
|
||||
// - a Command with the current last typed successful command
|
||||
|
||||
var lang = langs.Lang.init(allocator);
|
||||
defer lang.deinit();
|
||||
|
||||
var current: langs.Command = undefined;
|
||||
|
||||
while (true) {
|
||||
lang.reset();
|
||||
try stdout.print("> ");
|
||||
|
@ -53,10 +59,13 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void {
|
|||
};
|
||||
|
||||
if (std.mem.eql(u8, line, "push")) {
|
||||
try file.seekTo(0);
|
||||
try printer.printList(cmds, stream);
|
||||
try cmds.append(current);
|
||||
continue;
|
||||
} else if (std.mem.eql(u8, line, "list")) {
|
||||
try printer.printList(cmds, stdout);
|
||||
continue;
|
||||
} else if (std.mem.eql(u8, line, "save")) {
|
||||
try file.seekTo(0);
|
||||
try printer.printList(cmds, stream);
|
||||
continue;
|
||||
}
|
||||
|
@ -65,7 +74,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void {
|
|||
std.debug.warn("repl: error while parsing: {}\n", err);
|
||||
continue;
|
||||
};
|
||||
try cmds.append(cmds_parsed.at(0));
|
||||
current = cmds_parsed.at(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue