refactor: make focus_termimal a toggle

This commit is contained in:
CJ van den Berg 2026-02-24 23:14:38 +01:00
parent 3d1658541a
commit 613b95c2af
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 10 additions and 3 deletions

View file

@ -982,10 +982,13 @@ const cmds = struct {
pub const open_terminal_meta: Meta = .{ .description = "Open terminal", .arguments = &.{.string} };
pub fn focus_terminal(self: *Self, _: Ctx) Result {
if (self.get_panel_view(terminal_view)) |vt|
vt.focus()
else
if (self.get_panel_view(terminal_view)) |vt| {
vt.toggle_focus();
} else {
try self.toggle_panel_view(terminal_view, .enable);
if (self.get_panel_view(terminal_view)) |vt|
vt.focus();
}
}
pub const focus_terminal_meta: Meta = .{ .description = "Focus terminal panel" };

View file

@ -148,6 +148,10 @@ pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {
return true;
}
pub fn toggle_focus(self: *Self) void {
if (self.focused) self.unfocus() else self.focus();
}
pub fn focus(self: *Self) void {
self.focused = true;
tui.set_keyboard_focus(Widget.to(self));