repl: use readline
This commit is contained in:
parent
8c5f42b3db
commit
cb689c3ade
2 changed files with 15 additions and 6 deletions
|
@ -6,6 +6,7 @@ fn setupLinks(step: *builds.LibExeObjStep) void {
|
|||
|
||||
step.linkSystemLibrary("lilv-0");
|
||||
step.linkSystemLibrary("sndfile");
|
||||
step.linkSystemLibrary("readline");
|
||||
|
||||
step.linkSystemLibrary("GraphicsMagickWand");
|
||||
step.linkSystemLibrary("GraphicsMagick");
|
||||
|
|
20
src/main.zig
20
src/main.zig
|
@ -8,6 +8,14 @@ test "scritcher" {
|
|||
_ = @import("runner.zig");
|
||||
}
|
||||
|
||||
const readline = @cImport({
|
||||
@cInclude("stdio.h");
|
||||
@cInclude("stdlib.h");
|
||||
|
||||
@cInclude("readline/readline.h");
|
||||
@cInclude("readline/history.h");
|
||||
});
|
||||
|
||||
fn wrapInCmdList(allocator: *std.mem.Allocator, cmd: langs.Command) !langs.CommandList {
|
||||
var cmds = langs.CommandList.init(allocator);
|
||||
try cmds.append(cmd);
|
||||
|
@ -69,13 +77,13 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void {
|
|||
|
||||
while (true) {
|
||||
lang.reset();
|
||||
try stdout.print("> ");
|
||||
|
||||
var buffer = try std.Buffer.init(allocator, ""[0..]);
|
||||
var line = std.io.readLine(&buffer) catch |err| {
|
||||
if (err == error.EndOfStream) break;
|
||||
return err;
|
||||
};
|
||||
var rd_line = readline.readline(c"> ");
|
||||
if (rd_line == null) break;
|
||||
readline.add_history(rd_line);
|
||||
defer std.heap.c_allocator.destroy(rd_line);
|
||||
|
||||
var line = rd_line[0..std.mem.len(u8, rd_line)];
|
||||
|
||||
if (std.mem.eql(u8, line, "push")) {
|
||||
try cmds.append(current);
|
||||
|
|
Loading…
Reference in a new issue