refactor: improve create pattern to avoid leaks
This commit is contained in:
parent
de68c1a5d4
commit
efdad96054
46 changed files with 90 additions and 30 deletions
|
@ -81,7 +81,8 @@ const Self = @This();
|
|||
|
||||
pub fn create(allocator: std.mem.Allocator, parent: Widget) !Widget {
|
||||
const logger = log.logger("home");
|
||||
const self: *Self = try allocator.create(Self);
|
||||
const self = try allocator.create(Self);
|
||||
errdefer allocator.destroy(self);
|
||||
var n = try Plane.init(&(Widget.Box{}).opts("editor"), parent.plane.*);
|
||||
errdefer n.deinit();
|
||||
|
||||
|
@ -303,6 +304,8 @@ pub fn render(self: *Self, theme: *const Widget.Theme) bool {
|
|||
self.position_menu(self.v_center(5, self.menu_len, 5), self.center(x, self.menu_w));
|
||||
}
|
||||
|
||||
if (self.plane.dim_y() < 3 or self.plane.dim_x() < root.version.len + 4) return false;
|
||||
|
||||
self.plane.cursor_move_yx(
|
||||
@intCast(self.plane.dim_y() - 2),
|
||||
@intCast(@max(self.plane.dim_x(), root.version.len + 3) - root.version.len - 3),
|
||||
|
@ -311,6 +314,7 @@ pub fn render(self: *Self, theme: *const Widget.Theme) bool {
|
|||
_ = self.plane.print("{s}", .{root.version}) catch return false;
|
||||
if (builtin.mode == .Debug) {
|
||||
const debug_warning_text = "debug build";
|
||||
if (self.plane.dim_y() < 4 or self.plane.dim_x() < debug_warning_text.len + 4) return false;
|
||||
self.plane.cursor_move_yx(
|
||||
@intCast(self.plane.dim_y() - 3),
|
||||
@intCast(@max(self.plane.dim_x(), debug_warning_text.len + 3) - debug_warning_text.len - 3),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue