Add support for local keybinds

Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
AnErrupTion
2026-03-17 22:58:39 +01:00
parent a89c918c5d
commit acac884cfe
16 changed files with 87 additions and 40 deletions

View File

@@ -88,6 +88,7 @@ pub fn deinit(self: *BigLabel) void {
pub fn widget(self: *BigLabel) Widget {
return Widget.init(
"BigLabel",
null,
self,
deinit,
null,

View File

@@ -62,6 +62,7 @@ pub fn init(
pub fn widget(self: *CenteredBox) Widget {
return Widget.init(
"CenteredBox",
null,
self,
null,
null,

View File

@@ -46,6 +46,7 @@ pub fn deinit(self: *Label) void {
pub fn widget(self: *Label) Widget {
return Widget.init(
"Label",
null,
self,
deinit,
null,

View File

@@ -23,6 +23,7 @@ masked: bool,
maybe_mask: ?u32,
fg: u32,
bg: u32,
keybinds: TerminalBuffer.KeybindMap,
pub fn init(
allocator: Allocator,
@@ -32,8 +33,9 @@ pub fn init(
width: usize,
fg: u32,
bg: u32,
) Text {
return .{
) !*Text {
var self = try allocator.create(Text);
self.* = Text{
.allocator = allocator,
.buffer = buffer,
.text = .empty,
@@ -47,16 +49,24 @@ pub fn init(
.maybe_mask = maybe_mask,
.fg = fg,
.bg = bg,
.keybinds = .init(allocator),
};
try buffer.registerKeybind(&self.keybinds, "Ctrl+U", &clearTextEntry, self);
return self;
}
pub fn deinit(self: *Text) void {
self.text.deinit(self.allocator);
self.keybinds.deinit();
self.allocator.destroy(self);
}
pub fn widget(self: *Text) Widget {
return Widget.init(
"Text",
self.keybinds,
self,
deinit,
null,
@@ -208,3 +218,11 @@ fn write(self: *Text, char: u8) !void {
self.end += 1;
self.goRight();
}
fn clearTextEntry(ptr: *anyopaque) !bool {
var self: *Text = @ptrCast(@alignCast(ptr));
self.clear();
self.buffer.drawNextFrame(true);
return false;
}