+1
-1
build.zig
+1
-1
build.zig
+1
-1
build.zig.zon
+1
-1
build.zig.zon
···
2
2
.name = "vaxis",
3
3
// This is a [Semantic Version](https://semver.org/).
4
4
// In a future version of Zig it will be used for package deduplication.
5
-
.version = "0.0.0",
5
+
.version = "0.1.0",
6
6
7
7
// This field is optional.
8
8
// This is currently advisory only; Zig does not yet do anything
+58
examples/pathological.zig
+58
examples/pathological.zig
···
1
+
const std = @import("std");
2
+
const vaxis = @import("vaxis");
3
+
const Cell = vaxis.Cell;
4
+
5
+
const log = std.log.scoped(.main);
6
+
7
+
const Event = union(enum) {
8
+
winsize: vaxis.Winsize,
9
+
};
10
+
11
+
pub fn main() !void {
12
+
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
13
+
const alloc = gpa.allocator();
14
+
var vx = try vaxis.init(Event, .{});
15
+
errdefer vx.deinit(alloc);
16
+
17
+
try vx.startReadThread();
18
+
defer vx.stopReadThread();
19
+
try vx.enterAltScreen();
20
+
try vx.queryTerminal();
21
+
22
+
outer: while (true) {
23
+
const event = vx.nextEvent();
24
+
switch (event) {
25
+
.winsize => |ws| {
26
+
try vx.resize(alloc, ws);
27
+
break :outer;
28
+
},
29
+
}
30
+
}
31
+
32
+
const timer_start = std.time.microTimestamp();
33
+
var iter: usize = 0;
34
+
while (iter < 10_000) : (iter += 1) {
35
+
const win = vx.window();
36
+
const child = win.initChild(0, 0, .{ .limit = 20 }, .{ .limit = 20 });
37
+
win.clear();
38
+
var row: usize = 0;
39
+
while (row < child.height) : (row += 1) {
40
+
var col: usize = 0;
41
+
while (col < child.width) : (col += 1) {
42
+
child.writeCell(col, row, .{
43
+
.char = .{
44
+
.grapheme = " ",
45
+
.width = 1,
46
+
},
47
+
.style = .{
48
+
.bg = .{ .index = @truncate(col + iter) },
49
+
},
50
+
});
51
+
}
52
+
}
53
+
try vx.render();
54
+
}
55
+
const took = std.time.microTimestamp() - timer_start;
56
+
vx.deinit(alloc);
57
+
log.info("took {d}ms", .{@divTrunc(took, std.time.us_per_ms)});
58
+
}