diff --git a/src/keybind/builtin/flow.json b/src/keybind/builtin/flow.json index 818a41a..b27c000 100644 --- a/src/keybind/builtin/flow.json +++ b/src/keybind/builtin/flow.json @@ -39,6 +39,8 @@ ["ctrl+shift+f", "find_in_files"], ["ctrl+shift+l", "toggle_panel"], ["alt+shift+p", "open_command_palette"], + ["ctrl+shift+page_up", "terminal_scroll_up"], + ["ctrl+shift+page_down", "terminal_scroll_down"], ["alt+n", "goto_next_file_or_diagnostic"], ["alt+p", "goto_prev_file_or_diagnostic"], ["alt+l", "toggle_panel"], diff --git a/src/tui/terminal_view.zig b/src/tui/terminal_view.zig index 1aa8eb7..389751a 100644 --- a/src/tui/terminal_view.zig +++ b/src/tui/terminal_view.zig @@ -29,6 +29,7 @@ focused: bool = false, input_mode: Mode, hover: bool = false, vt: *Vt, +commands: Commands = undefined, pub fn create(allocator: Allocator, parent: Plane) !Widget { return create_with_args(allocator, parent, .{}); @@ -88,6 +89,7 @@ pub fn create_with_args(allocator: Allocator, parent: Plane, ctx: command.Contex .vt = &global_vt.?, }; + try self.commands.init(self); try tui.message_filters().add(MessageFilter.bind(self, receive_filter)); container.ctx = self; @@ -179,6 +181,7 @@ pub fn deinit(self: *Self, allocator: Allocator) void { // p.deinit(self.allocator); // state = null; // } + self.commands.unregister(); self.plane.deinit(); allocator.destroy(self); } @@ -240,6 +243,29 @@ fn receive_filter(_: *Self, _: tp.pid_ref, m: tp.message) MessageFilter.Error!bo return false; } +const Commands = command.Collection(cmds); + +const cmds = struct { + pub const Target = Self; + const Ctx = command.Context; + const Meta = command.Metadata; + const Result = command.Result; + + pub fn terminal_scroll_up(self: *Self, _: Ctx) Result { + const half_page = @max(1, self.vt.vt.front_screen.height / 2); + if (self.vt.vt.scroll(@intCast(half_page))) + tui.need_render(@src()); + } + pub const terminal_scroll_up_meta: Meta = .{ .description = "Terminal: Scroll up" }; + + pub fn terminal_scroll_down(self: *Self, _: Ctx) Result { + const half_page = @max(1, self.vt.vt.front_screen.height / 2); + if (self.vt.vt.scroll(-@as(i32, @intCast(half_page)))) + tui.need_render(@src()); + } + pub const terminal_scroll_down_meta: Meta = .{ .description = "Terminal: Scroll down" }; +}; + const Vt = struct { vt: Terminal, env: std.process.EnvMap,