1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-18 13:55:23 -05:00

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.
This commit is contained in:
Christian Duerr 2018-03-10 20:24:10 +01:00 committed by Joe Wilm
parent d9be2d2d88
commit e7a32b589f
7 changed files with 108 additions and 6 deletions

View file

@ -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.

View file

@ -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.

View file

@ -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)),
}))

View file

@ -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()

View file

@ -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 {

View file

@ -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();
},
}
}

View file

@ -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]