diff --git a/alacritty.yml b/alacritty.yml index f8342dba..0cb866d7 100644 --- a/alacritty.yml +++ b/alacritty.yml @@ -281,7 +281,18 @@ live_config_reload: true # around them. # # Either an `action`, `chars`, or `command` field must be present. -# `action` must be one of `Paste`, `PasteSelection`, `Copy`, or `Quit`. +# `action` must be one of the following: +# - `Paste` +# - `PasteSelection` +# - `Copy` +# - `IncreaseFontSize` +# - `DecreaseFontSize` +# - `ResetFontSize` +# - `ScrollPageUp` +# - `ScrollPageDown` +# - `ScrollToTop` +# - `ScrollToBottom` +# - `Quit` # `chars` writes the specified string every time that binding is activated. # These should generally be escape sequences, but they can be configured to # send arbitrary strings of bytes. diff --git a/alacritty_macos.yml b/alacritty_macos.yml index de8316af..e7646fbc 100644 --- a/alacritty_macos.yml +++ b/alacritty_macos.yml @@ -262,7 +262,18 @@ live_config_reload: true # around them. # # Either an `action`, `chars`, or `command` field must be present. -# `action` must be one of `Paste`, `PasteSelection`, `Copy`, or `Quit`. +# `action` must be one of the following: +# - `Paste` +# - `PasteSelection` +# - `Copy` +# - `IncreaseFontSize` +# - `DecreaseFontSize` +# - `ResetFontSize` +# - `ScrollPageUp` +# - `ScrollPageDown` +# - `ScrollToTop` +# - `ScrollToBottom` +# - `Quit` # `chars` writes the specified string every time that binding is activated. # These should generally be escape sequences, but they can be configured to # send arbitrary strings of bytes. diff --git a/src/config.rs b/src/config.rs index 02b3e7f9..57a23719 100644 --- a/src/config.rs +++ b/src/config.rs @@ -588,7 +588,8 @@ impl<'a> de::Deserialize<'a> for ActionWrapper { type Value = ActionWrapper; fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_str("Paste, Copy, PasteSelection, IncreaseFontSize, DecreaseFontSize, ResetFontSize, or Quit") + f.write_str("Paste, Copy, PasteSelection, IncreaseFontSize, DecreaseFontSize, \ + ResetFontSize, ScrollPageUp, ScrollPageDown, ScrollToTop, ScrollToBottom or Quit") } fn visit_str(self, value: &str) -> ::std::result::Result @@ -601,6 +602,10 @@ impl<'a> de::Deserialize<'a> for ActionWrapper { "IncreaseFontSize" => Action::IncreaseFontSize, "DecreaseFontSize" => Action::DecreaseFontSize, "ResetFontSize" => Action::ResetFontSize, + "ScrollPageUp" => Action::ScrollPageUp, + "ScrollPageDown" => Action::ScrollPageDown, + "ScrollToTop" => Action::ScrollToTop, + "ScrollToBottom" => Action::ScrollToBottom, "Quit" => Action::Quit, _ => return Err(E::invalid_value(Unexpected::Str(value), &self)), })) diff --git a/src/event.rs b/src/event.rs index c079ddfb..322f0278 100644 --- a/src/event.rs +++ b/src/event.rs @@ -61,6 +61,18 @@ impl<'a, N: Notify + 'a> input::ActionContext for ActionContext<'a, N> { self.terminal.reset_scroll(); } + fn scroll_to_top(&mut self) { + self.terminal.scroll_to_top(); + } + + fn scroll_page_up(&mut self) { + self.terminal.scroll_page_up(); + } + + fn scroll_page_down(&mut self) { + self.terminal.scroll_page_down(); + } + fn copy_selection(&self, buffer: ::copypasta::Buffer) { self.terminal .selection_to_string() diff --git a/src/grid/mod.rs b/src/grid/mod.rs index a52c27c5..ac761adc 100644 --- a/src/grid/mod.rs +++ b/src/grid/mod.rs @@ -176,6 +176,26 @@ impl Grid { self.display_offset = 0; } + pub fn scroll_to_top(&mut self) { + self.display_offset = self.scroll_limit; + } + + pub fn scroll_page_up(&mut self) { + if self.display_offset + self.lines.0 >= self.scroll_limit { + self.display_offset = self.scroll_limit; + } else { + self.display_offset += self.lines.0; + } + } + + pub fn scroll_page_down(&mut self) { + if self.display_offset <= self.lines.0 { + self.display_offset = 0; + } else { + self.display_offset -= self.lines.0; + } + } + pub fn resize(&mut self, lines: index::Line, cols: index::Column) { // Check that there's actually work to do and return early if not if lines == self.lines && cols == self.cols { diff --git a/src/input.rs b/src/input.rs index def20b4d..96c67db6 100644 --- a/src/input.rs +++ b/src/input.rs @@ -65,8 +65,11 @@ pub trait ActionContext { fn last_modifiers(&mut self) -> &mut ModifiersState; fn change_font_size(&mut self, delta: i8); fn reset_font_size(&mut self); - fn scroll(&mut self, count: isize) {} - fn reset_scroll(&mut self) {} + fn scroll(&mut self, count: isize); + fn reset_scroll(&mut self); + fn scroll_to_top(&mut self); + fn scroll_page_up(&mut self); + fn scroll_page_down(&mut self); } /// Describes a state and action to take in that state @@ -168,6 +171,18 @@ pub enum Action { /// Reset font size to the config value ResetFontSize, + /// Scroll exactly one page up + ScrollPageUp, + + /// Scroll exactly one page down + ScrollPageDown, + + /// Scroll all the way to the top + ScrollToTop, + + /// Scroll all the way to the bottom + ScrollToBottom, + /// Run given command Command(String, Vec), @@ -233,7 +248,19 @@ impl Action { } Action::ResetFontSize => { ctx.reset_font_size(); - } + }, + Action::ScrollPageUp => { + ctx.scroll_page_up(); + }, + Action::ScrollPageDown => { + ctx.scroll_page_down(); + }, + Action::ScrollToTop => { + ctx.scroll_to_top(); + }, + Action::ScrollToBottom => { + ctx.reset_scroll(); + }, } } diff --git a/src/term/mod.rs b/src/term/mod.rs index 8d378247..8f9fee1b 100644 --- a/src/term/mod.rs +++ b/src/term/mod.rs @@ -830,6 +830,22 @@ impl Term { pub fn reset_scroll(&mut self) { self.grid.reset_scroll_display(); + self.dirty = true; + } + + pub fn scroll_to_top(&mut self) { + self.grid.scroll_to_top(); + self.dirty = true; + } + + pub fn scroll_page_up(&mut self) { + self.grid.scroll_page_up(); + self.dirty = true; + } + + pub fn scroll_page_down(&mut self) { + self.grid.scroll_page_down(); + self.dirty = true; } #[inline]