diff --git a/build.zig b/build.zig index e60c15a..33f1ea1 100644 --- a/build.zig +++ b/build.zig @@ -20,7 +20,7 @@ pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ .name = "vaxis", - .root_source_file = .{ .path = "examples/text_input.zig" }, + .root_source_file = .{ .path = "examples/pathological.zig" }, .target = target, .optimize = optimize, }); diff --git a/build.zig.zon b/build.zig.zon index cf4b97a..1a56789 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -2,7 +2,7 @@ .name = "vaxis", // This is a [Semantic Version](https://semver.org/). // In a future version of Zig it will be used for package deduplication. - .version = "0.0.0", + .version = "0.1.0", // This field is optional. // This is currently advisory only; Zig does not yet do anything diff --git a/examples/pathological.zig b/examples/pathological.zig new file mode 100644 index 0000000..3b1a073 --- /dev/null +++ b/examples/pathological.zig @@ -0,0 +1,58 @@ +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(); + var vx = try vaxis.init(Event, .{}); + errdefer vx.deinit(alloc); + + try vx.startReadThread(); + defer vx.stopReadThread(); + try vx.enterAltScreen(); + try vx.queryTerminal(); + + outer: while (true) { + const event = vx.nextEvent(); + switch (event) { + .winsize => |ws| { + try vx.resize(alloc, ws); + break :outer; + }, + } + } + + 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(); + } + const took = std.time.microTimestamp() - timer_start; + vx.deinit(alloc); + log.info("took {d}ms", .{@divTrunc(took, std.time.us_per_ms)}); +}