From 8349ead6b24c886a7ffd75f49408d45e987d0abf Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Fri, 15 Jul 2022 19:01:08 -0700 Subject: [PATCH] Add bracketed paste support --- crates/terminal/src/connection.rs | 13 ++++++++++++- crates/terminal/src/terminal.rs | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/crates/terminal/src/connection.rs b/crates/terminal/src/connection.rs index 6eed882e2d47a..0e051da17caad 100644 --- a/crates/terminal/src/connection.rs +++ b/crates/terminal/src/connection.rs @@ -7,7 +7,7 @@ use alacritty_terminal::{ event_loop::{EventLoop, Msg, Notifier}, grid::Scroll, sync::FairMutex, - term::SizeInfo, + term::{SizeInfo, TermMode}, tty::{self, setup_env}, Term, }; @@ -228,6 +228,17 @@ impl TerminalConnection { false } } + + ///Paste text into the terminal + pub fn paste(&mut self, text: &str) { + if self.term.lock().mode().contains(TermMode::BRACKETED_PASTE) { + self.write_to_pty("\x1b[200~".to_string()); + self.write_to_pty(text.replace('\x1b', "").to_string()); + self.write_to_pty("\x1b[201~".to_string()); + } else { + self.write_to_pty(text.replace("\r\n", "\r").replace('\n', "\r")); + } + } } impl Drop for TerminalConnection { diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index c94e28d6e9b66..26880258daff3 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -191,7 +191,7 @@ impl Terminal { fn paste(&mut self, _: &Paste, cx: &mut ViewContext) { if let Some(item) = cx.read_from_clipboard() { self.connection.update(cx, |connection, _| { - connection.write_to_pty(item.text().to_owned()); + connection.paste(item.text()); }) } }