refactor(terminal): handle title_change and pwd_change events
This commit is contained in:
parent
367c532596
commit
d423696e7e
1 changed files with 13 additions and 1 deletions
|
|
@ -32,6 +32,8 @@ env: std.process.EnvMap,
|
||||||
write_buf: [4096]u8,
|
write_buf: [4096]u8,
|
||||||
poll_timer: ?tp.Cancellable = null,
|
poll_timer: ?tp.Cancellable = null,
|
||||||
focused: bool = false,
|
focused: bool = false,
|
||||||
|
cwd: std.ArrayListUnmanaged(u8) = .empty,
|
||||||
|
title: std.ArrayListUnmanaged(u8) = .empty,
|
||||||
|
|
||||||
pub fn create(allocator: Allocator, parent: Plane) !Widget {
|
pub fn create(allocator: Allocator, parent: Plane) !Widget {
|
||||||
return create_with_args(allocator, parent, .{});
|
return create_with_args(allocator, parent, .{});
|
||||||
|
|
@ -158,6 +160,8 @@ pub fn unfocus(self: *Self) void {
|
||||||
|
|
||||||
pub fn deinit(self: *Self, allocator: Allocator) void {
|
pub fn deinit(self: *Self, allocator: Allocator) void {
|
||||||
if (self.focused) tui.release_keyboard_focus(Widget.to(self));
|
if (self.focused) tui.release_keyboard_focus(Widget.to(self));
|
||||||
|
self.cwd.deinit(self.allocator);
|
||||||
|
self.title.deinit(self.allocator);
|
||||||
tui.message_filters().remove_ptr(self);
|
tui.message_filters().remove_ptr(self);
|
||||||
if (self.poll_timer) |*t| {
|
if (self.poll_timer) |*t| {
|
||||||
t.cancel() catch {};
|
t.cancel() catch {};
|
||||||
|
|
@ -177,7 +181,15 @@ pub fn render(self: *Self, _: *const Widget.Theme) bool {
|
||||||
tp.self_pid().send(.{ "cmd", "toggle_terminal_view" }) catch {};
|
tp.self_pid().send(.{ "cmd", "toggle_terminal_view" }) catch {};
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
.redraw, .bell, .title_change, .pwd_change => {},
|
.redraw, .bell => {},
|
||||||
|
.pwd_change => |path| {
|
||||||
|
self.cwd.clearRetainingCapacity();
|
||||||
|
self.cwd.appendSlice(self.allocator, path) catch {};
|
||||||
|
},
|
||||||
|
.title_change => |t| {
|
||||||
|
self.title.clearRetainingCapacity();
|
||||||
|
self.title.appendSlice(self.allocator, t) catch {};
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue