Browse Source

repl: use readline

embed-mp3
Luna 3 years ago
parent
commit
cb689c3ade
  1. 1
      build.zig
  2. 20
      src/main.zig

1
build.zig

@ -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

@ -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…
Cancel
Save