summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeert Jansen <geertj@gmail.com>2018-01-02 11:32:50 -0500
committerJoe Wilm <jwilm@users.noreply.github.com>2018-01-02 08:32:50 -0800
commit20aa45c8781f1954de90bb23070454a9581e6969 (patch)
tree637fa48fa5493d14e191c1f5e26779eb7eec60e0 /src
parentb01dc062c704ae3163ca6272dab5d4ec193430a6 (diff)
downloadalacritty-20aa45c8781f1954de90bb23070454a9581e6969.tar.gz
alacritty-20aa45c8781f1954de90bb23070454a9581e6969.zip
Add support for set-clipboard. (#970)
This allows e.g. tmux to set the clipboard via the OSC 52 escape code.
Diffstat (limited to 'src')
-rw-r--r--src/ansi.rs23
-rw-r--r--src/lib.rs1
-rw-r--r--src/term/mod.rs12
3 files changed, 35 insertions, 1 deletions
diff --git a/src/ansi.rs b/src/ansi.rs
index 3d66b497..8ff7d06b 100644
--- a/src/ansi.rs
+++ b/src/ansi.rs
@@ -18,7 +18,7 @@ use std::ops::Range;
use std::str;
use vte;
-
+use base64;
use index::{Column, Line, Contains};
use ::{MouseCursor, Rgb};
@@ -342,6 +342,9 @@ pub trait Handler {
/// Reset an indexed color to original value
fn reset_color(&mut self, usize) {}
+ /// Set the clipboard
+ fn set_clipboard(&mut self, &str) {}
+
/// Run the dectest routine
fn dectest(&mut self) {}
}
@@ -820,6 +823,24 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W>
}
}
+ // Set clipboard
+ b"52" => {
+ if params.len() < 3 {
+ return unhandled!();
+ }
+
+ match params[2] {
+ b"?" => unhandled!(),
+ selection => {
+ if let Ok(string) = base64::decode(selection) {
+ if let Ok(utf8_string) = str::from_utf8(&string) {
+ self.handler.set_clipboard(utf8_string);
+ }
+ }
+ }
+ }
+ }
+
// Reset color index
b"104" => {
// Reset all color indexes when no parameters are given
diff --git a/src/lib.rs b/src/lib.rs
index 1f3fcc96..cb0abb14 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -52,6 +52,7 @@ extern crate serde_yaml;
extern crate unicode_width;
extern crate vte;
extern crate xdg;
+extern crate base64;
#[macro_use]
pub mod macros;
diff --git a/src/term/mod.rs b/src/term/mod.rs
index 72d97ed9..e43ea7b6 100644
--- a/src/term/mod.rs
+++ b/src/term/mod.rs
@@ -29,6 +29,7 @@ use index::{self, Point, Column, Line, Linear, IndexRange, Contains, RangeInclus
use selection::{self, Span, Selection};
use config::{Config, VisualBellAnimation};
use {MouseCursor, Rgb};
+use copypasta::{Clipboard, Load, Store};
pub mod cell;
pub mod color;
@@ -1673,6 +1674,17 @@ impl ansi::Handler for Term {
self.color_modified[index] = false;
}
+ /// Set the clipboard
+ #[inline]
+ fn set_clipboard(&mut self, string: &str)
+ {
+ Clipboard::new()
+ .and_then(|mut clipboard| clipboard.store_primary(string))
+ .unwrap_or_else(|err| {
+ warn!("Error storing selection to clipboard. {}", err);
+ });
+ }
+
#[inline]
fn clear_screen(&mut self, mode: ansi::ClearMode) {
trace!("clear_screen: {:?}", mode);