From 66b92c84b096b47ce31aa554bd41cbbd1fa89f6a Mon Sep 17 00:00:00 2001 From: JEEVITHA KANNAN K S Date: Tue, 1 Oct 2024 02:16:05 +0530 Subject: [PATCH] feat: Add scroll (#643) * Add scroll * Update running_command.rs * Add hints, Up and Down to terminal --- tui/src/running_command.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/tui/src/running_command.rs b/tui/src/running_command.rs index 366a3dc3..ce7bee02 100644 --- a/tui/src/running_command.rs +++ b/tui/src/running_command.rs @@ -37,6 +37,7 @@ pub struct RunningCommand { writer: Box, /// Only set after the process has ended status: Option, + scroll_offset: usize, } impl FloatContent for RunningCommand { @@ -102,6 +103,12 @@ impl FloatContent for RunningCommand { KeyCode::Enter if self.is_finished() => { return true; } + KeyCode::PageUp => { + self.scroll_offset = self.scroll_offset.saturating_add(10); + } + KeyCode::PageDown => { + self.scroll_offset = self.scroll_offset.saturating_sub(10); + } // Pass other key events to the terminal _ => self.handle_passthrough_key_event(key), } @@ -121,12 +128,20 @@ impl FloatContent for RunningCommand { if self.is_finished() { ( "Finished command", - Box::new([Shortcut::new("Close window", ["Enter", "q"])]), + Box::new([ + Shortcut::new("Close window", ["Enter", "q"]), + Shortcut::new("Scroll up", ["Page up"]), + Shortcut::new("Scroll down", ["Page down"]), + ]), ) } else { ( "Running command", - Box::new([Shortcut::new("Kill the command", ["CTRL-c"])]), + Box::new([ + Shortcut::new("Kill the command", ["CTRL-c"]), + Shortcut::new("Scroll up", ["Page up"]), + Shortcut::new("Scroll down", ["Page down"]), + ]), ) } } @@ -220,6 +235,7 @@ impl RunningCommand { pty_master: pair.master, writer, status: None, + scroll_offset: 0, } } @@ -237,10 +253,12 @@ impl RunningCommand { // Process the buffer with a parser with the current screen size // We don't actually need to create a new parser every time, but it is so much easier this // way, and doesn't cost that much - let mut parser = vt100::Parser::new(size.height, size.width, 0); + let mut parser = vt100::Parser::new(size.height, size.width, 200); let mutex = self.buffer.lock(); let buffer = mutex.as_ref().unwrap(); parser.process(buffer); + // Adjust the screen content based on the scroll offset + parser.set_scrollback(self.scroll_offset); parser.screen().clone() } @@ -297,8 +315,6 @@ impl RunningCommand { KeyCode::Tab => vec![9], KeyCode::Home => vec![27, 91, 72], KeyCode::End => vec![27, 91, 70], - KeyCode::PageUp => vec![27, 91, 53, 126], - KeyCode::PageDown => vec![27, 91, 54, 126], KeyCode::BackTab => vec![27, 91, 90], KeyCode::Delete => vec![27, 91, 51, 126], KeyCode::Insert => vec![27, 91, 50, 126],