summaryrefslogtreecommitdiff
path: root/src/input.rs
diff options
context:
space:
mode:
authorNathan Lilienthal <nathan@nixpulvis.com>2018-09-01 20:30:03 -0400
committerChristian Duerr <chrisduerr@users.noreply.github.com>2018-09-02 00:30:03 +0000
commit72495172c25e00799f29eb2e79fe40ddfa189866 (patch)
tree996394ed5bef5318aaf202db98076f0455b02734 /src/input.rs
parent8e8ecdd0f98dd8005cd940d19dc0a922661d64fc (diff)
downloadalacritty-72495172c25e00799f29eb2e79fe40ddfa189866.tar.gz
alacritty-72495172c25e00799f29eb2e79fe40ddfa189866.zip
Implement `ansi::ClearMode::Saved`
The clearing the screen for the `ansi::ClearMode::Saved` enum value has been implemented. This is used to clear all lines which are currently outside of the visible region but still inside the scrollback buffer. The specifications of XTerm indicate that the clearing of saved lines should only clear the saved lines and not the saved lines plus the currently visible part of the grid. Applications like `clear` send both the escape for clearing history plus the escape for clearing history when requested, so all sources seem to agree here. To allow both clearing the screen and the saved lines when a key is pressed the `process_key_bindings` method has been altered so multiple bindings can be specified. So it is now possible to execute both `^L` and `ClearHistory` with just a single binding. The `process_mouse_bindings` method has also been changed for consistency. To make sure everything works properly a test has been added which clears the history and then attempts to scroll. Since scrolling is the only way for a user to check if scrollback is available, this seems like a nice abstraction to check if there is a scrollback.
Diffstat (limited to 'src/input.rs')
-rw-r--r--src/input.rs19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/input.rs b/src/input.rs
index cccb3bb4..3c20fe36 100644
--- a/src/input.rs
+++ b/src/input.rs
@@ -69,6 +69,7 @@ pub trait ActionContext {
fn change_font_size(&mut self, delta: f32);
fn reset_font_size(&mut self);
fn scroll(&mut self, scroll: Scroll);
+ fn clear_history(&mut self);
fn hide_window(&mut self);
}
@@ -183,6 +184,9 @@ pub enum Action {
/// Scroll all the way to the bottom
ScrollToBottom,
+ /// Clear the display buffer(s) to remove history
+ ClearHistory,
+
/// Run given command
Command(String, Vec<String>),
@@ -272,6 +276,9 @@ impl Action {
Action::ScrollToBottom => {
ctx.scroll(Scroll::Bottom);
},
+ Action::ClearHistory => {
+ ctx.clear_history();
+ },
}
}
@@ -634,15 +641,16 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
///
/// Returns true if an action is executed.
fn process_key_bindings(&mut self, mods: ModifiersState, key: VirtualKeyCode) -> bool {
+ let mut has_binding = false;
for binding in self.key_bindings {
if binding.is_triggered_by(self.ctx.terminal_mode(), mods, &key) {
// binding was triggered; run the action
binding.execute(&mut self.ctx);
- return true;
+ has_binding = true;
}
}
- false
+ has_binding
}
/// Attempts to find a binding and execute its action
@@ -652,15 +660,16 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
///
/// Returns true if an action is executed.
fn process_mouse_bindings(&mut self, mods: ModifiersState, button: MouseButton) -> bool {
+ let mut has_binding = false;
for binding in self.mouse_bindings {
if binding.is_triggered_by(self.ctx.terminal_mode(), mods, &button) {
// binding was triggered; run the action
binding.execute(&mut self.ctx);
- return true;
+ has_binding = true;
}
}
- false
+ has_binding
}
}
@@ -756,6 +765,8 @@ mod tests {
}
fn reset_font_size(&mut self) {
}
+ fn clear_history(&mut self) {
+ }
fn hide_window(&mut self) {
}
}