refactor: split out keybind events from inputview to a new keybindview
This commit is contained in:
parent
c87884f924
commit
65c9b41784
2 changed files with 114 additions and 20 deletions
|
|
@ -13,7 +13,6 @@ const input = @import("input");
|
|||
|
||||
const tui = @import("tui.zig");
|
||||
const Widget = @import("Widget.zig");
|
||||
const MessageFilter = @import("MessageFilter.zig");
|
||||
|
||||
pub const name = "inputview";
|
||||
|
||||
|
|
@ -44,14 +43,10 @@ pub fn create(allocator: Allocator, parent: Plane) !Widget {
|
|||
.buffer = .empty,
|
||||
};
|
||||
try tui.input_listeners().add(EventHandler.bind(self, listen));
|
||||
try tui.message_filters().add(MessageFilter.bind(self, keybind_match));
|
||||
tui.enable_match_events();
|
||||
return Widget.to(self);
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Self, allocator: Allocator) void {
|
||||
tui.disable_match_events();
|
||||
tui.message_filters().remove_ptr(self);
|
||||
tui.input_listeners().remove_ptr(self);
|
||||
for (self.buffer.items) |item|
|
||||
self.allocator.free(item.json);
|
||||
|
|
@ -135,21 +130,6 @@ fn listen(self: *Self, _: tp.pid_ref, m: tp.message) tp.result {
|
|||
self.append(result.written()) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
||||
}
|
||||
|
||||
fn keybind_match(self: *Self, _: tp.pid_ref, m: tp.message) MessageFilter.Error!bool {
|
||||
var namespace: []const u8 = undefined;
|
||||
var section: []const u8 = undefined;
|
||||
var cmds: []const u8 = undefined;
|
||||
if (!(m.match(.{ "K", tp.extract(&namespace), tp.extract(§ion), tp.extract_cbor(&cmds) }) catch false)) return false;
|
||||
|
||||
var result: Writer.Allocating = .init(self.allocator);
|
||||
defer result.deinit();
|
||||
const writer = &result.writer;
|
||||
cbor.toJsonWriter(m.buf, writer, .{}) catch return true;
|
||||
|
||||
self.append(result.written()) catch return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
pub fn receive(_: *Self, _: tp.pid_ref, _: tp.message) error{Exit}!bool {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue