add scroll page

This commit is contained in:
Hongjie Zhai 2021-04-21 14:27:58 +09:00
parent 74cc48fc50
commit fad088a868
7 changed files with 61 additions and 0 deletions

View File

@ -2171,6 +2171,30 @@ impl Tab {
self.render();
}
}
pub fn scroll_active_terminal_up_page(&mut self) {
if let Some(active_terminal_id) = self.get_active_terminal_id() {
let active_terminal = self
.panes
.get_mut(&PaneId::Terminal(active_terminal_id))
.unwrap();
// prevent overflow when row == 0
let scroll_columns = active_terminal.rows().max(1) - 1;
active_terminal.scroll_up(scroll_columns);
self.render();
}
}
pub fn scroll_active_terminal_down_page(&mut self) {
if let Some(active_terminal_id) = self.get_active_terminal_id() {
let active_terminal = self
.panes
.get_mut(&PaneId::Terminal(active_terminal_id))
.unwrap();
// prevent overflow when row == 0
let scroll_columns = active_terminal.rows().max(1) - 1;
active_terminal.scroll_down(scroll_columns);
self.render();
}
}
pub fn clear_active_terminal_scroll(&mut self) {
if let Some(active_terminal_id) = self.get_active_terminal_id() {
let active_terminal = self

View File

@ -196,6 +196,8 @@ pub enum ScreenContext {
Quit,
ScrollUp,
ScrollDown,
PageScrollUp,
PageScrollDown,
ClearScroll,
CloseFocusedPane,
ToggleActiveTerminalFullscreen,
@ -238,6 +240,8 @@ impl From<&ScreenInstruction> for ScreenContext {
ScreenInstruction::Quit => ScreenContext::Quit,
ScreenInstruction::ScrollUp => ScreenContext::ScrollUp,
ScreenInstruction::ScrollDown => ScreenContext::ScrollDown,
ScreenInstruction::PageScrollUp => ScreenContext::PageScrollUp,
ScreenInstruction::PageScrollDown => ScreenContext::PageScrollDown,
ScreenInstruction::ClearScroll => ScreenContext::ClearScroll,
ScreenInstruction::CloseFocusedPane => ScreenContext::CloseFocusedPane,
ScreenInstruction::ToggleActiveTerminalFullscreen => {

View File

@ -33,6 +33,10 @@ pub enum Action {
ScrollUp,
/// Scroll down in focus pane.
ScrollDown,
/// Scroll up one page in focus pane.
PageScrollUp,
/// Scroll down one page in focus pane.
PageScrollDown,
/// Toggle between fullscreen focus pane and normal layout.
ToggleFocusFullscreen,
/// Open a new pane in the specified direction (relative to focus).

View File

@ -184,6 +184,16 @@ impl InputHandler {
.send(ScreenInstruction::ScrollDown)
.unwrap();
}
Action::PageScrollUp => {
self.send_screen_instructions
.send(ScreenInstruction::PageScrollUp)
.unwrap();
}
Action::PageScrollDown => {
self.send_screen_instructions
.send(ScreenInstruction::PageScrollDown)
.unwrap();
}
Action::ToggleFocusFullscreen => {
self.send_screen_instructions
.send(ScreenInstruction::ToggleActiveTerminalFullscreen)

View File

@ -340,6 +340,11 @@ impl Keybinds {
defaults.insert(Key::Char('j'), vec![Action::ScrollDown]);
defaults.insert(Key::Char('k'), vec![Action::ScrollUp]);
defaults.insert(Key::Ctrl('f'), vec![Action::PageScrollDown]);
defaults.insert(Key::Ctrl('b'), vec![Action::PageScrollUp]);
defaults.insert(Key::PageDown, vec![Action::PageScrollDown]);
defaults.insert(Key::PageUp, vec![Action::PageScrollUp]);
defaults.insert(Key::Down, vec![Action::ScrollDown]);
defaults.insert(Key::Up, vec![Action::ScrollUp]);

View File

@ -366,6 +366,18 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) {
.unwrap()
.scroll_active_terminal_down();
}
ScreenInstruction::PageScrollUp => {
screen
.get_active_tab_mut()
.unwrap()
.scroll_active_terminal_up_page();
}
ScreenInstruction::PageScrollDown => {
screen
.get_active_tab_mut()
.unwrap()
.scroll_active_terminal_down_page();
}
ScreenInstruction::ClearScroll => {
screen
.get_active_tab_mut()

View File

@ -38,6 +38,8 @@ pub enum ScreenInstruction {
Quit,
ScrollUp,
ScrollDown,
PageScrollUp,
PageScrollDown,
ClearScroll,
CloseFocusedPane,
ToggleActiveTerminalFullscreen,