From f988bd334b3894141053b64deacea792b4f18dce Mon Sep 17 00:00:00 2001 From: AnErrupTion Date: Fri, 29 Aug 2025 00:45:28 +0200 Subject: [PATCH] Update termbox2 Signed-off-by: AnErrupTion --- build.zig.zon | 4 ++-- src/tui/TerminalBuffer.zig | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/build.zig.zon b/build.zig.zon index dad2165..138fbda 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -13,8 +13,8 @@ .hash = "zigini-0.3.2-BSkB7aVHAADhxwo0aEdWtNzaVXer3d8RwXMuZd-q-spO", }, .termbox2 = .{ - .url = "git+https://github.com/AnErrupTion/termbox2?ref=get_cell#e975d250ee6567773400e9d5b0b5c2f175349c57", - .hash = "N-V-__8AAMruBACJ7xT-O64hnS7lNeTiZQMketHdkHKrR1A8", + .url = "git+https://github.com/AnErrupTion/termbox2?ref=master#290ac6b8225aacfd16851224682b851b65fcb918", + .hash = "N-V-__8AAGcUBQAa5vov1Yi_9AXEffFQ1e2KsXaK4dgygRKq", }, }, .paths = .{""}, diff --git a/src/tui/TerminalBuffer.zig b/src/tui/TerminalBuffer.zig index c5e15d9..f09877d 100644 --- a/src/tui/TerminalBuffer.zig +++ b/src/tui/TerminalBuffer.zig @@ -117,24 +117,28 @@ pub fn cascade(self: TerminalBuffer) bool { while (y > 0) : (y -= 1) { for (0..self.width) |x| { - var cell: termbox.tb_cell = undefined; - var cell_under: termbox.tb_cell = undefined; + var cell: ?*termbox.tb_cell = undefined; + var cell_under: ?*termbox.tb_cell = undefined; _ = termbox.tb_get_cell(@intCast(x), @intCast(y - 1), 1, &cell); _ = termbox.tb_get_cell(@intCast(x), @intCast(y), 1, &cell_under); - const char: u8 = @truncate(cell.ch); + // This shouldn't happen under normal circumstances, but because + // this is a *secret* animation, there's no need to care that much + if (cell == null or cell_under == null) continue; + + const char: u8 = @truncate(cell.?.ch); if (std.ascii.isWhitespace(char)) continue; - const char_under: u8 = @truncate(cell_under.ch); + const char_under: u8 = @truncate(cell_under.?.ch); if (!std.ascii.isWhitespace(char_under)) continue; changed = true; if ((self.random.int(u16) % 10) > 7) continue; - _ = termbox.tb_set_cell(@intCast(x), @intCast(y), cell.ch, cell.fg, cell.bg); - _ = termbox.tb_set_cell(@intCast(x), @intCast(y - 1), ' ', cell_under.fg, cell_under.bg); + _ = termbox.tb_set_cell(@intCast(x), @intCast(y), cell.?.ch, cell.?.fg, cell.?.bg); + _ = termbox.tb_set_cell(@intCast(x), @intCast(y - 1), ' ', cell_under.?.fg, cell_under.?.bg); } }