From 7d10c8f0a4d7103ac5a63ed52fa6ba173bc355bf Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 26 Apr 2022 19:52:51 -0700 Subject: [PATCH] catch errors in ttyRead --- src/Window.zig | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Window.zig b/src/Window.zig index aaf5844c1..f5d9758c8 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -354,9 +354,20 @@ fn ttyRead(t: *libuv.Tty, n: isize, buf: []const u8) void { // log.info("DATA: {any}", .{buf[0..@intCast(usize, n)]}); + // First check for errors in the case n is less than 0. + libuv.convertError(@intCast(i32, n)) catch |err| { + switch (err) { + // ignore EOF because it should end the process. + libuv.Error.EOF => {}, + else => log.err("read error: {}", .{err}), + } + + return; + }; + + // Add this character to the terminal buffer. win.terminal.append(win.alloc, buf[0..@intCast(usize, n)]) catch |err| log.err("error writing terminal data: {}", .{err}); - win.grid.updateCells(win.terminal) catch unreachable; // Whenever a character is typed, we ensure the cursor is visible // and we restart the cursor timer.