feat: rework header; add footer; padding for content
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user