refactor: change a -> allocator
This commit is contained in:
parent
ad58b1868d
commit
7b812d73ea
63 changed files with 896 additions and 896 deletions
|
@ -9,13 +9,13 @@ const Self = @This();
|
|||
|
||||
pub const Style = enum { none, grip };
|
||||
|
||||
pub fn create(a: std.mem.Allocator, parent: Widget, config: []const u8, style: Style, event_handler: ?Widget.EventHandler) !Widget {
|
||||
var w = try WidgetList.createH(a, parent, "statusbar", .{ .static = 1 });
|
||||
pub fn create(allocator: std.mem.Allocator, parent: Widget, config: []const u8, style: Style, event_handler: ?Widget.EventHandler) !Widget {
|
||||
var w = try WidgetList.createH(allocator, parent, "statusbar", .{ .static = 1 });
|
||||
if (style == .grip) w.after_render = render_grip;
|
||||
w.ctx = w;
|
||||
var it = std.mem.splitScalar(u8, config, ' ');
|
||||
while (it.next()) |widget_name|
|
||||
try w.add(try status_widget.create(widget_name, a, w.plane, event_handler) orelse continue);
|
||||
try w.add(try status_widget.create(widget_name, allocator, w.plane, event_handler) orelse continue);
|
||||
return w.widget();
|
||||
}
|
||||
|
||||
|
|
|
@ -12,8 +12,8 @@ const Self = @This();
|
|||
|
||||
pub fn Create(comptime layout_: Widget.Layout) @import("widget.zig").CreateFunction {
|
||||
return struct {
|
||||
fn create(a: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
|
||||
const self: *Self = try a.create(Self);
|
||||
fn create(allocator: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
|
||||
const self: *Self = try allocator.create(Self);
|
||||
self.* = .{
|
||||
.plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent),
|
||||
.layout = layout_,
|
||||
|
@ -24,9 +24,9 @@ pub fn Create(comptime layout_: Widget.Layout) @import("widget.zig").CreateFunct
|
|||
}.create;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Self, a: std.mem.Allocator) void {
|
||||
pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
|
||||
self.plane.deinit();
|
||||
a.destroy(self);
|
||||
allocator.destroy(self);
|
||||
}
|
||||
|
||||
pub fn layout(self: *Self) Widget.Layout {
|
||||
|
|
|
@ -26,22 +26,22 @@ const Level = enum {
|
|||
err,
|
||||
};
|
||||
|
||||
pub fn create(a: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
|
||||
var env = std.process.getEnvMap(a) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
||||
pub fn create(allocator: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
|
||||
var env = std.process.getEnvMap(allocator) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
||||
defer env.deinit();
|
||||
const self: *Self = try a.create(Self);
|
||||
const self: *Self = try allocator.create(Self);
|
||||
self.* = .{
|
||||
.allocator = a,
|
||||
.allocator = allocator,
|
||||
.plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent),
|
||||
.on_event = event_handler,
|
||||
.tz = zeit.local(a, &env) catch |e| return tp.exit_error(e, @errorReturnTrace()),
|
||||
.tz = zeit.local(allocator, &env) catch |e| return tp.exit_error(e, @errorReturnTrace()),
|
||||
};
|
||||
try tui.current().message_filters.add(MessageFilter.bind(self, receive_tick));
|
||||
self.update_tick_timer(.init);
|
||||
return Widget.to(self);
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Self, a: std.mem.Allocator) void {
|
||||
pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
|
||||
tui.current().message_filters.remove_ptr(self);
|
||||
if (self.tick_timer) |*t| {
|
||||
t.cancel() catch {};
|
||||
|
@ -50,7 +50,7 @@ pub fn deinit(self: *Self, a: std.mem.Allocator) void {
|
|||
}
|
||||
self.tz.deinit();
|
||||
self.plane.deinit();
|
||||
a.destroy(self);
|
||||
allocator.destroy(self);
|
||||
}
|
||||
|
||||
pub fn receive(self: *Self, from: tp.pid_ref, m: tp.message) error{Exit}!bool {
|
||||
|
|
|
@ -19,8 +19,8 @@ rendered: [:0]const u8 = "",
|
|||
|
||||
const Self = @This();
|
||||
|
||||
pub fn create(a: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
|
||||
return Button.create_widget(Self, a, parent, .{
|
||||
pub fn create(allocator: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
|
||||
return Button.create_widget(Self, allocator, parent, .{
|
||||
.ctx = .{},
|
||||
.label = "",
|
||||
.on_click = on_click,
|
||||
|
|
|
@ -13,7 +13,7 @@ const Button = @import("../Button.zig");
|
|||
const command = @import("../command.zig");
|
||||
const tui = @import("../tui.zig");
|
||||
|
||||
a: Allocator,
|
||||
allocator: Allocator,
|
||||
name: []const u8,
|
||||
name_buf: [512]u8 = undefined,
|
||||
previous_title: []const u8 = "",
|
||||
|
@ -34,10 +34,10 @@ file: bool = false,
|
|||
const project_icon = "";
|
||||
const Self = @This();
|
||||
|
||||
pub fn create(a: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
|
||||
const btn = try Button.create(Self, a, parent, .{
|
||||
pub fn create(allocator: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
|
||||
const btn = try Button.create(Self, allocator, parent, .{
|
||||
.ctx = .{
|
||||
.a = a,
|
||||
.allocator = allocator,
|
||||
.name = "",
|
||||
.file_type = "",
|
||||
.lines = 0,
|
||||
|
|
|
@ -31,10 +31,10 @@ const Self = @This();
|
|||
const idle_msg = "🐶";
|
||||
pub const width = idle_msg.len + 20;
|
||||
|
||||
pub fn create(a: Allocator, parent: Plane, _: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
|
||||
pub fn create(allocator: Allocator, parent: Plane, _: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
|
||||
var frame_rate = tp.env.get().num("frame-rate");
|
||||
if (frame_rate == 0) frame_rate = 60;
|
||||
const self: *Self = try a.create(Self);
|
||||
const self: *Self = try allocator.create(Self);
|
||||
self.* = .{
|
||||
.plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent),
|
||||
.wipe_after_frames = @divTrunc(frame_rate, 2),
|
||||
|
@ -47,10 +47,10 @@ pub fn widget(self: *Self) Widget {
|
|||
return Widget.to(self);
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Self, a: Allocator) void {
|
||||
pub fn deinit(self: *Self, allocator: Allocator) void {
|
||||
tui.current().input_listeners.remove_ptr(self);
|
||||
self.plane.deinit();
|
||||
a.destroy(self);
|
||||
allocator.destroy(self);
|
||||
}
|
||||
|
||||
pub fn layout(_: *Self) Widget.Layout {
|
||||
|
|
|
@ -18,8 +18,8 @@ rendered: [:0]const u8 = "",
|
|||
|
||||
const Self = @This();
|
||||
|
||||
pub fn create(a: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
|
||||
return Button.create_widget(Self, a, parent, .{
|
||||
pub fn create(allocator: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
|
||||
return Button.create_widget(Self, allocator, parent, .{
|
||||
.ctx = .{},
|
||||
.label = "",
|
||||
.on_click = on_click,
|
||||
|
|
|
@ -26,20 +26,20 @@ const Level = enum {
|
|||
err,
|
||||
};
|
||||
|
||||
pub fn create(a: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
|
||||
const self: *Self = try a.create(Self);
|
||||
pub fn create(allocator: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
|
||||
const self: *Self = try allocator.create(Self);
|
||||
self.* = .{
|
||||
.plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent),
|
||||
.msg = std.ArrayList(u8).init(a),
|
||||
.msg = std.ArrayList(u8).init(allocator),
|
||||
.on_event = event_handler,
|
||||
};
|
||||
logview.init(a);
|
||||
logview.init(allocator);
|
||||
try tui.current().message_filters.add(MessageFilter.bind(self, receive_log));
|
||||
try log.subscribe();
|
||||
return Widget.to(self);
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Self, a: std.mem.Allocator) void {
|
||||
pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
|
||||
if (self.clear_timer) |*t| {
|
||||
t.cancel() catch {};
|
||||
t.deinit();
|
||||
|
@ -49,7 +49,7 @@ pub fn deinit(self: *Self, a: std.mem.Allocator) void {
|
|||
log.unsubscribe() catch {};
|
||||
tui.current().message_filters.remove_ptr(self);
|
||||
self.plane.deinit();
|
||||
a.destroy(self);
|
||||
allocator.destroy(self);
|
||||
}
|
||||
|
||||
pub fn receive(self: *Self, from: tp.pid_ref, m: tp.message) error{Exit}!bool {
|
||||
|
|
|
@ -15,8 +15,8 @@ const ed = @import("../editor.zig");
|
|||
const tui = @import("../tui.zig");
|
||||
const CreateError = @import("widget.zig").CreateError;
|
||||
|
||||
pub fn create(a: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) CreateError!Widget {
|
||||
return Button.create_widget(void, a, parent, .{
|
||||
pub fn create(allocator: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) CreateError!Widget {
|
||||
return Button.create_widget(void, allocator, parent, .{
|
||||
.ctx = {},
|
||||
.label = tui.get_mode(),
|
||||
.on_click = on_click,
|
||||
|
|
|
@ -23,8 +23,8 @@ const Self = @This();
|
|||
|
||||
pub const width = 5;
|
||||
|
||||
pub fn create(a: Allocator, parent: Plane, _: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
|
||||
const self: *Self = try a.create(Self);
|
||||
pub fn create(allocator: Allocator, parent: Plane, _: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
|
||||
const self: *Self = try allocator.create(Self);
|
||||
self.* = .{
|
||||
.plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent),
|
||||
};
|
||||
|
@ -36,10 +36,10 @@ pub fn widget(self: *Self) Widget {
|
|||
return Widget.to(self);
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Self, a: Allocator) void {
|
||||
pub fn deinit(self: *Self, allocator: Allocator) void {
|
||||
tui.current().input_listeners.remove_ptr(self);
|
||||
self.plane.deinit();
|
||||
a.destroy(self);
|
||||
allocator.destroy(self);
|
||||
}
|
||||
|
||||
pub fn layout(_: *Self) Widget.Layout {
|
||||
|
|
|
@ -19,8 +19,8 @@ on_event: ?Widget.EventHandler,
|
|||
|
||||
const Self = @This();
|
||||
|
||||
pub fn create(a: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
|
||||
const self: *Self = try a.create(Self);
|
||||
pub fn create(allocator: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
|
||||
const self: *Self = try allocator.create(Self);
|
||||
self.* = .{
|
||||
.plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent),
|
||||
.on_event = event_handler,
|
||||
|
@ -28,9 +28,9 @@ pub fn create(a: Allocator, parent: Plane, event_handler: ?Widget.EventHandler)
|
|||
return Widget.to(self);
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Self, a: Allocator) void {
|
||||
pub fn deinit(self: *Self, allocator: Allocator) void {
|
||||
self.plane.deinit();
|
||||
a.destroy(self);
|
||||
allocator.destroy(self);
|
||||
}
|
||||
|
||||
pub fn layout(self: *Self) Widget.Layout {
|
||||
|
|
|
@ -16,9 +16,9 @@ const widgets = std.static_string_map.StaticStringMap(CreateFunction).initCompti
|
|||
.{ "clock", @import("clock.zig").create },
|
||||
});
|
||||
pub const CreateError = error{ OutOfMemory, Exit };
|
||||
pub const CreateFunction = *const fn (a: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) CreateError!Widget;
|
||||
pub const CreateFunction = *const fn (allocator: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) CreateError!Widget;
|
||||
|
||||
pub fn create(name: []const u8, a: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) CreateError!?Widget {
|
||||
pub fn create(name: []const u8, allocator: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) CreateError!?Widget {
|
||||
const create_ = widgets.get(name) orelse return null;
|
||||
return try create_(a, parent, event_handler);
|
||||
return try create_(allocator, parent, event_handler);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue