From fd9e5a4624745ac78db5c3bb4ae22005b7b4e1d9 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Mon, 13 May 2024 20:51:53 +0200 Subject: [PATCH] fix(repl): Better handle Ctrl-C, Ctrl-D --- src/linenoise.zig | 2 +- src/repl.zig | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/linenoise.zig b/src/linenoise.zig index 6d24b75c..744973f2 100644 --- a/src/linenoise.zig +++ b/src/linenoise.zig @@ -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; diff --git a/src/repl.zig b/src/repl.zig index e7df1974..827423dc 100644 --- a/src/repl.zig +++ b/src/repl.zig @@ -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));