From 20aa45c8781f1954de90bb23070454a9581e6969 Mon Sep 17 00:00:00 2001 From: Geert Jansen Date: Tue, 2 Jan 2018 11:32:50 -0500 Subject: Add support for set-clipboard. (#970) This allows e.g. tmux to set the clipboard via the OSC 52 escape code. --- src/ansi.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/ansi.rs') 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 -- cgit v1.2.3-54-g00ecf