Skip to content

Commit

Permalink
feat: Add scroll (#643)
Browse files Browse the repository at this point in the history
* Add scroll

* Update running_command.rs

* Add hints, Up and Down to terminal
  • Loading branch information
jeevithakannan2 authored Sep 30, 2024
1 parent df4f444 commit 66b92c8
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions tui/src/running_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub struct RunningCommand {
writer: Box<dyn Write + Send>,
/// Only set after the process has ended
status: Option<ExitStatus>,
scroll_offset: usize,
}

impl FloatContent for RunningCommand {
Expand Down Expand Up @@ -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),
}
Expand All @@ -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"]),
]),
)
}
}
Expand Down Expand Up @@ -220,6 +235,7 @@ impl RunningCommand {
pty_master: pair.master,
writer,
status: None,
scroll_offset: 0,
}
}

Expand All @@ -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()
}

Expand Down Expand Up @@ -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],
Expand Down

0 comments on commit 66b92c8

Please sign in to comment.