diff options
Diffstat (limited to 'alacritty/src/input.rs')
-rw-r--r-- | alacritty/src/input.rs | 55 |
1 files changed, 32 insertions, 23 deletions
diff --git a/alacritty/src/input.rs b/alacritty/src/input.rs index a3b9fdf9..7851b6e4 100644 --- a/alacritty/src/input.rs +++ b/alacritty/src/input.rs @@ -790,36 +790,45 @@ impl<T: EventListener, A: ActionContext<T>> Processor<T, A> { self.ctx.clear_selection(); let utf8_len = c.len_utf8(); - let mut char_bytes = Vec::with_capacity(utf8_len); let mut all_bytes = Vec::new(); - unsafe { - char_bytes.set_len(utf8_len); - c.encode_utf8(&mut char_bytes[..]); - } - if self.ctx.config().ui_config.alt_send_esc - && *self.ctx.received_count() == 0 - && self.ctx.modifiers().alt() - { - all_bytes.push(b'\x1b'); - } + let shift = self.ctx.modifiers().shift(); + let alt = self.ctx.modifiers().alt(); + let ctrl = self.ctx.modifiers().ctrl(); + let logo = self.ctx.modifiers().logo(); - if self.ctx.modifiers().logo() - { - // In this case, either the Hyper or Windows key is held down, in - // this case prepend with '^[[2;8~', whic is <C-S-M-Insert>. THis - // is better keybinding in Vim. - all_bytes.append(&mut vec![b'\x1b', b'[', b'2', b';', b'8', b'~']); + fn encode_extended_ctrl_char(c: char) -> bool { + return ! c.is_ascii_control() + || c == '\n' + || c == '\r' + || c == '\x07'; } - if self.ctx.modifiers().ctrl() && utf8_len > 1 { - // In this case, it's a multibyte character that also has CTRL - // down. This prepends said character with '^[[1;8H', which - // is <C-S-M-Home>. This is for even better keybinding in vim. - all_bytes.append(&mut vec![b'\x1b', b'[', b'1', b';', b'8', b'H']); + if ((shift || alt || encode_extended_ctrl_char(c)) && ctrl) || logo { + // Special, extended character code + let modifier_code = + 1 + (shift as u32) + (alt as u32) * 2 + (ctrl as u32) * 4 + (logo as u32) * 8; + + let out = format!("\x1b[{};{}u", c as u32, modifier_code); + all_bytes.append(&mut out.into_bytes()); + } else { + let mut char_bytes = Vec::with_capacity(utf8_len); + + unsafe { + char_bytes.set_len(utf8_len); + c.encode_utf8(&mut char_bytes[..]); + } + + if self.ctx.config().ui_config.alt_send_esc + && *self.ctx.received_count() == 0 + && alt + { + all_bytes.push(b'\x1b'); + } + + all_bytes.append(&mut char_bytes); } - all_bytes.append(&mut char_bytes); self.ctx.write_to_pty(all_bytes); *self.ctx.received_count() += 1; |