aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2018-03-10 20:24:10 +0100
committerJoe Wilm <jwilm@users.noreply.github.com>2018-03-15 12:27:12 -0700
commite7a32b589f6701667bb7c0135491b6800f8716e6 (patch)
tree754efd9bf97f8fc13abc36af8722b2c2cfddd221
parentd9be2d2d88689d31d08f9218f8493635d0724860 (diff)
downloadalacritty-e7a32b589f6701667bb7c0135491b6800f8716e6.tar.gz
alacritty-e7a32b589f6701667bb7c0135491b6800f8716e6.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.
-rw-r--r--alacritty.yml13
-rw-r--r--alacritty_macos.yml13
-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
7 files changed, 108 insertions, 6 deletions
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<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 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<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 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<String>),
@@ -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]