mod: simplify Container and Element creation with updated zterm behavior
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 1m9s

This commit is contained in:
2025-11-27 21:23:36 +01:00
parent da9e4c89f3
commit 1485385735
3 changed files with 49 additions and 8 deletions

View File

@@ -28,22 +28,31 @@ pub fn main() !void {
// skip own executable name // skip own executable name
_ = arg_it.skip(); _ = arg_it.skip();
} }
// tui creation
errdefer |err| log.err("Application Error: {any}", .{err});
var threaded_io: std.Io.Threaded = .init(allocator); var threaded_io: std.Io.Threaded = .init(allocator);
errdefer threaded_io.deinit(); errdefer threaded_io.deinit();
const io = threaded_io.io(); const io = threaded_io.io();
errdefer |err| log.err("Application Error: {any}", .{err});
var renderer = zterm.Renderer.Buffered.init(allocator); var renderer = zterm.Renderer.Buffered.init(allocator);
defer renderer.deinit(); defer renderer.deinit();
var app: App = .init(io, .init); var app: App = .init(io, .init);
var root = try tui_diff.Container(App, allocator); var element_root: tui_diff.elements.Root(App) = .init;
var element_tree: tui_diff.elements.Tree(App) = .init;
var changes: [3]tui_diff.elements.Change(App) = @splat(.init);
var scrollable_diffs = try tui_diff.elements.Diff(App, allocator, &changes);
// NOTE scrollable should provide deinit function (*zterm*)
// -> `Container` of `Scrollable` does not pass through the `minSize` request to its children!
var root = try tui_diff.Container(App, allocator, &element_root, &element_tree, &scrollable_diffs);
defer root.deinit(); // also de-initializes the children defer root.deinit(); // also de-initializes the children
try app.start(); try app.start();
defer app.stop() catch |err| log.err("Failed to stop application: {any}", .{err}); defer app.stop() catch |err| log.err("Failed to stop application: {any}", .{err});
// defer app.model.deinit();
// event loop // event loop
loop: while (true) { loop: while (true) {

View File

@@ -1,9 +1,32 @@
//! Model of the `zterm` application. //! Model of the `zterm` application.
// TODO planned features: // TODO planned features:
// - create change sets (i.e. parse diff headers and provide contents) is the multiarray that what I need?
// - create `elements.Change` structs which each point to every change associated to a given file (for each file)
// FIX known issues: // FIX known issues:
const Model = @This(); content: []const u8,
changes: std.MultiArrayList(Change) = .empty,
render_mode: enum {
side_by_side,
stacked,
} = .stacked,
pub const init: @This() = .{}; // TODO alloc-free parsing? (similar to how I've implemented the parser for `smd`?)
pub const init: Model = .{
.content = &.{},
};
pub const Index = struct {
idx: usize,
len: usize,
};
pub const Change = struct {
file: Index,
diff: Index,
};
const Model = @This();
const std = @import("std");

View File

@@ -6,15 +6,24 @@
pub const Event = union(enum) {}; pub const Event = union(enum) {};
pub fn Container(App: type, gpa: Allocator) !App.Container { pub fn Container(App: type, gpa: Allocator, element: *elements.Root(App), tree: *elements.Tree(App), diffs: *App.Scrollable) !App.Container {
// TODO create container structure var root: App.Container = try .init(gpa, .{
// -> might require some additional arguments .layout = .{
return try .init(gpa, .{}, .{}); .direction = .horizontal,
.separator = .{
.enabled = true,
},
},
}, element.element());
try root.append(try .init(gpa, .{}, tree.element()));
try root.append(try .init(gpa, .{}, diffs.element()));
return root;
} }
const std = @import("std"); const std = @import("std");
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
pub const elements = @import("elements.zig");
pub const Model = @import("model.zig"); pub const Model = @import("model.zig");
test { test {