add(example): input with simple text field
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 1m41s

This commit is contained in:
2025-02-20 23:48:57 +01:00
parent 07e932741c
commit c4639bf4bb
3 changed files with 148 additions and 16 deletions

View File

@@ -5,7 +5,7 @@ const App = zterm.App(union(enum) {
send: []u21,
});
const log = std.log.scoped(.example);
const log = std.log.scoped(.default);
pub const InputField = struct {
// TODO: I would need the following features:
@@ -67,10 +67,6 @@ pub const InputField = struct {
for (this.input.items, 0..) |cp, idx| {
cells[(row * size.cols) + col + idx].style.fg = .black;
cells[(row * size.cols) + col + idx].cp = cp;
// NOTE: line wrapping happens automatically due to the way the container cells are constructed
// - it would also be possible to limit the line to cols you want to display (i.e. then only for a single row)
// - for areas you would rather go ahead and create another
// container and fit the text inside of that container (so it is dynamic to the screen size, etc.)
// NOTE: do not write over the contents of this `Container`'s `Size`
if ((row * size.cols) + col + idx == cells.len - 1) break;
@@ -83,12 +79,9 @@ pub fn main() !void {
// TODO: maybe create own allocator as some sort of arena allocator to have consistent memory usage
var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
defer {
const deinit_status = gpa.deinit();
if (deinit_status == .leak) {
log.err("memory leak", .{});
}
}
defer if (gpa.deinit() == .leak) {
log.err("memory leak", .{});
};
const allocator = gpa.allocator();
var app: App = .init;