aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2018-03-10 20:24:10 +0100
committerJoe Wilm <joe@jwilm.com>2018-06-02 09:56:50 -0700
commit2c7bb9a4d3ce3ead6de4ca6485ca67c44c0bd1c1 (patch)
tree68616e8f2d0c2018d766d8462dc122bea1d70923 /src
parente20aa550cbcf7b3f7be6757c007960b3f9b1ac08 (diff)
downloadalacritty-2c7bb9a4d3ce3ead6de4ca6485ca67c44c0bd1c1.tar.gz
alacritty-2c7bb9a4d3ce3ead6de4ca6485ca67c44c0bd1c1.zip
Add scrollback hotkeys
This offers a few additional hotkeys that can be used in combination with scrollback. None of these are used by default yet. This implements the following bindings: - ScrollPageUp: Scroll exactly one screen height up - ScrollPageDown: Scroll exactly one screen height down - ScrollToTop: Scroll as far up as possible - ScrollToBottom: Scroll as far down as possible This fixes #1151.
Diffstat (limited to 'src')
-rw-r--r--src/config.rs7
-rw-r--r--src/event.rs12
-rw-r--r--src/grid/mod.rs20
-rw-r--r--src/input.rs33
-rw-r--r--src/term/mod.rs16
5 files changed, 84 insertions, 4 deletions
diff --git a/src/config.rs b/src/config.rs
index e7f1b587..f8dad1f2 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<E>(self, value: &str) -> ::std::result::Result<ActionWrapper, E>
@@ -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 b0987d58..4823d824 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<T: Copy + Clone> Grid<T> {
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 98e0d241..adce3448 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<String>),
@@ -237,7 +252,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 c8017262..8e973b0b 100644
--- a/src/term/mod.rs
+++ b/src/term/mod.rs
@@ -831,6 +831,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]