diff --git a/examples/main.zig b/examples/main.zig index c985fdd..0d3f43c 100644 --- a/examples/main.zig +++ b/examples/main.zig @@ -1,5 +1,6 @@ const std = @import("std"); const vaxis = @import("vaxis"); +const Cell = vaxis.Cell; const log = std.log.scoped(.main); pub fn main() !void { @@ -21,6 +22,7 @@ pub fn main() !void { try vx.enterAltScreen(); + const msg = "Hello, world!"; outer: while (true) { const event = vx.nextEvent(); log.debug("event: {}\r\n", .{event}); @@ -37,12 +39,17 @@ pub fn main() !void { } const win = vx.window(); - _ = win; + const child = win.initChild(20, 20, .expand, .expand); + for (msg, 0..) |_, i| { + const cell: Cell = .{ .char = .{ .grapheme = msg[i .. i + 1] } }; + child.writeCell(cell, i, 0); + } + try vx.render(); } } const Event = union(enum) { key_press: vaxis.Key, winsize: vaxis.Winsize, - mouse: u8, + foo: u8, }; diff --git a/src/Screen.zig b/src/Screen.zig index 2ef3da5..5c61c00 100644 --- a/src/Screen.zig +++ b/src/Screen.zig @@ -24,6 +24,9 @@ pub fn deinit(self: *Screen, alloc: std.mem.Allocator) void { pub fn resize(self: *Screen, alloc: std.mem.Allocator, w: usize, h: usize) !void { alloc.free(self.buf); self.buf = try alloc.alloc(Cell, w * h); + for (self.buf, 0..) |_, i| { + self.buf[i] = .{}; + } self.width = w; self.height = h; } diff --git a/src/Tty.zig b/src/Tty.zig index e6d48c6..5330cbc 100644 --- a/src/Tty.zig +++ b/src/Tty.zig @@ -60,7 +60,7 @@ pub fn run( // get our initial winsize const winsize = try getWinsize(self.fd); - log.debug("{}", .{winsize}); + vx.postEvent(.{ .winsize = winsize }); // assign the write end of the pipe to our quit_fd self.quit_fd = pipe[1]; diff --git a/src/Window.zig b/src/Window.zig index 3861651..b97b356 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -25,7 +25,7 @@ screen: *Screen, /// parent's size. Windows do not retain a reference to their parent and are /// unaware of resizes. pub fn initChild( - self: *Window, + self: Window, x_off: usize, y_off: usize, width: Size, @@ -60,7 +60,7 @@ pub fn initChild( /// writes a cell to the location in the window pub fn writeCell(self: Window, cell: Cell, row: usize, col: usize) void { - if (self.h < row or self.w < col) return; + if (self.height < row or self.width < col) return; self.screen.writeCell(cell, row + self.y_off, col + self.x_off); } diff --git a/src/ctlseqs.zig b/src/ctlseqs.zig index 5e2b223..6089ef3 100644 --- a/src/ctlseqs.zig +++ b/src/ctlseqs.zig @@ -9,6 +9,7 @@ pub const csi_u_push = "\x1b[>{d}u"; pub const csi_u_pop = "\x1b[