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:
1 parent
3ceb71026e
commit
f261f079f7
3 files changed
+46
No files matched your search
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user