mod(benchmark): correct size and provide documentation

This commit is contained in:
2024-11-09 01:33:06 +01:00
parent 817d818d4c
commit 9d711ea047
3 changed files with 32 additions and 7 deletions

View File

@@ -4,6 +4,17 @@ This is my terminal based website. It is served as a tui application via ssh and
It contains information about me and my projects as well as blog entries about something I feel like writing something about. It contains information about me and my projects as well as blog entries about something I feel like writing something about.
## Terminal User Interface
### Benchmark
```sh
zig build -Dbenchmark run 2> log
```
_Press any button_ at the end of the benchmark (when you are back to the original screen). `log` now contains the frame
delay for each frame in each line of the output.
## Open tasks ## Open tasks
- [ ] Improve navigation - [ ] Improve navigation

View File

@@ -31,12 +31,24 @@ pub fn Layout(comptime Event: type) type {
} }
pub fn handle(this: *@This(), event: Event) !*Events { pub fn handle(this: *@This(), event: Event) !*Events {
switch (event) {
else => {},
}
this.events.clearRetainingCapacity(); this.events.clearRetainingCapacity();
if (this.widget.handle(event)) |e| { switch (event) {
try this.events.append(e); .resize => |size| {
const widget_event: Event = .{
.resize = .{
.cols = size.cols,
.rows = size.rows -| 2, // remove top and bottom rows
},
};
if (this.widget.handle(widget_event)) |e| {
try this.events.append(e);
}
},
else => {
if (this.widget.handle(event)) |e| {
try this.events.append(e);
}
},
} }
return &this.events; return &this.events;
} }
@@ -44,7 +56,9 @@ pub fn Layout(comptime Event: type) type {
pub fn content(this: *@This()) !*std.ArrayList(u8) { pub fn content(this: *@This()) !*std.ArrayList(u8) {
const widget_content = try this.widget.content(); const widget_content = try this.widget.content();
this.c.clearRetainingCapacity(); this.c.clearRetainingCapacity();
try this.c.appendSlice("\n");
try this.c.appendSlice(widget_content); try this.c.appendSlice(widget_content);
try this.c.appendSlice("\n");
return &this.c; return &this.c;
} }
}; };

View File

@@ -43,7 +43,7 @@ pub fn main() !void {
var instants: std.ArrayList(u64) = undefined; var instants: std.ArrayList(u64) = undefined;
var benchmark_thread: std.Thread = undefined; var benchmark_thread: std.Thread = undefined;
if (comptime build_options.benchmark) { if (comptime build_options.benchmark) {
instants = try std.ArrayList(u64).initCapacity(allocator, 512); instants = try std.ArrayList(u64).initCapacity(allocator, 1024);
benchmark_thread = try std.Thread.spawn(.{}, benchmark, .{&app}); benchmark_thread = try std.Thread.spawn(.{}, benchmark, .{&app});
} }
@@ -110,7 +110,7 @@ pub fn main() !void {
fn benchmark(app: *App) void { fn benchmark(app: *App) void {
std.time.sleep(1 * std.time.ns_per_s); std.time.sleep(1 * std.time.ns_per_s);
for (0..511) |_| { for (0..512) |_| {
app.postEvent(.{ .key = .{ .cp = 'j' } }); app.postEvent(.{ .key = .{ .cp = 'j' } });
app.postEvent(.{ .key = .{ .cp = 'k' } }); app.postEvent(.{ .key = .{ .cp = 'k' } });
} }