From f261f079f7dd92ecb6823c81a3404b7ea9d1788a Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 2 Mar 2019 08:23:18 -0800 Subject: [PATCH] lift clipboard hotkeys up to gui layer My original idea was that I would centralize of the key binding logic in the terminalstate, but this places a bit of a burden on the TerminalHost portion of the interface. In particular: when running a multiplexer server we may be headless or have multiple heads. In that scenario we want the terminal to be backed by a virtualized screen, and that means removing the direct callback to access eg: the host clipboard. This diff is the first of a couple that have the goal of removing those sorts of dependencies. --- src/gliumwindows.rs | 26 ++++++++++++++++++++++++++ src/xwindows/xwin.rs | 7 +++++++ term/src/terminalstate.rs | 13 +++++++++++++ 3 files changed, 46 insertions(+) diff --git a/src/gliumwindows.rs b/src/gliumwindows.rs index e15fe67e9..66eee08c0 100644 --- a/src/gliumwindows.rs +++ b/src/gliumwindows.rs @@ -638,6 +638,32 @@ impl GliumTerminalWindow { return Ok(()); } + if mods == KeyModifiers::ALT + && (key == KeyCode::Char('\r') + || key == KeyCode::Char('\n') + || key == KeyCode::Enter) + { + self.host.toggle_full_screen(); + return Ok(()); + } + + if cfg!(target_os = "macos") + && mods == KeyModifiers::SUPER + && key == KeyCode::Char('c') + { + // Nominally copy, but that is implicit, so NOP + return Ok(()); + } + if (cfg!(target_os = "macos") + && mods == KeyModifiers::SUPER + && key == KeyCode::Char('v')) + || (mods == KeyModifiers::SHIFT && key == KeyCode::Insert) + { + tab.terminal() + .send_paste(&self.host.get_clipboard()?, &mut *tab.pty())?; + return Ok(()); + } + tab.terminal().key_down( key, mods, diff --git a/src/xwindows/xwin.rs b/src/xwindows/xwin.rs index dd8aa3aa7..17bdf9eb8 100644 --- a/src/xwindows/xwin.rs +++ b/src/xwindows/xwin.rs @@ -240,6 +240,13 @@ impl X11TerminalWindow { self.host.with_window(|win| win.spawn_tab().map(|_| ())); return Ok(()); } + + if mods == KeyModifiers::SHIFT && key == KeyCode::Insert { + tab.terminal() + .send_paste(&self.host.get_clipboard()?, &mut *tab.pty())?; + return Ok(()); + } + tab.terminal().key_down( code, mods, diff --git a/term/src/terminalstate.rs b/term/src/terminalstate.rs index 73c12a14a..aea54304d 100644 --- a/term/src/terminalstate.rs +++ b/term/src/terminalstate.rs @@ -671,6 +671,19 @@ impl TerminalState { Ok(()) } + /// Send text to the terminal that is the result of pasting. + /// If bracketed paste mode is enabled, the paste is enclosed + /// in the bracketing, otherwise it is fed to the pty as-is. + pub fn send_paste(&mut self, text: &str, writer: &mut std::io::Write) -> Result<(), Error> { + if self.bracketed_paste { + let buf = format!("\x1b[200~{}\x1b[201~", text); + write_all(writer, buf.as_bytes())?; + } else { + write_all(writer, text.as_bytes())?; + } + Ok(()) + } + /// Processes a key_down event generated by the gui/render layer /// that is embedding the Terminal. This method translates the /// keycode into a sequence of bytes to send to the slave end