mirror of
https://codeberg.org/fairyglade/ly.git
synced 2026-08-22 05:24:24 +02:00
review pt 4
This commit is contained in:
parent
d2d7a55e1a
commit
72b3374688
2 changed files with 25 additions and 21 deletions
|
|
@ -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});
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue