Handle termbox2 errors

Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
AnErrupTion
2026-05-17 13:26:46 +02:00
parent 05c1d4bece
commit 4c066ce564
17 changed files with 114 additions and 90 deletions

View File

@@ -71,14 +71,14 @@ fn draw(self: *Cascade) void {
if ((self.buffer.random.int(u16) % 10) > 7) continue;
cell.?.put(x, y);
cell.?.put(x, y) catch {};
var space = Cell.init(
' ',
cell_under.?.fg,
cell_under.?.bg,
);
space.put(x, y - 1);
space.put(x, y - 1) catch {};
}
}
@@ -87,6 +87,6 @@ fn draw(self: *Cascade) void {
self.current_auth_fails.* = 0;
}
TerminalBuffer.presentBuffer();
TerminalBuffer.presentBuffer() catch {};
}
}

View File

@@ -114,7 +114,7 @@ fn draw(self: *ColorMix) void {
}
const cell = self.palette[@as(usize, @trunc(math.floor(length(uv) * 5.0))) % palette_len];
cell.put(x, y);
cell.put(x, y) catch {};
}
}
}

View File

@@ -129,13 +129,13 @@ fn draw(self: *Doom) void {
// Send known fire levels to terminal buffer
const from_cell = self.fire[level_buf_from];
const to_cell = self.fire[level_buf_to];
from_cell.put(x, y);
to_cell.put(to_x, to_y);
from_cell.put(x, y) catch {};
to_cell.put(to_x, to_y) catch {};
}
// Draw bottom line (fire source)
const src_cell = self.fire[STEPS];
src_cell.put(x, self.terminal_buffer.height - 1);
src_cell.put(x, self.terminal_buffer.height - 1) catch {};
}
}

View File

@@ -535,7 +535,7 @@ fn draw(self: *DurFile) void {
const cell = Cell{ .ch = @intCast(codepoint), .fg = fg_color, .bg = bg_color };
self.terminal_buffer.setCellBoundsChecked(cell_x, cell_y, cell);
self.terminal_buffer.setCellBoundsChecked(cell_x, cell_y, cell) catch {};
}
}

View File

@@ -146,7 +146,7 @@ fn draw(self: *GameOfLife) void {
const row_offset = y * self.width;
for (0..self.width) |x| {
const cell = if (self.current_grid[row_offset + x]) alive_cell else self.dead_cell;
cell.put(x, y);
cell.put(x, y) catch {};
}
}
}

View File

@@ -200,9 +200,9 @@ fn draw(self: *Matrix) void {
.bg = self.terminal_buffer.bg,
};
cell.put(x, y - 1);
cell.put(x, y - 1) catch {};
// Fill background in between columns
self.default_cell.put(x + 1, y - 1);
self.default_cell.put(x + 1, y - 1) catch {};
}
}
}

View File

@@ -84,7 +84,7 @@ pub fn clearRendered(self: InfoLine, allocator: Allocator) !void {
@memset(spaces, ' ');
TerminalBuffer.drawText(
try TerminalBuffer.drawText(
spaces,
self.label.component_pos.x + 2,
self.label.component_pos.y,
@@ -98,7 +98,7 @@ fn draw(self: *InfoLine) void {
}
fn handle(self: *InfoLine, maybe_key: ?keyboard.Key) !void {
self.label.handle(maybe_key);
try self.label.handle(maybe_key);
}
fn drawItem(label: *MessageLabel, message: Message, x: usize, y: usize, width: usize) void {
@@ -114,5 +114,5 @@ fn drawItem(label: *MessageLabel, message: Message, x: usize, y: usize, width: u
width,
message.fg,
message.bg,
);
) catch {};
}

View File

@@ -87,7 +87,7 @@ fn draw(self: *Session) void {
}
fn handle(self: *Session, maybe_key: ?keyboard.Key) !void {
self.label.handle(maybe_key);
try self.label.handle(maybe_key);
}
fn addedSession(env: Env, user_list: *UserList) void {
@@ -119,5 +119,5 @@ fn drawItem(label: *EnvironmentLabel, env: Env, x: usize, y: usize, width: usize
width,
label.fg,
label.bg,
);
) catch {};
}

View File

@@ -118,7 +118,7 @@ fn draw(self: *UserList) void {
}
fn handle(self: *UserList, maybe_key: ?keyboard.Key) !void {
self.label.handle(maybe_key);
try self.label.handle(maybe_key);
}
fn usernameChanged(user: User, maybe_session: ?*Session) void {
@@ -143,5 +143,5 @@ fn drawItem(label: *UserLabel, user: User, x: usize, y: usize, width: usize) voi
width,
label.fg,
label.bg,
);
) catch {};
}

View File

@@ -56,12 +56,12 @@ fn signalHandler(sig: std.posix.SIG) callconv(.c) void {
_ = std.c.waitpid(session_pid, &status, 0);
}
TerminalBuffer.shutdown();
TerminalBuffer.shutdown() catch {};
std.c.exit(@intCast(@intFromEnum(sig)));
}
fn ttyControlTransferSignalHandler(_: std.posix.SIG) callconv(.c) void {
TerminalBuffer.shutdown();
TerminalBuffer.shutdown() catch {};
}
const CustomBindLabel = struct {
@@ -1484,7 +1484,7 @@ fn authenticate(ptr: *anyopaque) !bool {
);
};
state.info_line.label.draw();
TerminalBuffer.presentBuffer();
try TerminalBuffer.presentBuffer();
return false;
}
@@ -1507,7 +1507,7 @@ fn authenticate(ptr: *anyopaque) !bool {
);
};
state.info_line.label.draw();
TerminalBuffer.presentBuffer();
try TerminalBuffer.presentBuffer();
if (state.config.save) save_last_settings: {
// It isn't worth cluttering the code with precise error
@@ -1660,8 +1660,8 @@ fn authenticate(ptr: *anyopaque) !bool {
}
// Restore the cursor
TerminalBuffer.setCursor(0, 0);
TerminalBuffer.presentBuffer();
try TerminalBuffer.setCursor(0, 0);
try TerminalBuffer.presentBuffer();
return false;
}