From 72b3374688bc882579c886201d610f19b51cb0d4 Mon Sep 17 00:00:00 2001 From: RadsammyT Date: Thu, 18 Jun 2026 17:25:40 -0400 Subject: [PATCH] review pt 4 --- src/animations/Lua.zig | 45 ++++++++++++++++++++++-------------------- src/main.zig | 1 + 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/animations/Lua.zig b/src/animations/Lua.zig index 5cd4704..5c71115 100644 --- a/src/animations/Lua.zig +++ b/src/animations/Lua.zig @@ -30,6 +30,7 @@ fg: u32, bg: u32, lang: Lang, +full_color: bool, lua_error: bool = false, lua_error_logged: bool = false, @@ -47,6 +48,7 @@ pub fn init( fg: u32, bg: u32, lang: Lang, + full_color: bool, ) !Lua { var self: Lua = .{ .lua = try zlua.Lua.init(alloc), @@ -63,6 +65,7 @@ pub fn init( .fg = fg, .bg = bg, .lang = lang, + .full_color = full_color, }; // exclude IO and debug libraries @@ -116,7 +119,8 @@ fn draw(self: *Lua) void { self.propagateTerminalBounds(); if (self.lua_error) { // Ly's Red Screen of Omega-Death:tm: - const cell = Cell.init(0x2588, 0x00ff0000, 0x00ff0000); + const RED: u32 = if (self.full_color) TerminalBuffer.Color.TRUE_RED else TerminalBuffer.Color.ECOL_RED; + const cell = Cell.init(0x2588, RED, RED); for (0..self.terminal_buffer.height) |y| for (0..self.terminal_buffer.width) |x| cell.put(x, y) catch {}; @@ -164,30 +168,29 @@ pub fn widget(self: *Lua) *Widget { null, self, deinit, - null, //realloc - draw, //draw - null, //update null, - calculateTimeout, //calculateTimeout + draw, + null, + null, + calculateTimeout, ); return &self.instance.?; } fn propagateTerminalBounds(self: *Lua) void { - if (self.terminal_buffer.height != self.height or - self.terminal_buffer.width != self.width) - { - self.width = self.terminal_buffer.width; - self.height = self.terminal_buffer.height; - _ = self.lua.getGlobal("ly"); - _ = self.lua.pushString("width"); - self.lua.pushInteger(@intCast(self.terminal_buffer.width)); - self.lua.setTable(-3); - _ = self.lua.pushString("height"); - self.lua.pushInteger(@intCast(self.terminal_buffer.height)); - self.lua.setTable(-3); - self.lua.setGlobal("ly"); - } + if (self.terminal_buffer.height == self.height and + self.terminal_buffer.width == self.width) + return; + self.width = self.terminal_buffer.width; + self.height = self.terminal_buffer.height; + _ = self.lua.getGlobal("ly"); + _ = self.lua.pushString("width"); + self.lua.pushInteger(@intCast(self.terminal_buffer.width)); + self.lua.setTable(-3); + _ = self.lua.pushString("height"); + self.lua.pushInteger(@intCast(self.terminal_buffer.height)); + self.lua.setTable(-3); + self.lua.setGlobal("ly"); } fn luaLyClock(state: ?*zlua.LuaState) callconv(.c) c_int { @@ -199,7 +202,7 @@ fn luaLyClock(state: ?*zlua.LuaState) callconv(.c) c_int { fn luaPutCell(state: ?*zlua.LuaState) callconv(.c) c_int { const lua: *zlua.Lua = @ptrCast(@alignCast(state orelse unreachable)); - const MSG = "ly.putCell: Cannot convert %s-typed "; + const MSG = "ly.putCell: cannot convert %s-typed "; const byte = lua.toNumeric(u32, 1) catch { const t = lua.typeName(lua.typeOf(1)); lua.raiseErrorStr(MSG ++ "byte to u32", .{t.ptr}); @@ -230,7 +233,7 @@ fn luaPutCell(state: ?*zlua.LuaState) callconv(.c) c_int { fn luaPutLabel(state: ?*zlua.LuaState) callconv(.c) c_int { const lua: *zlua.Lua = @ptrCast(@alignCast(state orelse unreachable)); - const MSG = "ly.putLabel: Cannot convert %s-typed "; + const MSG = "ly.putLabel: cannot convert %s-typed "; const str = lua.toString(1) catch { const t = lua.typeName(lua.typeOf(2)); lua.raiseErrorStr(MSG ++ "str to string", .{t.ptr}); diff --git a/src/main.zig b/src/main.zig index 487e54a..a5f40e3 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1112,6 +1112,7 @@ pub fn main(init: std.process.Init) !void { state.config.error_fg, state.config.error_bg, state.lang, + state.config.full_color, ); animation = lua.widget(); },