diff --git a/src/tui/filelist_view.zig b/src/tui/filelist_view.zig index ff820e1..9001b07 100644 --- a/src/tui/filelist_view.zig +++ b/src/tui/filelist_view.zig @@ -57,7 +57,7 @@ const Entry = struct { pos_type: editor.PosType, }; -pub fn create(allocator: Allocator, parent: Plane) !Widget { +pub fn create(allocator: Allocator, parent: Plane, _: command.Context) !Widget { const self = try allocator.create(Self); errdefer allocator.destroy(self); self.* = .{ diff --git a/src/tui/info_view.zig b/src/tui/info_view.zig index 1bc72dc..9628df0 100644 --- a/src/tui/info_view.zig +++ b/src/tui/info_view.zig @@ -1,6 +1,7 @@ const std = @import("std"); const Allocator = @import("std").mem.Allocator; const Plane = @import("renderer").Plane; +const command = @import("command"); const Widget = @import("Widget.zig"); const WidgetList = @import("WidgetList.zig"); const reflow = @import("Buffer").reflow; @@ -19,7 +20,7 @@ widget_type: Widget.Type, const default_widget_type: Widget.Type = .panel; -pub fn create(allocator: Allocator, parent: Plane) !Widget { +pub fn create(allocator: Allocator, parent: Plane, _: command.Context) !Widget { return create_widget_type(allocator, parent, default_widget_type); } diff --git a/src/tui/inputview.zig b/src/tui/inputview.zig index 00e2b55..b1e732c 100644 --- a/src/tui/inputview.zig +++ b/src/tui/inputview.zig @@ -10,6 +10,7 @@ const cbor = @import("cbor"); const Plane = @import("renderer").Plane; const EventHandler = @import("EventHandler"); const input = @import("input"); +const command = @import("command"); const tui = @import("tui.zig"); const Widget = @import("Widget.zig"); @@ -33,7 +34,7 @@ const Entry = struct { }; const Buffer = ArrayList(Entry); -pub fn create(allocator: Allocator, parent: Plane) !Widget { +pub fn create(allocator: Allocator, parent: Plane, _: command.Context) !Widget { var n = try Plane.init(&(Widget.Box{}).opts_vscroll(@typeName(Self)), parent); errdefer n.deinit(); const container = try WidgetList.createHStyled(allocator, parent, "panel_frame", .dynamic, widget_type); diff --git a/src/tui/inspector_view.zig b/src/tui/inspector_view.zig index a7c26a0..69bf41b 100644 --- a/src/tui/inspector_view.zig +++ b/src/tui/inspector_view.zig @@ -9,6 +9,7 @@ const Plane = @import("renderer").Plane; const style = @import("renderer").style; const styles = @import("renderer").styles; const EventHandler = @import("EventHandler"); +const command = @import("command"); const tui = @import("tui.zig"); const Widget = @import("Widget.zig"); @@ -25,7 +26,7 @@ last_node: usize = 0, const Self = @This(); const widget_type: Widget.Type = .panel; -pub fn create(allocator: Allocator, parent: Plane) !Widget { +pub fn create(allocator: Allocator, parent: Plane, _: command.Context) !Widget { const editor = tui.get_active_editor() orelse return error.NotFound; const self = try allocator.create(Self); errdefer allocator.destroy(self); diff --git a/src/tui/keybindview.zig b/src/tui/keybindview.zig index 339d7c2..4064577 100644 --- a/src/tui/keybindview.zig +++ b/src/tui/keybindview.zig @@ -10,6 +10,7 @@ const cbor = @import("cbor"); const Plane = @import("renderer").Plane; const input = @import("input"); +const command = @import("command"); const tui = @import("tui.zig"); const Widget = @import("Widget.zig"); @@ -33,7 +34,7 @@ const Entry = struct { }; const Buffer = ArrayList(Entry); -pub fn create(allocator: Allocator, parent: Plane) !Widget { +pub fn create(allocator: Allocator, parent: Plane, _: command.Context) !Widget { var n = try Plane.init(&(Widget.Box{}).opts_vscroll(@typeName(Self)), parent); errdefer n.deinit(); const container = try WidgetList.createHStyled(allocator, parent, "panel_frame", .dynamic, widget_type); diff --git a/src/tui/logview.zig b/src/tui/logview.zig index 92a756a..04ceedc 100644 --- a/src/tui/logview.zig +++ b/src/tui/logview.zig @@ -6,6 +6,7 @@ const array_list = @import("std").array_list; const tp = @import("thespian"); const cbor = @import("cbor"); +const command = @import("command"); const Plane = @import("renderer").Plane; @@ -39,7 +40,7 @@ const Level = enum { err, }; -pub fn create(allocator: Allocator, parent: Plane) !Widget { +pub fn create(allocator: Allocator, parent: Plane, _: command.Context) !Widget { const self = try allocator.create(Self); errdefer allocator.destroy(self); const container = try WidgetList.createHStyled(allocator, parent, "panel_frame", .dynamic, widget_type); diff --git a/src/tui/mainview.zig b/src/tui/mainview.zig index fe4507a..4633709 100644 --- a/src/tui/mainview.zig +++ b/src/tui/mainview.zig @@ -298,7 +298,13 @@ pub fn get_panel_height(self: *Self) usize { return self.panel_height orelse self.box().h / 5; } -fn toggle_panel_view(self: *Self, view: anytype, mode: enum { toggle, enable, disable }) !void { +pub const PanelToggleMode = enum { toggle, enable, disable }; + +fn toggle_panel_view(self: *Self, view: anytype, mode: PanelToggleMode) !void { + return self.toggle_panel_view_with_args(view, mode, .{}); +} + +fn toggle_panel_view_with_args(self: *Self, view: anytype, mode: PanelToggleMode, ctx: command.Context) !void { if (self.panels) |panels| { if (self.get_panel(@typeName(view))) |w| { if (mode != .enable) { @@ -310,39 +316,17 @@ fn toggle_panel_view(self: *Self, view: anytype, mode: enum { toggle, enable, di } } else { if (mode != .disable) - try panels.add(try view.create(self.allocator, self.widgets.plane)); + try panels.add(try view.create(self.allocator, self.widgets.plane, ctx)); } } else if (mode != .disable) { const panels = try WidgetList.createH(self.allocator, self.widgets.plane, "panel", .{ .static = self.get_panel_height() }); try self.widgets.add(panels.widget()); - try panels.add(try view.create(self.allocator, self.widgets.plane)); + try panels.add(try view.create(self.allocator, self.widgets.plane, ctx)); self.panels = panels; } tui.resize(); } -fn toggle_panel_view_with_args(self: *Self, view: anytype, mode: enum { toggle, enable, disable }, ctx: command.Context) !void { - if (self.panels) |panels| { - if (self.get_panel(@typeName(view))) |w| { - if (mode != .enable) { - panels.remove(w.*); - if (panels.empty()) { - self.widgets.remove(panels.widget()); - self.panels = null; - } - } - } else { - if (mode != .disable) - try panels.add(try view.create_with_args(self.allocator, self.widgets.plane, ctx)); - } - } else if (mode != .disable) { - const panels = try WidgetList.createH(self.allocator, self.widgets.plane, "panel", .{ .static = self.get_panel_height() }); - try self.widgets.add(panels.widget()); - try panels.add(try view.create_with_args(self.allocator, self.widgets.plane, ctx)); - self.panels = panels; - } - tui.resize(); -} fn get_panel(self: *Self, name_: []const u8) ?*Widget { if (self.panels) |panels| for (panels.widgets.items) |*w| diff --git a/src/tui/terminal_view.zig b/src/tui/terminal_view.zig index 6fac6a2..d84f8b2 100644 --- a/src/tui/terminal_view.zig +++ b/src/tui/terminal_view.zig @@ -37,11 +37,7 @@ hover: bool = false, vt: *Vt, commands: Commands = undefined, -pub fn create(allocator: Allocator, parent: Plane) !Widget { - return create_with_args(allocator, parent, .{}); -} - -pub fn create_with_args(allocator: Allocator, parent: Plane, ctx: command.Context) !Widget { +pub fn create(allocator: Allocator, parent: Plane, ctx: command.Context) !Widget { const container = try WidgetList.createHStyled( allocator, parent,