refactor: split mini modes into input mode and a ui mode

This commit is contained in:
CJ van den Berg 2024-10-25 18:40:01 +02:00
parent d804203760
commit f41fb97d02
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
6 changed files with 56 additions and 58 deletions

View file

@ -34,7 +34,7 @@ pub fn Create(options: type) type {
type: enum { dir, file, link },
};
pub fn create(allocator: std.mem.Allocator, _: command.Context) !*Self {
pub fn create(allocator: std.mem.Allocator, _: command.Context) !struct { tui.Mode, tui.MiniMode } {
const self: *Self = try allocator.create(Self);
self.* = .{
.allocator = allocator,
@ -47,7 +47,14 @@ pub fn Create(options: type) type {
try options.load_entries(self);
if (@hasDecl(options, "restore_state"))
options.restore_state(self) catch {};
return self;
return .{
.{
.handler = EventHandler.to_owned(self),
.name = options.name(self),
.description = options.name(self),
},
.{},
};
}
pub fn deinit(self: *Self) void {
@ -60,14 +67,6 @@ pub fn Create(options: type) type {
self.allocator.destroy(self);
}
pub fn handler(self: *Self) EventHandler {
return EventHandler.to_owned(self);
}
pub fn name(self: *Self) []const u8 {
return options.name(self);
}
pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {
var evtype: u32 = undefined;
var keypress: u32 = undefined;