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.
This commit is contained in:
Wez Furlong committed 2019-03-02 09:33:58 -08:00
1 parent 3ceb71026e
commit f261f079f7
3 files changed
+46

No files matched your search

+26
View File
@@ -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,
+7
View File
@@ -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,
+13
View File
@@ -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