mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-18 13:55:23 -05:00
Add support for set-clipboard. (#970)
This allows e.g. tmux to set the clipboard via the OSC 52 escape code.
This commit is contained in:
parent
b01dc062c7
commit
20aa45c878
5 changed files with 68 additions and 10 deletions
41
Cargo.lock
generated
41
Cargo.lock
generated
|
@ -1,8 +1,17 @@
|
|||
[root]
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "alacritty"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"arraydeque 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"base64 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cgmath 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"clap 2.29.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -31,14 +40,6 @@ dependencies = [
|
|||
"xdg 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "android_glue"
|
||||
version = "0.2.3"
|
||||
|
@ -73,6 +74,15 @@ dependencies = [
|
|||
"winapi 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "0.4.0"
|
||||
|
@ -103,6 +113,11 @@ name = "block"
|
|||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "bytes"
|
||||
version = "0.3.0"
|
||||
|
@ -992,6 +1007,11 @@ name = "regex-syntax"
|
|||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "safemem"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "same-file"
|
||||
version = "1.0.0"
|
||||
|
@ -1524,12 +1544,14 @@ dependencies = [
|
|||
"checksum approx 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "08abcc3b4e9339e33a3d0a5ed15d84a687350c05689d825e0f6655eef9e76a94"
|
||||
"checksum arraydeque 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "96e774cadb24c2245225280c6799793f9802b918a58a79615e9490607489a717"
|
||||
"checksum atty 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "8352656fd42c30a0c3c89d26dea01e3b77c0ab2af18230835c15e2e13cd51859"
|
||||
"checksum base64 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "229d032f1a99302697f10b27167ae6d03d49d032e6a8e2550e8d3fc13356d2b4"
|
||||
"checksum bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dead7461c1127cf637931a1e50934eb6eee8bff2f74433ac7909e9afcee04a3"
|
||||
"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
|
||||
"checksum bitflags 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1370e9fc2a6ae53aea8b7a5110edbd08836ed87c88736dfabccade1c2b44bff4"
|
||||
"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5"
|
||||
"checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf"
|
||||
"checksum block 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a"
|
||||
"checksum byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "652805b7e73fada9d85e9a6682a4abd490cb52d96aeecc12e33a0de34dfd0d23"
|
||||
"checksum bytes 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c129aff112dcc562970abb69e2508b40850dd24c274761bb50fb8a0067ba6c27"
|
||||
"checksum cargo_metadata 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "be1057b8462184f634c3a208ee35b0f935cfd94b694b26deadccd98732088d7b"
|
||||
"checksum cc 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a9b13a57efd6b30ecd6598ebdb302cca617930b5470647570468a65d12ef9719"
|
||||
|
@ -1629,6 +1651,7 @@ dependencies = [
|
|||
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
|
||||
"checksum regex 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ac6ab4e9218ade5b423358bbd2567d1617418403c7a512603630181813316322"
|
||||
"checksum regex-syntax 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad890a5eef7953f55427c50575c680c42841653abd2b028b68cd223d157f62db"
|
||||
"checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f"
|
||||
"checksum same-file 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "70a18720d745fb9ca6a041b37cb36d0b21066006b6cff8b5b360142d4b81fb60"
|
||||
"checksum semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a3186ec9e65071a2095434b1f5bb24838d4e8e130f584c790f6033c79943537"
|
||||
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
||||
|
|
|
@ -36,6 +36,7 @@ arraydeque = "0.2"
|
|||
glutin = "0.11"
|
||||
clippy = { version = "*", optional = true }
|
||||
env_logger = "0.4"
|
||||
base64 = "0.9.0"
|
||||
|
||||
[target.'cfg(any(target_os = "linux", target_os = "freebsd", target_os="dragonfly", target_os="openbsd"))'.dependencies]
|
||||
x11-dl = "2"
|
||||
|
|
23
src/ansi.rs
23
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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue