Add support for bracketed paste
Binding/Action execute now has access to TermMode to support bracketed paste mode.
This commit is contained in:
parent
7bf3d059c3
commit
ff5081d5e5
|
@ -243,6 +243,8 @@ pub enum Mode {
|
|||
ReportMouseClicks = 1000,
|
||||
/// ?1049
|
||||
SwapScreenAndSetRestoreCursor = 1049,
|
||||
/// ?2004
|
||||
BracketedPaste = 2004,
|
||||
}
|
||||
|
||||
impl Mode {
|
||||
|
@ -258,6 +260,7 @@ impl Mode {
|
|||
25 => Mode::ShowCursor,
|
||||
1000 => Mode::ReportMouseClicks,
|
||||
1049 => Mode::SwapScreenAndSetRestoreCursor,
|
||||
2004 => Mode::BracketedPaste,
|
||||
_ => return None
|
||||
})
|
||||
} else {
|
||||
|
|
22
src/input.rs
22
src/input.rs
|
@ -135,8 +135,8 @@ impl KeyBinding {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn execute<N: Notify>(&self, notifier: &mut N) {
|
||||
self.binding.action.execute(notifier)
|
||||
fn execute<N: Notify>(&self, notifier: &mut N, mode: &TermMode) {
|
||||
self.binding.action.execute(notifier, mode)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,8 +155,8 @@ impl MouseBinding {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn execute<N: Notify>(&self, notifier: &mut N) {
|
||||
self.binding.action.execute(notifier)
|
||||
fn execute<N: Notify>(&self, notifier: &mut N, mode: &TermMode) {
|
||||
self.binding.action.execute(notifier, mode)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,7 +174,7 @@ pub enum Action {
|
|||
|
||||
impl Action {
|
||||
#[inline]
|
||||
fn execute<N: Notify>(&self, notifier: &mut N) {
|
||||
fn execute<N: Notify>(&self, notifier: &mut N, mode: &TermMode) {
|
||||
match *self {
|
||||
Action::Esc(ref s) => notifier.notify(s.clone().into_bytes()),
|
||||
Action::Paste | Action::PasteSelection => {
|
||||
|
@ -183,7 +183,13 @@ impl Action {
|
|||
clip.load_selection()
|
||||
.map(|contents| {
|
||||
println!("got contents");
|
||||
notifier.notify(contents.into_bytes())
|
||||
if mode.contains(mode::BRACKETED_PASTE) {
|
||||
notifier.notify("\x1b[200~".as_bytes());
|
||||
notifier.notify(contents.into_bytes());
|
||||
notifier.notify("\x1b[201~".as_bytes());
|
||||
} else {
|
||||
notifier.notify(contents.into_bytes());
|
||||
}
|
||||
})
|
||||
.unwrap_or_else(|err| {
|
||||
err_println!("Error getting clipboard contents: {}", err);
|
||||
|
@ -410,7 +416,7 @@ impl Processor {
|
|||
for binding in bindings {
|
||||
if binding.is_triggered_by(&mode, &mods, &key) {
|
||||
// binding was triggered; run the action
|
||||
binding.execute(notifier);
|
||||
binding.execute(notifier, &mode);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -436,7 +442,7 @@ impl Processor {
|
|||
for binding in bindings {
|
||||
if binding.is_triggered_by(&mode, &mods, &button) {
|
||||
// binding was triggered; run the action
|
||||
binding.execute(notifier);
|
||||
binding.execute(notifier, &mode);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -164,6 +164,7 @@ pub mod mode {
|
|||
const APP_CURSOR = 0b00000010,
|
||||
const APP_KEYPAD = 0b00000100,
|
||||
const MOUSE_REPORT_CLICK = 0b00001000,
|
||||
const BRACKETED_PASTE = 0b00010000,
|
||||
const ANY = 0b11111111,
|
||||
const NONE = 0b00000000,
|
||||
}
|
||||
|
@ -838,6 +839,7 @@ impl ansi::Handler for Term {
|
|||
ansi::Mode::ShowCursor => self.mode.insert(mode::SHOW_CURSOR),
|
||||
ansi::Mode::CursorKeys => self.mode.insert(mode::APP_CURSOR),
|
||||
ansi::Mode::ReportMouseClicks => self.mode.insert(mode::MOUSE_REPORT_CLICK),
|
||||
ansi::Mode::BracketedPaste => self.mode.insert(mode::BRACKETED_PASTE),
|
||||
_ => {
|
||||
debug_println!(".. ignoring set_mode");
|
||||
}
|
||||
|
@ -852,6 +854,7 @@ impl ansi::Handler for Term {
|
|||
ansi::Mode::ShowCursor => self.mode.remove(mode::SHOW_CURSOR),
|
||||
ansi::Mode::CursorKeys => self.mode.remove(mode::APP_CURSOR),
|
||||
ansi::Mode::ReportMouseClicks => self.mode.remove(mode::MOUSE_REPORT_CLICK),
|
||||
ansi::Mode::BracketedPaste => self.mode.remove(mode::BRACKETED_PASTE),
|
||||
_ => {
|
||||
debug_println!(".. ignoring unset_mode");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue