From 335ea9f2d0655a75ce68b56fceeb603499a5cfe3 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Thu, 30 May 2024 10:06:28 -0500 Subject: [PATCH] xev: fix todos --- examples/xev.zig | 2 -- src/xev.zig | 32 ++++++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/examples/xev.zig b/examples/xev.zig index 23c2c18..a0e2165 100644 --- a/examples/xev.zig +++ b/examples/xev.zig @@ -37,7 +37,6 @@ pub fn main() !void { try vx.queryTerminalSend(tty.anyWriter()); try loop.run(.until_done); - @panic("AHHH"); } fn callback( @@ -56,7 +55,6 @@ fn callback( .winsize => |ws| watcher.vx.resize(ud.?.*, watcher.tty.anyWriter(), ws) catch @panic("TODO"), else => {}, } - std.log.debug("a", .{}); const win = watcher.vx.window(); win.clear(); watcher.vx.render(watcher.tty.anyWriter()) catch { diff --git a/src/xev.zig b/src/xev.zig index b5ed13d..30686cd 100644 --- a/src/xev.zig +++ b/src/xev.zig @@ -105,7 +105,9 @@ pub fn TtyWatcher(comptime Userdata: type) type { fn signalCallback(ptr: *anyopaque) void { const self: *Self = @ptrCast(@alignCast(ptr)); - self.winsize_wakeup.notify() catch @panic("TODO"); + self.winsize_wakeup.notify() catch |err| { + log.warn("couldn't wake up winsize callback: {}", .{err}); + }; } fn ttyReadCallback( @@ -117,7 +119,10 @@ pub fn TtyWatcher(comptime Userdata: type) type { r: xev.ReadError!usize, ) xev.CallbackAction { _ = c; // autofix - const n = r catch @panic("TODO"); + const n = r catch |err| { + log.err("read error: {}", .{err}); + return .disarm; + }; const self = ud orelse unreachable; // reset read start state @@ -125,7 +130,10 @@ pub fn TtyWatcher(comptime Userdata: type) type { var seq_start: usize = 0; parse_loop: while (seq_start < n) { - const result = self.parser.parse(buf.slice[seq_start..n], null) catch @panic("TODO"); + const result = self.parser.parse(buf.slice[seq_start..n], null) catch |err| { + log.err("couldn't parse input: {}", .{err}); + return .disarm; + }; if (result.n == 0) { // copy the read to the beginning. We don't use memcpy because // this could be overlapping, and it's also rare @@ -138,7 +146,7 @@ pub fn TtyWatcher(comptime Userdata: type) type { } seq_start += n; const event_inner = result.event orelse { - std.log.warn("unknown event: {s}", .{self.read_buf[seq_start - n + 1 .. seq_start]}); + log.warn("unknown event: {s}", .{self.read_buf[seq_start - n + 1 .. seq_start]}); continue :parse_loop; }; @@ -215,7 +223,9 @@ pub fn TtyWatcher(comptime Userdata: type) type { self.vx.caps.color_scheme_updates = true; }, .cap_da1 => { - self.vx.enableDetectedFeatures(self.tty.anyWriter()) catch {}; + self.vx.enableDetectedFeatures(self.tty.anyWriter()) catch |err| { + log.err("couldn't enable features: {}", .{err}); + }; }, } } @@ -229,9 +239,15 @@ pub fn TtyWatcher(comptime Userdata: type) type { _: *xev.Completion, r: xev.Async.WaitError!void, ) xev.CallbackAction { - _ = r catch @panic("TODO"); - const self = ud orelse @panic("TODO"); - const winsize = Tty.getWinsize(self.tty.fd) catch @panic("TODO"); + _ = r catch |err| { + log.err("async error: {}", .{err}); + return .disarm; + }; + const self = ud orelse unreachable; // no userdata + const winsize = Tty.getWinsize(self.tty.fd) catch |err| { + log.err("couldn't get winsize: {}", .{err}); + return .disarm; + }; return self.callback(self.ud, l, self, .{ .winsize = winsize }); } };