Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: Add scroll #643

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions tui/src/running_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,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 @@ -105,6 +106,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 @@ -124,12 +131,20 @@ impl FloatContent for RunningCommand {
if self.is_finished() {
ShortcutList {
scope_name: "Finished command",
hints: vec![Shortcut::new(vec!["Enter", "q"], "Close window")],
hints: vec![
Shortcut::new(vec!["Enter", "q"], "Close window"),
Shortcut::new(vec!["Page up"], "Scroll up"),
Shortcut::new(vec!["Page down"], "Scroll down"),
],
}
} else {
ShortcutList {
scope_name: "Running command",
hints: vec![Shortcut::new(vec!["CTRL-c"], "Kill the command")],
hints: vec![
Shortcut::new(vec!["CTRL-c"], "Kill the command"),
Shortcut::new(vec!["Page up"], "Scroll up"),
Shortcut::new(vec!["Page down"], "Scroll down"),
],
}
}
}
Expand Down Expand Up @@ -223,6 +238,7 @@ impl RunningCommand {
pty_master: pair.master,
writer,
status: None,
scroll_offset: 0,
}
}

Expand All @@ -240,10 +256,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 @@ -300,8 +318,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