Skip to content

Commit

Permalink
fix(repl): Better handle Ctrl-C, Ctrl-D
Browse files Browse the repository at this point in the history
  • Loading branch information
giann committed May 13, 2024
1 parent 93bc16f commit fd9e5a4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/linenoise.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub const linenoiseCompletions = extern struct {
};

// Blocking API.
pub extern fn linenoise(prompt: [*:0]const u8) [*:0]const u8;
pub extern fn linenoise(prompt: [*:0]const u8) ?[*:0]const u8;

// Completion API.
pub const linenoiseCompletionCallback = fn ([*:0]const u8, *linenoiseCompletions) void;
Expand Down
7 changes: 6 additions & 1 deletion src/repl.zig
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,12 @@ pub fn repl(allocator: std.mem.Allocator) !void {
var previous_type_registry = try gc.type_registry.registry.clone();
while (true) {
const read_source = ln.linenoise("> ");
const source = std.mem.span(read_source);

if (read_source == null) {
std.process.exit(0);
}

const source = std.mem.span(read_source.?);

_ = ln.linenoiseHistoryAdd(source);
_ = ln.linenoiseHistorySave(@ptrCast(buzz_history_path.items.ptr));
Expand Down

0 comments on commit fd9e5a4

Please sign in to comment.