2024-02-09 19:27:22 +01:00
|
|
|
const std = @import("std");
|
|
|
|
const vaxis = @import("vaxis");
|
|
|
|
const Cell = vaxis.Cell;
|
|
|
|
|
|
|
|
const log = std.log.scoped(.main);
|
|
|
|
|
|
|
|
const Event = union(enum) {
|
|
|
|
winsize: vaxis.Winsize,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub fn main() !void {
|
|
|
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
|
|
|
const alloc = gpa.allocator();
|
2024-04-30 00:03:54 +02:00
|
|
|
var vx = try vaxis.init(alloc, .{});
|
2024-04-30 19:57:29 +02:00
|
|
|
defer vx.deinit(alloc);
|
2024-02-09 19:27:22 +01:00
|
|
|
|
2024-04-29 19:35:02 +02:00
|
|
|
var loop: vaxis.Loop(Event) = .{ .vaxis = &vx };
|
|
|
|
|
|
|
|
try loop.run();
|
|
|
|
defer loop.stop();
|
2024-02-09 19:27:22 +01:00
|
|
|
try vx.enterAltScreen();
|
|
|
|
try vx.queryTerminal();
|
|
|
|
|
2024-02-11 19:59:33 +01:00
|
|
|
while (true) {
|
2024-04-29 19:35:02 +02:00
|
|
|
const event = loop.nextEvent();
|
2024-02-09 19:27:22 +01:00
|
|
|
switch (event) {
|
|
|
|
.winsize => |ws| {
|
|
|
|
try vx.resize(alloc, ws);
|
2024-02-11 19:59:33 +01:00
|
|
|
break;
|
2024-02-09 19:27:22 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const timer_start = std.time.microTimestamp();
|
|
|
|
var iter: usize = 0;
|
|
|
|
while (iter < 10_000) : (iter += 1) {
|
|
|
|
const win = vx.window();
|
|
|
|
const child = win.initChild(0, 0, .{ .limit = 20 }, .{ .limit = 20 });
|
|
|
|
win.clear();
|
|
|
|
var row: usize = 0;
|
|
|
|
while (row < child.height) : (row += 1) {
|
|
|
|
var col: usize = 0;
|
|
|
|
while (col < child.width) : (col += 1) {
|
|
|
|
child.writeCell(col, row, .{
|
|
|
|
.char = .{
|
|
|
|
.grapheme = " ",
|
|
|
|
.width = 1,
|
|
|
|
},
|
|
|
|
.style = .{
|
|
|
|
.bg = .{ .index = @truncate(col + iter) },
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try vx.render();
|
|
|
|
}
|
2024-04-30 19:57:29 +02:00
|
|
|
try vx.exitAltScreen();
|
2024-02-09 19:27:22 +01:00
|
|
|
const took = std.time.microTimestamp() - timer_start;
|
2024-04-30 19:57:29 +02:00
|
|
|
const stdout = std.io.getStdOut().writer();
|
|
|
|
try stdout.print("\r\ntook {d}ms to render 10,000 times\r\n", .{@divTrunc(took, std.time.us_per_ms)});
|
2024-02-09 19:27:22 +01:00
|
|
|
}
|