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

Add keybinding action for clearing warns/errors

Since running `clear` inside of tmux doesn't actually clear any part of
the screen, but just resets the scrolling region, the warning and error
notices can't be removed without quitting tmux or Alacritty.

As a solution, a new action `ClearLogNotice` has been added which has
been bound to Ctrl+L by default. As a result, Ctrl+L can be used inside
of tmux to remove the messages, even though tmux doesn't clear the
screen.

This fixes #1811.
This commit is contained in:
Christian Duerr 2018-11-19 08:33:48 +00:00 committed by GitHub
parent e429b8dfdd
commit 42d8989916
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 38 additions and 10 deletions

View file

@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- Option for evenly spreading extra padding around the terminal (`window.dynamic_padding`) - Option for evenly spreading extra padding around the terminal (`window.dynamic_padding`)
- Display notice about errors and warnings inside Alacritty
- Log all messages to both stderr and a log file in the system's temporary directory
- New configuration option `persistent_logging` and CLI flag `--persistent-logging`,
for keeping the log file after closing Alacritty
- `ClearLogNotice` action for removing the warning and error message
### Changed ### Changed
@ -31,10 +36,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- New `mouse.url.modifiers` option to specify keyboard modifiers for opening URLs on click - New `mouse.url.modifiers` option to specify keyboard modifiers for opening URLs on click
- Binaries for macOS, Windows and Debian-based systems are now published with GitHub releases - Binaries for macOS, Windows and Debian-based systems are now published with GitHub releases
- The keys F16-F24 have been added as options for key bindings - The keys F16-F24 have been added as options for key bindings
- Display notice about errors and warnings inside Alacritty
- Log all messages to both stderr and a log file in the system's temporary directory
- New configuration option `persistent_logging` and CLI flag `--persistent-logging`,
for keeping the log file after closing Alacritty
### Changed ### Changed

View file

@ -369,6 +369,7 @@ live_config_reload: true
# - ClearHistory # - ClearHistory
# - Hide # - Hide
# - Quit # - Quit
# - ClearLogNotice
# #
# Values for `command`: # Values for `command`:
# The `command` field must be a map containing a `program` string and # The `command` field must be a map containing a `program` string and
@ -393,6 +394,8 @@ key_bindings:
- { key: Key0, mods: Control, action: ResetFontSize } - { key: Key0, mods: Control, action: ResetFontSize }
- { key: Equals, mods: Control, action: IncreaseFontSize } - { key: Equals, mods: Control, action: IncreaseFontSize }
- { key: Subtract, mods: Control, action: DecreaseFontSize } - { key: Subtract, mods: Control, action: DecreaseFontSize }
- { key: L, mods: Control, action: ClearLogNotice }
- { key: L, mods: Control, chars: "\x0c" }
- { key: Home, chars: "\x1bOH", mode: AppCursor } - { key: Home, chars: "\x1bOH", mode: AppCursor }
- { key: Home, chars: "\x1b[H", mode: ~AppCursor } - { key: Home, chars: "\x1b[H", mode: ~AppCursor }
- { key: End, chars: "\x1bOF", mode: AppCursor } - { key: End, chars: "\x1bOF", mode: AppCursor }

View file

@ -366,6 +366,7 @@ live_config_reload: true
# - ClearHistory # - ClearHistory
# - Hide # - Hide
# - Quit # - Quit
# - ClearLogNotice
# #
# Values for `command`: # Values for `command`:
# The `command` field must be a map containing a `program` string and # The `command` field must be a map containing a `program` string and
@ -396,6 +397,8 @@ key_bindings:
- { key: Minus, mods: Command, action: DecreaseFontSize } - { key: Minus, mods: Command, action: DecreaseFontSize }
- { key: K, mods: Command, action: ClearHistory } - { key: K, mods: Command, action: ClearHistory }
- { key: K, mods: Command, chars: "\x0c" } - { key: K, mods: Command, chars: "\x0c" }
- { key: L, mods: Control, action: ClearLogNotice }
- { key: L, mods: Control, chars: "\x0c" }
- { key: PageUp, mods: Shift, chars: "\x1b[5;2~" } - { key: PageUp, mods: Shift, chars: "\x1b[5;2~" }
- { key: PageUp, mods: Control, chars: "\x1b[5;5~" } - { key: PageUp, mods: Control, chars: "\x1b[5;5~" }
- { key: PageUp, chars: "\x1b[5~" } - { key: PageUp, chars: "\x1b[5~" }

View file

@ -343,6 +343,7 @@ shell:
# - ClearHistory # - ClearHistory
# - Hide # - Hide
# - Quit # - Quit
# - ClearLogNotice
# #
# Values for `command`: # Values for `command`:
# The `command` field must be a map containing a `program` string and # The `command` field must be a map containing a `program` string and
@ -365,6 +366,8 @@ key_bindings:
- { key: Key0, mods: Control, action: ResetFontSize } - { key: Key0, mods: Control, action: ResetFontSize }
- { key: Equals, mods: Control, action: IncreaseFontSize } - { key: Equals, mods: Control, action: IncreaseFontSize }
- { key: Subtract, mods: Control, action: DecreaseFontSize } - { key: Subtract, mods: Control, action: DecreaseFontSize }
- { key: L, mods: Control, action: ClearLogNotice }
- { key: L, mods: Control, chars: "\x0c" }
- { key: Home, chars: "\x1bOH", mode: AppCursor } - { key: Home, chars: "\x1bOH", mode: AppCursor }
- { key: Home, chars: "\x1b[H", mode: ~AppCursor } - { key: Home, chars: "\x1b[H", mode: ~AppCursor }
- { key: End, chars: "\x1bOF", mode: AppCursor } - { key: End, chars: "\x1bOF", mode: AppCursor }

View file

@ -746,7 +746,7 @@ impl<'a> de::Deserialize<'a> for ActionWrapper {
fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result { fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("Paste, Copy, PasteSelection, IncreaseFontSize, DecreaseFontSize, \ f.write_str("Paste, Copy, PasteSelection, IncreaseFontSize, DecreaseFontSize, \
ResetFontSize, ScrollPageUp, ScrollPageDown, ScrollToTop, \ ResetFontSize, ScrollPageUp, ScrollPageDown, ScrollToTop, \
ScrollToBottom, ClearHistory, Hide, or Quit") ScrollToBottom, ClearHistory, Hide, ClearLogNotice or Quit")
} }
fn visit_str<E>(self, value: &str) -> ::std::result::Result<ActionWrapper, E> fn visit_str<E>(self, value: &str) -> ::std::result::Result<ActionWrapper, E>
@ -766,6 +766,7 @@ impl<'a> de::Deserialize<'a> for ActionWrapper {
"ClearHistory" => Action::ClearHistory, "ClearHistory" => Action::ClearHistory,
"Hide" => Action::Hide, "Hide" => Action::Hide,
"Quit" => Action::Quit, "Quit" => Action::Quit,
"ClearLogNotice" => Action::ClearLogNotice,
_ => return Err(E::invalid_value(Unexpected::Str(value), &self)), _ => return Err(E::invalid_value(Unexpected::Str(value), &self)),
})) }))
} }

View file

@ -171,6 +171,11 @@ impl<'a, N: Notify + 'a> input::ActionContext for ActionContext<'a, N> {
fn hide_window(&mut self) { fn hide_window(&mut self) {
self.window_changes.hide = true; self.window_changes.hide = true;
} }
#[inline]
fn clear_log(&mut self) {
self.terminal.clear_log();
}
} }
/// The ActionContext can't really have direct access to the Window /// The ActionContext can't really have direct access to the Window

View file

@ -76,6 +76,7 @@ pub trait ActionContext {
fn clear_history(&mut self); fn clear_history(&mut self);
fn hide_window(&mut self); fn hide_window(&mut self);
fn url(&self, _: Point<usize>) -> Option<String>; fn url(&self, _: Point<usize>) -> Option<String>;
fn clear_log(&mut self);
} }
/// Describes a state and action to take in that state /// Describes a state and action to take in that state
@ -200,6 +201,9 @@ pub enum Action {
/// Quits Alacritty. /// Quits Alacritty.
Quit, Quit,
/// Clears warning and error notices.
ClearLogNotice,
} }
impl Action { impl Action {
@ -292,6 +296,9 @@ impl Action {
Action::ClearHistory => { Action::ClearHistory => {
ctx.clear_history(); ctx.clear_history();
}, },
Action::ClearLogNotice => {
ctx.clear_log();
}
} }
} }
@ -885,6 +892,7 @@ mod tests {
} }
fn hide_window(&mut self) { fn hide_window(&mut self) {
} }
fn clear_log(&mut self) {}
} }
macro_rules! test_clickstate { macro_rules! test_clickstate {

View file

@ -877,6 +877,14 @@ impl Term {
&self.grid.selection &self.grid.selection
} }
/// Clear displayed errors and warnings.
pub fn clear_log(&mut self) {
if let Some(ref mut logger_proxy) = self.logger_proxy {
logger_proxy.clear();
}
}
pub fn selection_mut(&mut self) -> &mut Option<Selection> { pub fn selection_mut(&mut self) -> &mut Option<Selection> {
&mut self.grid.selection &mut self.grid.selection
} }
@ -1831,11 +1839,7 @@ impl ansi::Handler for Term {
} }
}, },
ansi::ClearMode::All => { ansi::ClearMode::All => {
// Clear displayed errors and warnings self.clear_log();
if let Some(ref mut logger_proxy) = self.logger_proxy {
logger_proxy.clear();
}
self.grid.region_mut(..).each(|c| c.reset(&template)); self.grid.region_mut(..).each(|c| c.reset(&template));
}, },
ansi::ClearMode::Above => { ansi::ClearMode::Above => {