feat: rework header; add footer; padding for content
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 1m37s
Release Zig Application / Release zig project (release) Has been cancelled

This commit is contained in:
2025-10-30 16:28:49 +01:00
parent c07cfd5f3d
commit 5acca12abf
3 changed files with 204 additions and 30 deletions

View File

@@ -53,6 +53,89 @@ pub fn Content(App: type) type {
};
}
pub fn Title(App: type) type {
return struct {
text: []const u8,
pub fn init() @This() {
return .{
.text = "<Title>",
};
}
pub fn element(this: *@This()) App.Element {
return .{
.ptr = this,
.vtable = &.{
.content = content,
},
};
}
fn content(ctx: *anyopaque, _: *const App.Model, cells: []zterm.Cell, size: zterm.Point) !void {
const this: *const @This() = @ptrCast(@alignCast(ctx));
assert(cells.len == @as(usize, size.x) * @as(usize, size.y));
for (0.., this.text) |idx, cp| {
cells[idx].style.fg = .green;
cells[idx].style.emphasis = &.{.bold};
cells[idx].cp = cp;
// NOTE do not write over the contents of this `Container`'s `Size`
if (idx == cells.len - 1) break;
}
}
};
}
pub fn InfoBanner(App: type) type {
return struct {
left_text: []const u8,
right_text: []const u8,
pub fn init() @This() {
return .{
.left_text = "Build with zig",
.right_text = "Yves Biener (@yves-biener)",
};
}
pub fn element(this: *@This()) App.Element {
return .{
.ptr = this,
.vtable = &.{
.content = content,
},
};
}
fn content(ctx: *anyopaque, _: *const App.Model, cells: []zterm.Cell, size: zterm.Point) !void {
const this: *const @This() = @ptrCast(@alignCast(ctx));
assert(cells.len == @as(usize, size.x) * @as(usize, size.y));
for (0.., this.left_text) |idx, cp| {
// NOTE do not write over the contents of this `Container`'s `Size`
if (idx == cells.len) break;
cells[idx].style.fg = .default;
cells[idx].style.emphasis = &.{.dim};
cells[idx].cp = cp;
}
var start_idx = size.x -| this.right_text.len;
if (start_idx <= this.left_text.len) start_idx = this.left_text.len + 1;
for (start_idx.., this.right_text) |idx, cp| {
// NOTE do not write over the contents of this `Container`'s `Size`
if (idx == cells.len) break;
cells[idx].style.fg = .default;
cells[idx].style.emphasis = &.{.dim};
cells[idx].cp = cp;
}
}
};
}
const std = @import("std");
const Allocator = std.mem.Allocator;
const assert = std.debug.assert;