From 8b155960708a0ff551c5fc8ec65d2c3c6d12e1da Mon Sep 17 00:00:00 2001 From: Simon Dahlberg Date: Thu, 17 Jan 2019 22:42:12 +0200 Subject: [PATCH] Add config option to send or not send ESC when ALT-key is pressed --- CHANGELOG.md | 4 ++++ alacritty.yml | 3 +++ src/config/mod.rs | 10 ++++++++++ src/event.rs | 4 ++++ src/input.rs | 8 +++++++- 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ecba7bd6..cc247c79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- New `alt_send_esc` option for controlling if alt key should send escape sequences + ### Changed - All options in the configuration file are now optional diff --git a/alacritty.yml b/alacritty.yml index 50d36b42..f31f0746 100644 --- a/alacritty.yml +++ b/alacritty.yml @@ -352,6 +352,9 @@ live_config_reload: true # backend cannot be initialized. enable_experimental_conpty_backend: false +# Send ESC (\x1b) before characters when alt is pressed. +alt_send_esc: true + # Key bindings # # Key bindings are specified as a list of objects. Each binding will specify a diff --git a/src/config/mod.rs b/src/config/mod.rs index fd40776d..836fe483 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -538,6 +538,10 @@ pub struct Config { #[serde(default, deserialize_with = "failure_default")] enable_experimental_conpty_backend: bool, + /// Send escape sequences using the alt key. + #[serde(default = "default_true_bool", deserialize_with = "deserialize_true_bool")] + alt_send_esc: bool, + // TODO: DEPRECATED custom_cursor_colors: Option, @@ -1819,6 +1823,12 @@ impl Config { self.enable_experimental_conpty_backend } + /// Send escape sequences using the alt key + #[inline] + pub fn alt_send_esc(&self) -> bool { + self.alt_send_esc + } + // Update the history size, used in ref tests pub fn set_history(&mut self, history: u32) { self.scrolling.history = history; diff --git a/src/event.rs b/src/event.rs index bada4f68..5c6b71d0 100644 --- a/src/event.rs +++ b/src/event.rs @@ -293,6 +293,7 @@ pub struct Processor { pending_events: Vec, window_changes: WindowChanges, save_to_clipboard: bool, + alt_send_esc: bool, } /// Notify that the terminal was resized @@ -337,6 +338,7 @@ impl Processor { pending_events: Vec::with_capacity(4), window_changes: Default::default(), save_to_clipboard: config.selection().save_to_clipboard, + alt_send_esc: config.alt_send_esc(), } } @@ -518,6 +520,7 @@ impl Processor { key_bindings: &self.key_bindings[..], mouse_bindings: &self.mouse_bindings[..], save_to_clipboard: self.save_to_clipboard, + alt_send_esc: self.alt_send_esc, }; let mut window_is_focused = window.is_focused; @@ -573,5 +576,6 @@ impl Processor { self.mouse_bindings = config.mouse_bindings().to_vec(); self.mouse_config = config.mouse().to_owned(); self.save_to_clipboard = config.selection().save_to_clipboard; + self.alt_send_esc = config.alt_send_esc(); } } diff --git a/src/input.rs b/src/input.rs index c2473448..65b7b6ce 100644 --- a/src/input.rs +++ b/src/input.rs @@ -49,6 +49,7 @@ pub struct Processor<'a, A: 'a> { pub scrolling_config: &'a config::Scrolling, pub ctx: A, pub save_to_clipboard: bool, + pub alt_send_esc: bool, } pub trait ActionContext { @@ -742,7 +743,11 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> { c.encode_utf8(&mut bytes[..]); } - if *self.ctx.received_count() == 0 && self.ctx.last_modifiers().alt && utf8_len == 1 { + if self.alt_send_esc + && *self.ctx.received_count() == 0 + && self.ctx.last_modifiers().alt + && utf8_len == 1 + { bytes.insert(0, b'\x1b'); } @@ -977,6 +982,7 @@ mod tests { key_bindings: &config.key_bindings()[..], mouse_bindings: &config.mouse_bindings()[..], save_to_clipboard: config.selection().save_to_clipboard, + alt_send_esc: config.alt_send_esc(), }; if let Event::WindowEvent { event: WindowEvent::MouseInput { state, button, modifiers, .. }, .. } = $input {