Compare commits

...

2 Commits

Author SHA1 Message Date
1485385735 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
2025-11-27 21:23:36 +01:00
da9e4c89f3 mod: bump zterm dependency 2025-11-27 21:23:11 +01:00
4 changed files with 51 additions and 10 deletions

View File

@@ -3,8 +3,8 @@
.version = "0.0.1",
.dependencies = .{
.zterm = .{
.url = "git+https://gitea.yves-biener.de/yves-biener/zterm#9488d0b64da0f202943f92ac75808db0c352ec90",
.hash = "zterm-0.3.0-1xmmEKIcHACcXhEe66UhQk9TA2uf79ZnmpcPxAh6AY8s",
.url = "git+https://gitea.yves-biener.de/yves-biener/zterm#855594a8c836723f0230bfd6ad24f47613a147b1",
.hash = "zterm-0.3.0-1xmmEM8eHAB0cA7KLXGC7C8Nt7YEJcyoTme4domF1Yty",
},
},
.minimum_zig_version = "0.16.0-dev.1254+bf15c791f",

View File

@@ -28,22 +28,31 @@ pub fn main() !void {
// skip own executable name
_ = arg_it.skip();
}
// tui creation
errdefer |err| log.err("Application Error: {any}", .{err});
var threaded_io: std.Io.Threaded = .init(allocator);
errdefer threaded_io.deinit();
const io = threaded_io.io();
errdefer |err| log.err("Application Error: {any}", .{err});
var renderer = zterm.Renderer.Buffered.init(allocator);
defer renderer.deinit();
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
try app.start();
defer app.stop() catch |err| log.err("Failed to stop application: {any}", .{err});
// defer app.model.deinit();
// event loop
loop: while (true) {

View File

@@ -1,9 +1,32 @@
//! Model of the `zterm` application.
// 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:
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 fn Container(App: type, gpa: Allocator) !App.Container {
// TODO create container structure
// -> might require some additional arguments
return try .init(gpa, .{}, .{});
pub fn Container(App: type, gpa: Allocator, element: *elements.Root(App), tree: *elements.Tree(App), diffs: *App.Scrollable) !App.Container {
var root: App.Container = try .init(gpa, .{
.layout = .{
.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 Allocator = std.mem.Allocator;
pub const elements = @import("elements.zig");
pub const Model = @import("model.zig");
test {