mod(memory): do not create items on the stack instead using the provided allocator
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 4m26s

This commit is contained in:
2025-01-06 21:56:04 +01:00
parent 04e1ca087f
commit c2c3f41ff3
21 changed files with 404 additions and 464 deletions

View File

@@ -30,56 +30,37 @@ pub fn main() !void {
// TODO: when not running fullscreen, the application needs to screen down accordingly to display the contents
// -> size hint how much should it use?
var layout = Layout.createFrom(layout: {
var stack = Layout.HContainer.init(allocator, .{
.{
Widget.createFrom(blk: {
var spacer = Widget.Spacer.init();
break :blk &spacer;
}),
15,
},
.{
Layout.createFrom(container: {
var container = Layout.VContainer.init(allocator, .{
.{
Widget.createFrom(blk: {
var spacer = Widget.Spacer.init();
break :blk &spacer;
}),
25,
},
.{
Widget.createFrom(blk: {
const file = try std.fs.cwd().openFile("./src/app.zig", .{});
defer file.close();
var widget = Widget.RawText.init(allocator, file);
break :blk &widget;
}),
50,
},
.{
Widget.createFrom(blk: {
var spacer = Widget.Spacer.init();
break :blk &spacer;
}),
25,
},
});
break :container &container;
}),
70,
},
.{
Widget.createFrom(blk: {
var spacer = Widget.Spacer.init();
break :blk &spacer;
}),
15,
},
});
break :layout &stack;
});
var layout = Layout.createFrom(Layout.HContainer.init(allocator, .{
.{
Widget.createFrom(Widget.Spacer.init(allocator)),
15,
},
.{
Layout.createFrom(Layout.VContainer.init(allocator, .{
.{
Widget.createFrom(Widget.Spacer.init(allocator)),
25,
},
.{
Widget.createFrom(blk: {
const file = try std.fs.cwd().openFile("./src/app.zig", .{});
defer file.close();
break :blk Widget.RawText.init(allocator, file);
}),
50,
},
.{
Widget.createFrom(Widget.Spacer.init(allocator)),
25,
},
})),
70,
},
.{
Widget.createFrom(Widget.Spacer.init(allocator)),
15,
},
}));
defer layout.deinit();
try app.start(null);

View File

@@ -31,41 +31,26 @@ pub fn main() !void {
// TODO: when not running fullscreen, the application needs to screen down accordingly to display the contents
// -> size hint how much should it use?
var layout = Layout.createFrom(layout: {
var container = Layout.VContainer.init(allocator, .{
.{
Widget.createFrom(blk: {
var spacer = Widget.Spacer.init();
break :blk &spacer;
}),
45,
},
.{
Layout.createFrom(framing: {
var framing = Layout.Framing.init(allocator, .{}, .{
.widget = Widget.createFrom(blk: {
var widget = Widget.Text.init(.center, &[_]Cell{
.{ .content = "Press " },
.{ .content = "Ctrl+n", .style = .{ .fg = .{ .index = 6 } } },
.{ .content = " to launch $EDITOR" },
});
break :blk &widget;
}),
});
break :framing &framing;
}),
10,
},
.{
Widget.createFrom(blk: {
var spacer = Widget.Spacer.init();
break :blk &spacer;
}),
45,
},
});
break :layout &container;
});
var layout = Layout.createFrom(Layout.VContainer.init(allocator, .{
.{
Widget.createFrom(Widget.Spacer.init(allocator)),
45,
},
.{
Layout.createFrom(Layout.Framing.init(allocator, .{}, .{
.widget = Widget.createFrom(Widget.Text.init(allocator, .center, &[_]Cell{
.{ .content = "Press " },
.{ .content = "Ctrl+n", .style = .{ .fg = .{ .index = 6 } } },
.{ .content = " to launch $EDITOR" },
})),
})),
10,
},
.{
Widget.createFrom(Widget.Spacer.init(allocator)),
45,
},
}));
defer layout.deinit();
const min_size: zterm.Size = .{

View File

@@ -30,54 +30,44 @@ pub fn main() !void {
// TODO: when not running fullscreen, the application needs to screen down accordingly to display the contents
// -> size hint how much should it use?
var layout = Layout.createFrom(layout: {
var padding = Layout.Padding.init(allocator, .{
.padding = 15,
}, .{
.layout = Layout.createFrom(framing: {
var framing = Layout.Framing.init(
var layout = Layout.createFrom(Layout.Padding.init(allocator, .{
.padding = 15,
}, .{
.layout = Layout.createFrom(Layout.Framing.init(
allocator,
.{
.style = .{
.fg = .{
.index = 6,
},
},
.frame = .round,
.title = .{
.str = "Content in Margin",
.style = .{
.ul_style = .single,
.ul = .{ .index = 6 },
.bold = true,
},
},
},
.{
.layout = Layout.createFrom(Layout.Margin.init(
allocator,
.{
.style = .{
.fg = .{
.index = 6,
},
},
.frame = .round,
.title = .{
.str = "Content in Margin",
.style = .{
.ul_style = .single,
.ul = .{ .index = 6 },
.bold = true,
},
},
.margin = 10,
},
.{
.layout = Layout.createFrom(margin: {
var margin = Layout.Margin.init(
allocator,
.{
.margin = 10,
},
.{
.widget = Widget.createFrom(blk: {
const file = try std.fs.cwd().openFile("./examples/padding.zig", .{});
defer file.close();
var widget = Widget.RawText.init(allocator, file);
break :blk &widget;
}),
},
);
break :margin &margin;
.widget = Widget.createFrom(blk: {
const file = try std.fs.cwd().openFile("./examples/padding.zig", .{});
defer file.close();
break :blk Widget.RawText.init(allocator, file);
}),
},
);
break :framing &framing;
}),
});
break :layout &padding;
});
)),
},
)),
}));
defer layout.deinit();
try app.start(null);

View File

@@ -30,97 +30,71 @@ pub fn main() !void {
// TODO: when not running fullscreen, the application needs to screen down accordingly to display the contents
// -> size hint how much should it use?
var layout = Layout.createFrom(layout: {
var framing = Layout.Framing.init(allocator, .{
var layout = Layout.createFrom(Layout.Framing.init(allocator, .{
.style = .{
.fg = .{
.index = 6,
},
},
.frame = .round,
.title = .{
.str = "HStack",
.style = .{
.fg = .{
.index = 6,
},
.ul_style = .single,
.ul = .{ .index = 6 },
.bold = true,
},
.frame = .round,
.title = .{
.str = "HStack",
.style = .{
.ul_style = .single,
.ul = .{ .index = 6 },
.bold = true,
},
}, .{
.layout = Layout.createFrom(Layout.HStack.init(allocator, .{
Widget.createFrom(Widget.Spacer.init(allocator)),
Layout.createFrom(Layout.Framing.init(
allocator,
.{
.style = .{
.fg = .{
.index = 6,
},
},
.frame = .round,
.title = .{
.str = "VStack",
.style = .{
.ul_style = .single,
.ul = .{ .index = 6 },
.bold = true,
},
},
},
},
}, .{
.layout = Layout.createFrom(hstack: {
var hstack = Layout.HStack.init(allocator, .{
Widget.createFrom(blk: {
var spacer = Widget.Spacer.init();
break :blk &spacer;
}),
Layout.createFrom(framing: {
var framing = Layout.Framing.init(
.{
.layout = Layout.createFrom(
Layout.Margin.init(
allocator,
.{
.style = .{
.fg = .{
.index = 6,
},
},
.frame = .round,
.title = .{
.str = "VStack",
.style = .{
.ul_style = .single,
.ul = .{ .index = 6 },
.bold = true,
},
},
.margin = 10,
},
.{
.layout = Layout.createFrom(
padding: {
var padding = Layout.Margin.init(
allocator,
.{
.margin = 10,
},
.{
.layout = Layout.createFrom(vstack: {
var vstack = Layout.VStack.init(allocator, .{
Widget.createFrom(blk: {
const file = try std.fs.cwd().openFile("./examples/stack.zig", .{});
defer file.close();
var widget = Widget.RawText.init(allocator, file);
break :blk &widget;
}),
Widget.createFrom(blk: {
var spacer = Widget.Spacer.init();
break :blk &spacer;
}),
Widget.createFrom(blk: {
const file = try std.fs.cwd().openFile("./examples/stack.zig", .{});
defer file.close();
var widget = Widget.RawText.init(allocator, file);
break :blk &widget;
}),
});
break :vstack &vstack;
}),
},
);
break :padding &padding;
},
),
.layout = Layout.createFrom(Layout.VStack.init(allocator, .{
Widget.createFrom(blk: {
const file = try std.fs.cwd().openFile("./examples/stack.zig", .{});
defer file.close();
break :blk Widget.RawText.init(allocator, file);
}),
Widget.createFrom(Widget.Spacer.init(allocator)),
Widget.createFrom(blk: {
const file = try std.fs.cwd().openFile("./examples/stack.zig", .{});
defer file.close();
break :blk Widget.RawText.init(allocator, file);
}),
})),
},
);
break :framing &framing;
}),
Widget.createFrom(blk: {
var spacer = Widget.Spacer.init();
break :blk &spacer;
}),
});
break :hstack &hstack;
}),
});
break :layout &framing;
});
),
),
},
)),
Widget.createFrom(Widget.Spacer.init(allocator)),
})),
}));
defer layout.deinit();
try app.start(null);

View File

@@ -31,62 +31,46 @@ pub fn main() !void {
// TODO: when not running fullscreen, the application needs to screen down accordingly to display the contents
// -> size hint how much should it use?
var layout = Layout.createFrom(layout: {
var tabs = Layout.Tab.init(allocator, .{}, .{
.{
Layout.createFrom(margin: {
var margin = Layout.Margin.init(allocator, .{ .margin = 10 }, .{
.widget = Widget.createFrom(blk: {
const file = try std.fs.cwd().openFile("./examples/tabs.zig", .{});
defer file.close();
var widget = Widget.RawText.init(allocator, file);
break :blk &widget;
}),
});
break :margin &margin;
var layout = Layout.createFrom(Layout.Tab.init(allocator, .{}, .{
.{
Layout.createFrom(Layout.Margin.init(allocator, .{ .margin = 10 }, .{
.widget = Widget.createFrom(blk: {
const file = try std.fs.cwd().openFile("./examples/tabs.zig", .{});
defer file.close();
break :blk Widget.RawText.init(allocator, file);
}),
"Tab 2",
Cell.Style.Color{ .index = 6 },
},
.{
Layout.createFrom(framing: {
var framing = Layout.Framing.init(
allocator,
.{
.frame = .round,
.title = .{
.str = "Content in Margin",
.style = .{
.ul_style = .single,
.ul = .{ .index = 4 },
.bold = true,
},
},
})),
"Tab 2",
Cell.Style.Color{ .index = 6 },
},
.{
Layout.createFrom(Layout.Framing.init(
allocator,
.{
.frame = .round,
.title = .{
.str = "Content in Margin",
.style = .{
.ul_style = .single,
.ul = .{ .index = 4 },
.bold = true,
},
.{
.layout = Layout.createFrom(margin: {
var margin = Layout.Margin.init(allocator, .{ .margin = 10 }, .{
.widget = Widget.createFrom(blk: {
var widget = Widget.List.init(allocator, .ordered, .{
&[_]Cell{.{ .content = "First entry" }},
&[_]Cell{.{ .content = "Second entry" }},
&[_]Cell{.{ .content = "Third entry" }},
});
break :blk &widget;
}),
});
break :margin &margin;
}),
},
);
break :framing &framing;
}),
"Tab 1",
Cell.Style.Color{ .index = 4 },
},
});
break :layout &tabs;
});
},
},
.{
.layout = Layout.createFrom(Layout.Margin.init(allocator, .{ .margin = 10 }, .{
.widget = Widget.createFrom(Widget.List.init(allocator, .ordered, .{
&[_]Cell{.{ .content = "First entry" }},
&[_]Cell{.{ .content = "Second entry" }},
&[_]Cell{.{ .content = "Third entry" }},
})),
})),
},
)),
"Tab 1",
Cell.Style.Color{ .index = 4 },
},
}));
defer layout.deinit();
try app.start(null);

View File

@@ -25,73 +25,49 @@ pub fn main() !void {
var renderer: App.Renderer = .{};
// FIXME: the layout creates an 'incorrect alignment'?
var layout = Layout.createFrom(layout: {
var layout = Layout.VContainer.init(allocator, .{
.{
Layout.createFrom(framing: {
var framing = Layout.Framing.init(allocator, .{
.title = .{
.str = "Welcome to my terminal website",
.style = .{
.ul = .{ .index = 6 },
.ul_style = .single,
},
},
}, .{
.layout = Layout.createFrom(hcontainer: {
var hcontainer = Layout.HContainer.init(allocator, .{
.{
Widget.createFrom(text: {
var text = Widget.Text.init(.left, &[1]Cell{
.{ .content = "Yves Biener", .style = .{ .bold = true } },
});
break :text &text;
}),
25,
},
.{
Widget.createFrom(text: {
var text = Widget.Text.init(.left, &[1]Cell{
.{ .content = "File name", .style = .{ .bold = true } },
});
break :text &text;
}),
50,
},
.{
Widget.createFrom(text: {
var text = Widget.Text.init(.left, &[1]Cell{
.{ .content = "Contacts", .style = .{ .bold = true } },
});
break :text &text;
}),
25,
},
});
break :hcontainer &hcontainer;
}),
});
break :framing &framing;
}),
10,
},
.{
Layout.createFrom(margin: {
var margin = Layout.Margin.init(allocator, .{ .left = 15, .right = 15 }, .{
.widget = Widget.createFrom(text: {
var text = Widget.Text.init(.default, &[1]Cell{
.{ .content = "Does this change anything", .style = .{ .ul = .default, .ul_style = .single } },
});
break :text &text;
}),
});
break :margin &margin;
}),
90,
},
});
break :layout &layout;
});
var layout = Layout.createFrom(Layout.VContainer.init(allocator, .{
.{
Layout.createFrom(Layout.Framing.init(allocator, .{
.title = .{
.str = "Welcome to my terminal website",
.style = .{
.ul = .{ .index = 6 },
.ul_style = .single,
},
},
}, .{
.layout = Layout.createFrom(Layout.HContainer.init(allocator, .{
.{
Widget.createFrom(Widget.Text.init(allocator, .left, &[1]Cell{
.{ .content = "Yves Biener", .style = .{ .bold = true } },
})),
25,
},
.{
Widget.createFrom(Widget.Text.init(allocator, .left, &[1]Cell{
.{ .content = "File name", .style = .{ .bold = true } },
})),
50,
},
.{
Widget.createFrom(Widget.Text.init(allocator, .left, &[1]Cell{
.{ .content = "Contacts", .style = .{ .bold = true } },
})),
25,
},
})),
})),
10,
},
.{
Layout.createFrom(Layout.Margin.init(allocator, .{ .left = 15, .right = 15 }, .{
.widget = Widget.createFrom(Widget.Text.init(allocator, .default, &[1]Cell{
.{ .content = "Does this change anything", .style = .{ .ul = .default, .ul_style = .single } },
})),
})),
90,
},
}));
defer layout.deinit();
try app.start(null);