From e1b1321e0c0f3d914358d6a540dd1241853da0e8 Mon Sep 17 00:00:00 2001 From: Uko Kokņevičs Date: Sun, 2 Jan 2022 08:42:19 +0200 Subject: Some changes to promptYN --- src/Editor.zig | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Editor.zig b/src/Editor.zig index 99ec932..469fc81 100644 --- a/src/Editor.zig +++ b/src/Editor.zig @@ -245,7 +245,7 @@ pub fn promptEx( if (std.ascii.isSpace(key_char) or std.ascii.isGraph(key_char)) { try buf.append(key_char); } - }, // else ?? + }, // TODO: else ?? } if (callback) |cb| { @@ -265,18 +265,20 @@ pub fn promptYN(self: *Editor, prompt_str: []const u8) !bool { var response = try self.prompt(full_prompt); defer if (response) |str| self.allocator.free(str); // TODO: This can be improved - while (response == null - or response.?.len == 0 - or (response.?[0] != 'y' - and response.?[0] != 'Y' - and response.?[0] != 'n' - and response.?[0] != 'N') + while (response != null + and (response.?.len == 0 + or (response.?[0] != 'y' + and response.?[0] != 'Y' + and response.?[0] != 'n' + and response.?[0] != 'N' + ) + ) ) { if (response) |str| self.allocator.free(str); response = try self.prompt(full_prompt); } - return response.?[0] == 'y' or response.?[0] == 'Y'; + return response != null and (response.?[0] == 'y' or response.?[0] == 'Y'); } pub fn putBuffer(self: *Editor, buf_name: []const u8) !*Buffer { -- cgit v1.2.3