refactor: Use zig fetch for termbox2 dependency

Replaced the local `termbox2.h` header file with a proper dependency managed by the Zig package manager. This improves maintainability and makes it easier to track and update the library in the future.

The previous `termbox2.h` contained a custom `tb_get_cell` function that is not present in the upstream repository. This function has been re-implemented in Zig (`src/tui/termbox_extras.zig`) to maintain compatibility, especially for the failed-login "cascade" animation.

This change also involved updating `build.zig` and `build.zig.zon` to use the new dependency.
This commit is contained in:
João Lucas 2025-07-04 08:32:49 -03:00
parent 3ad0c00380
commit 7b81336761
5 changed files with 39 additions and 4325 deletions

View File

@ -68,13 +68,17 @@ pub fn build(b: *std.Build) !void {
const clap = b.dependency("clap", .{ .target = target, .optimize = optimize }); const clap = b.dependency("clap", .{ .target = target, .optimize = optimize });
exe.root_module.addImport("clap", clap.module("clap")); exe.root_module.addImport("clap", clap.module("clap"));
exe.addIncludePath(b.path("include")); const termbox_dep = b.dependency("termbox2", .{
.target = target,
.optimize = optimize,
});
exe.linkSystemLibrary("pam"); exe.linkSystemLibrary("pam");
if (enable_x11_support) exe.linkSystemLibrary("xcb"); if (enable_x11_support) exe.linkSystemLibrary("xcb");
exe.linkLibC(); exe.linkLibC();
const translate_c = b.addTranslateC(.{ const translate_c = b.addTranslateC(.{
.root_source_file = b.path("include/termbox2.h"), .root_source_file = termbox_dep.path("termbox2.h"),
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
}); });

View File

@ -12,6 +12,10 @@
.url = "https://github.com/Kawaii-Ash/zigini/archive/2ed3d417f17fab5b0ee8cad8a63c6d62d7ac1042.tar.gz", .url = "https://github.com/Kawaii-Ash/zigini/archive/2ed3d417f17fab5b0ee8cad8a63c6d62d7ac1042.tar.gz",
.hash = "zigini-0.3.1-BSkB7XJGAAB2E-sKyzhTaQCBlYBL8yqzE4E_jmSY99sC", .hash = "zigini-0.3.1-BSkB7XJGAAB2E-sKyzhTaQCBlYBL8yqzE4E_jmSY99sC",
}, },
.termbox2 = .{
.url = "git+https://github.com/termbox/termbox2#8ee9dc17e1ca61c630f91db0aa7f81fa29a32040",
.hash = "N-V-__8AAKvjBAAUF2KVdkHsNs7L5EEZYzBnrJTBvj-baBMZ",
},
}, },
.paths = .{""}, .paths = .{""},
} }

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,7 @@ const std = @import("std");
const builtin = @import("builtin"); const builtin = @import("builtin");
const interop = @import("../interop.zig"); const interop = @import("../interop.zig");
const Cell = @import("Cell.zig"); const Cell = @import("Cell.zig");
const termbox_extras = @import("termbox_extras.zig");
const Random = std.Random; const Random = std.Random;
@ -113,8 +114,8 @@ pub fn cascade(self: TerminalBuffer) bool {
var cell: termbox.tb_cell = undefined; var cell: termbox.tb_cell = undefined;
var cell_under: termbox.tb_cell = undefined; var cell_under: termbox.tb_cell = undefined;
_ = termbox.tb_get_cell(@intCast(x), @intCast(y - 1), 1, &cell); _ = termbox_extras.tb_get_cell(@intCast(x), @intCast(y - 1), 1, &cell);
_ = termbox.tb_get_cell(@intCast(x), @intCast(y), 1, &cell_under); _ = termbox_extras.tb_get_cell(@intCast(x), @intCast(y), 1, &cell_under);
const char: u8 = @truncate(cell.ch); const char: u8 = @truncate(cell.ch);
if (std.ascii.isWhitespace(char)) continue; if (std.ascii.isWhitespace(char)) continue;

View File

@ -0,0 +1,26 @@
const std = @import("std");
const interop = @import("../interop.zig");
const termbox = interop.termbox;
pub fn tb_get_cell(x: c_int, y: c_int, back: c_int, cell: *termbox.tb_cell) c_int {
if (back == 0) {
return termbox.TB_ERR;
}
const width = termbox.tb_width();
const height = termbox.tb_height();
if (x < 0 or x >= width or y < 0 or y >= height) {
return termbox.TB_ERR_OUT_OF_BOUNDS;
}
const buffer = termbox.tb_cell_buffer();
if (buffer == null) {
return termbox.TB_ERR_NOT_INIT;
}
const index = y * width + x;
cell.* = buffer[@intCast(index)];
return termbox.TB_OK;
}