mirror of
https://github.com/ChrisTitusTech/linutil.git
synced 2024-11-24 14:11:55 +00:00
feat: Add scroll (#643)
* Add scroll * Update running_command.rs * Add hints, Up and Down to terminal
This commit is contained in:
parent
df4f44461e
commit
66b92c84b0
|
@ -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 {
|
||||
|
@ -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],
|
||||
|
|
Loading…
Reference in New Issue
Block a user