better repl logic

This commit is contained in:
Luna 2019-09-10 15:44:10 -03:00
parent 058bf8deb9
commit 88a73e64d8
1 changed files with 12 additions and 3 deletions

View File

@ -39,9 +39,15 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void {
// TODO start a runner and keep it hot // 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); var lang = langs.Lang.init(allocator);
defer lang.deinit(); defer lang.deinit();
var current: langs.Command = undefined;
while (true) { while (true) {
lang.reset(); lang.reset();
try stdout.print("> "); 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")) { if (std.mem.eql(u8, line, "push")) {
try file.seekTo(0); try cmds.append(current);
try printer.printList(cmds, stream);
continue; continue;
} else if (std.mem.eql(u8, line, "list")) { } 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); try printer.printList(cmds, stream);
continue; 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); std.debug.warn("repl: error while parsing: {}\n", err);
continue; continue;
}; };
try cmds.append(cmds_parsed.at(0)); current = cmds_parsed.at(0);
} }
} }