Compare commits

..

8 commits

8 changed files with 50 additions and 6 deletions

View file

@ -44,6 +44,7 @@
["f10", "theme_next"],
["f11", "toggle_panel"],
["alt+f11", "toggle_color_scheme"],
["alt+f9", "panel_next_widget_style"],
["shift+alt+f9", "hint_window_next_widget_style"],
["alt+!", "run_task"],
["ctrl+tab", "next_tab"],
@ -527,6 +528,7 @@
"press": [
["ctrl+?", "toggle_keybind_hints"],
["ctrl+alt+?", "scroll_keybind_hints"],
["alt+f9", "panel_next_widget_style"],
["ctrl+q", "quit"],
["ctrl+v", "system_paste"],
["ctrl+u", "mini_mode_reset"],

View file

@ -2,6 +2,7 @@ const std = @import("std");
const Allocator = @import("std").mem.Allocator;
const Plane = @import("renderer").Plane;
const Widget = @import("Widget.zig");
const WidgetList = @import("WidgetList.zig");
pub const name = @typeName(Self);
@ -13,15 +14,20 @@ plane: Plane,
view_rows: usize = 0,
lines: std.ArrayList([]const u8),
const widget_type: Widget.Type = .panel;
pub fn create(allocator: Allocator, parent: Plane) !Widget {
const self = try allocator.create(Self);
errdefer allocator.destroy(self);
const container = try WidgetList.createHStyled(allocator, parent, "panel_frame", .dynamic, widget_type);
self.* = .{
.allocator = allocator,
.plane = try Plane.init(&(Widget.Box{}).opts(name), parent),
.lines = .empty,
};
return Widget.to(self);
container.ctx = self;
try container.add(Widget.to(self));
return container.widget();
}
pub fn deinit(self: *Self, allocator: Allocator) void {

View file

@ -13,6 +13,7 @@ const input = @import("input");
const tui = @import("tui.zig");
const Widget = @import("Widget.zig");
const WidgetList = @import("WidgetList.zig");
pub const name = "inputview";
@ -23,6 +24,7 @@ last_count: u64 = 0,
buffer: Buffer,
const Self = @This();
const widget_type: Widget.Type = .panel;
const Entry = struct {
time: i64,
@ -34,6 +36,7 @@ const Buffer = ArrayList(Entry);
pub fn create(allocator: Allocator, parent: Plane) !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);
const self = try allocator.create(Self);
errdefer allocator.destroy(self);
self.* = .{
@ -43,7 +46,9 @@ pub fn create(allocator: Allocator, parent: Plane) !Widget {
.buffer = .empty,
};
try tui.input_listeners().add(EventHandler.bind(self, listen));
return Widget.to(self);
container.ctx = self;
try container.add(Widget.to(self));
return container.widget();
}
pub fn deinit(self: *Self, allocator: Allocator) void {

View file

@ -12,6 +12,7 @@ const EventHandler = @import("EventHandler");
const tui = @import("tui.zig");
const Widget = @import("Widget.zig");
const WidgetList = @import("WidgetList.zig");
const ed = @import("editor.zig");
pub const name = @typeName(Self);
@ -22,17 +23,21 @@ theme: ?*const Widget.Theme = null,
last_node: usize = 0,
const Self = @This();
const widget_type: Widget.Type = .panel;
pub fn create(allocator: Allocator, parent: Plane) !Widget {
const editor = tui.get_active_editor() orelse return error.NotFound;
const self = try allocator.create(Self);
errdefer allocator.destroy(self);
const container = try WidgetList.createHStyled(allocator, parent, "panel_frame", .dynamic, widget_type);
self.* = .{
.plane = try Plane.init(&(Widget.Box{}).opts_vscroll(name), parent),
.editor = editor,
};
try editor.handlers.add(EventHandler.bind(self, ed_receive));
return Widget.to(self);
container.ctx = self;
try container.add(Widget.to(self));
return container.widget();
}
pub fn deinit(self: *Self, allocator: Allocator) void {

View file

@ -13,6 +13,7 @@ const input = @import("input");
const tui = @import("tui.zig");
const Widget = @import("Widget.zig");
const WidgetList = @import("WidgetList.zig");
const MessageFilter = @import("MessageFilter.zig");
pub const name = "keybindview";
@ -23,6 +24,7 @@ plane: Plane,
buffer: Buffer,
const Self = @This();
const widget_type: Widget.Type = .panel;
const Entry = struct {
time: i64,
@ -34,6 +36,7 @@ const Buffer = ArrayList(Entry);
pub fn create(allocator: Allocator, parent: Plane) !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);
const self = try allocator.create(Self);
errdefer allocator.destroy(self);
self.* = .{
@ -44,7 +47,9 @@ pub fn create(allocator: Allocator, parent: Plane) !Widget {
};
try tui.message_filters().add(MessageFilter.bind(self, keybind_match));
tui.enable_match_events();
return Widget.to(self);
container.ctx = self;
try container.add(Widget.to(self));
return container.widget();
}
pub fn deinit(self: *Self, allocator: Allocator) void {

View file

@ -10,6 +10,7 @@ const cbor = @import("cbor");
const Plane = @import("renderer").Plane;
const Widget = @import("Widget.zig");
const WidgetList = @import("WidgetList.zig");
const MessageFilter = @import("MessageFilter.zig");
const escape = @import("std").ascii.hexEscape;
@ -22,6 +23,7 @@ var persistent_buffer: ?Buffer = null;
var last_count: u64 = 0;
const Self = @This();
const widget_type: Widget.Type = .panel;
const Entry = struct {
src: []u8,
@ -40,8 +42,11 @@ const Level = enum {
pub fn create(allocator: Allocator, parent: Plane) !Widget {
const self = try allocator.create(Self);
errdefer allocator.destroy(self);
const container = try WidgetList.createHStyled(allocator, parent, "panel_frame", .dynamic, widget_type);
self.* = .{ .plane = try Plane.init(&(Widget.Box{}).opts(name), parent) };
return Widget.to(self);
container.ctx = self;
try container.add(Widget.to(self));
return container.widget();
}
pub fn deinit(self: *Self, allocator: Allocator) void {

View file

@ -273,7 +273,7 @@ fn bottom_bar_primary_drag(self: *Self, y: usize) tp.result {
fn toggle_panel_view(self: *Self, view: anytype, mode: enum { toggle, enable, disable }) !void {
if (self.panels) |panels| {
if (panels.get(@typeName(view))) |w| {
if (self.get_panel(@typeName(view))) |w| {
if (mode != .enable) {
panels.remove(w.*);
if (panels.empty()) {
@ -294,6 +294,14 @@ fn toggle_panel_view(self: *Self, view: anytype, mode: enum { toggle, enable, di
tui.resize();
}
fn get_panel(self: *Self, name_: []const u8) ?*Widget {
if (self.panels) |panels|
for (panels.widgets.items) |*w|
if (w.widget.get(name_)) |_|
return &w.widget;
return null;
}
fn get_panel_view(self: *Self, comptime view: type) ?*view {
return if (self.panels) |panels| if (panels.get(@typeName(view))) |w| w.dynamic_cast(view) else null else null;
}

View file

@ -1552,6 +1552,13 @@ const cmds = struct {
}
pub const shrink_centered_view_meta: Meta = .{ .description = "Shrink centered view" };
pub fn panel_next_widget_style(_: *Self, _: Ctx) Result {
set_next_style(.panel);
need_render();
try save_config();
}
pub const panel_next_widget_style_meta: Meta = .{};
pub fn hint_window_next_widget_style(_: *Self, _: Ctx) Result {
set_next_style(.hint_window);
need_render();
@ -2212,6 +2219,7 @@ pub fn set_next_style(widget_type: WidgetType) void {
ref.* = next_widget_style(ref.*);
const self = current();
self.logger.print("{t} style {t}", .{ widget_type, ref.* });
resize();
}
fn next_widget_style(tag: ConfigWidgetStyle) ConfigWidgetStyle {