summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Chibisov <contact@kchibisov.com>2020-06-07 00:33:20 +0300
committerGitHub <noreply@github.com>2020-06-07 00:33:20 +0300
commit4f5f8412966626771043bd3a90800124fed44ebe (patch)
tree264e8ffa917324b5e30b7532fcf7d773382012c3
parent7aafbb757d485c5ff065324464dde8b5322cdd92 (diff)
downloadalacritty-4f5f8412966626771043bd3a90800124fed44ebe.tar.gz
alacritty-4f5f8412966626771043bd3a90800124fed44ebe.zip
Remove copypasta dependency from alacritty_terminal
-rw-r--r--Cargo.lock2
-rw-r--r--alacritty/Cargo.toml5
-rw-r--r--alacritty/src/clipboard.rs (renamed from alacritty_terminal/src/clipboard.rs)13
-rw-r--r--alacritty/src/event.rs26
-rw-r--r--alacritty/src/input.rs23
-rw-r--r--alacritty/src/main.rs10
-rw-r--r--alacritty_terminal/Cargo.toml5
-rw-r--r--alacritty_terminal/src/ansi.rs12
-rw-r--r--alacritty_terminal/src/event.rs25
-rw-r--r--alacritty_terminal/src/lib.rs1
-rw-r--r--alacritty_terminal/src/selection.rs3
-rw-r--r--alacritty_terminal/src/term/mod.rs73
-rw-r--r--alacritty_terminal/src/vi_mode.rs3
-rw-r--r--alacritty_terminal/tests/ref.rs3
14 files changed, 118 insertions, 86 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 8864e536..3db5142b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -19,6 +19,7 @@ version = "0.5.0-dev"
dependencies = [
"alacritty_terminal 0.5.0-dev",
"clap 2.33.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "copypasta 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"embed-resource 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -47,7 +48,6 @@ version = "0.5.0-dev"
dependencies = [
"base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "copypasta 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"font 0.1.0",
"libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/alacritty/Cargo.toml b/alacritty/Cargo.toml
index 3a352f1e..184f2102 100644
--- a/alacritty/Cargo.toml
+++ b/alacritty/Cargo.toml
@@ -22,6 +22,7 @@ notify = "4"
parking_lot = "0.10.2"
font = { path = "../font" }
urlocator = "0.1.3"
+copypasta = { version = "0.7.0", default-features = false }
[build-dependencies]
gl_generator = "0.14.0"
@@ -48,8 +49,8 @@ embed-resource = "1.3"
[features]
default = ["wayland", "x11", "winpty"]
-x11 = ["alacritty_terminal/x11"]
-wayland = ["alacritty_terminal/wayland"]
+x11 = ["copypasta/x11"]
+wayland = ["copypasta/wayland"]
winpty = ["alacritty_terminal/winpty"]
# Enabling this feature makes shaders automatically reload when changed
live-shader-reload = []
diff --git a/alacritty_terminal/src/clipboard.rs b/alacritty/src/clipboard.rs
index 8a045bf7..df0b1c78 100644
--- a/alacritty_terminal/src/clipboard.rs
+++ b/alacritty/src/clipboard.rs
@@ -3,6 +3,9 @@ use std::ffi::c_void;
use log::{debug, warn};
+use alacritty_terminal::term::ClipboardType;
+
+#[cfg(any(test, not(any(feature = "x11", target_os = "macos", windows))))]
use copypasta::nop_clipboard::NopClipboardContext;
#[cfg(all(not(any(target_os = "macos", windows)), feature = "wayland"))]
use copypasta::wayland_clipboard;
@@ -47,7 +50,9 @@ impl Clipboard {
return Self::new_nop();
}
- // Use for tests and ref-tests.
+ /// Used for tests and to handle missing clipboard provider when built without the `x11`
+ /// feature.
+ #[cfg(any(test, not(any(feature = "x11", target_os = "macos", windows))))]
pub fn new_nop() -> Self {
Self { clipboard: Box::new(NopClipboardContext::new().unwrap()), selection: None }
}
@@ -62,12 +67,6 @@ impl Default for Clipboard {
}
}
-#[derive(Debug)]
-pub enum ClipboardType {
- Clipboard,
- Selection,
-}
-
impl Clipboard {
pub fn store(&mut self, ty: ClipboardType, text: impl Into<String>) {
let clipboard = match (ty, &mut self.selection) {
diff --git a/alacritty/src/event.rs b/alacritty/src/event.rs
index 21149ad0..4e2a0578 100644
--- a/alacritty/src/event.rs
+++ b/alacritty/src/event.rs
@@ -27,7 +27,6 @@ use serde_json as json;
use font::set_font_smoothing;
use font::{self, Size};
-use alacritty_terminal::clipboard::ClipboardType;
use alacritty_terminal::config::Font;
use alacritty_terminal::config::LOG_TARGET_CONFIG;
use alacritty_terminal::event::OnResize;
@@ -38,12 +37,13 @@ use alacritty_terminal::message_bar::{Message, MessageBuffer};
use alacritty_terminal::selection::{Selection, SelectionType};
use alacritty_terminal::sync::FairMutex;
use alacritty_terminal::term::cell::Cell;
-use alacritty_terminal::term::{SizeInfo, Term, TermMode};
+use alacritty_terminal::term::{ClipboardType, SizeInfo, Term, TermMode};
#[cfg(not(windows))]
use alacritty_terminal::tty;
use alacritty_terminal::util::{limit, start_daemon};
use crate::cli::Options;
+use crate::clipboard::Clipboard;
use crate::config;
use crate::config::Config;
use crate::display::Display;
@@ -68,6 +68,7 @@ impl DisplayUpdate {
pub struct ActionContext<'a, N, T> {
pub notifier: &'a mut N,
pub terminal: &'a mut Term<T>,
+ pub clipboard: &'a mut Clipboard,
pub size_info: &'a mut SizeInfo,
pub mouse: &'a mut Mouse,
pub received_count: &'a mut usize,
@@ -111,7 +112,7 @@ impl<'a, N: Notify + 'a, T: EventListener> input::ActionContext<T> for ActionCon
fn copy_selection(&mut self, ty: ClipboardType) {
if let Some(selected) = self.terminal.selection_to_string() {
if !selected.is_empty() {
- self.terminal.clipboard().store(ty, selected);
+ self.clipboard.store(ty, selected);
}
}
}
@@ -281,6 +282,10 @@ impl<'a, N: Notify + 'a, T: EventListener> input::ActionContext<T> for ActionCon
self.urls
}
+ fn clipboard(&mut self) -> &mut Clipboard {
+ self.clipboard
+ }
+
/// Spawn URL launcher when clicking on URLs.
fn launch_url(&self, url: Url) {
if self.mouse.block_url_launcher {
@@ -358,6 +363,7 @@ pub struct Processor<N> {
mouse: Mouse,
received_count: usize,
suppress_chars: bool,
+ clipboard: Clipboard,
modifiers: ModifiersState,
config: Config,
message_buffer: MessageBuffer,
@@ -376,6 +382,11 @@ impl<N: Notify + OnResize> Processor<N> {
config: Config,
display: Display,
) -> Processor<N> {
+ #[cfg(not(any(target_os = "macos", windows)))]
+ let clipboard = Clipboard::new(display.window.wayland_display());
+ #[cfg(any(target_os = "macos", windows))]
+ let clipboard = Clipboard::new();
+
Processor {
notifier,
mouse: Default::default(),
@@ -387,6 +398,7 @@ impl<N: Notify + OnResize> Processor<N> {
message_buffer,
display,
event_queue: Vec::new(),
+ clipboard,
}
}
@@ -472,6 +484,7 @@ impl<N: Notify + OnResize> Processor<N> {
terminal: &mut terminal,
notifier: &mut self.notifier,
mouse: &mut self.mouse,
+ clipboard: &mut self.clipboard,
size_info: &mut self.display.size_info,
received_count: &mut self.received_count,
suppress_chars: &mut self.suppress_chars,
@@ -569,6 +582,13 @@ impl<N: Notify + OnResize> Processor<N> {
processor.ctx.display_update_pending.message_buffer = true;
processor.ctx.terminal.dirty = true;
},
+ Event::ClipboardStore(clipboard_type, content) => {
+ processor.ctx.clipboard.store(clipboard_type, content);
+ },
+ Event::ClipboardLoad(clipboard_type, format) => {
+ let text = format(processor.ctx.clipboard.load(clipboard_type).as_str());
+ processor.ctx.write_to_pty(text.into_bytes());
+ },
Event::MouseCursorDirty => processor.reset_mouse_cursor(),
Event::Exit => (),
},
diff --git a/alacritty/src/input.rs b/alacritty/src/input.rs
index 9109aa4f..2025f108 100644
--- a/alacritty/src/input.rs
+++ b/alacritty/src/input.rs
@@ -21,17 +21,17 @@ use glutin::platform::macos::EventLoopWindowTargetExtMacOS;
use glutin::window::CursorIcon;
use alacritty_terminal::ansi::{ClearMode, Handler};
-use alacritty_terminal::clipboard::ClipboardType;
use alacritty_terminal::event::{Event, EventListener};
use alacritty_terminal::grid::Scroll;
use alacritty_terminal::index::{Column, Line, Point, Side};
use alacritty_terminal::message_bar::{self, Message};
use alacritty_terminal::selection::SelectionType;
use alacritty_terminal::term::mode::TermMode;
-use alacritty_terminal::term::{SizeInfo, Term};
+use alacritty_terminal::term::{ClipboardType, SizeInfo, Term};
use alacritty_terminal::util::start_daemon;
use alacritty_terminal::vi_mode::ViMotion;
+use crate::clipboard::Clipboard;
use crate::config::{Action, Binding, Config, Key, ViAction};
use crate::event::{ClickState, Mouse};
use crate::url::{Url, Urls};
@@ -77,6 +77,7 @@ pub trait ActionContext<T: EventListener> {
fn message(&self) -> Option<&Message>;
fn config(&self) -> &Config;
fn event_loop(&self) -> &EventLoopWindowTarget<Event>;
+ fn clipboard(&mut self) -> &mut Clipboard;
fn urls(&self) -> &Urls;
fn launch_url(&self, url: Url);
fn mouse_mode(&self) -> bool;
@@ -127,11 +128,11 @@ impl<T: EventListener> Execute<T> for Action {
#[cfg(not(any(target_os = "macos", windows)))]
Action::CopySelection => ctx.copy_selection(ClipboardType::Selection),
Action::Paste => {
- let text = ctx.terminal_mut().clipboard().load(ClipboardType::Clipboard);
+ let text = ctx.clipboard().load(ClipboardType::Clipboard);
paste(ctx, &text);
},
Action::PasteSelection => {
- let text = ctx.terminal_mut().clipboard().load(ClipboardType::Selection);
+ let text = ctx.clipboard().load(ClipboardType::Selection);
paste(ctx, &text);
},
Action::Command(ref program) => {
@@ -881,14 +882,14 @@ mod tests {
};
use glutin::event_loop::EventLoopWindowTarget;
- use alacritty_terminal::clipboard::{Clipboard, ClipboardType};
use alacritty_terminal::event::{Event as TerminalEvent, EventListener};
use alacritty_terminal::grid::Scroll;
use alacritty_terminal::index::{Point, Side};
use alacritty_terminal::message_bar::{Message, MessageBuffer};
use alacritty_terminal::selection::{Selection, SelectionType};
- use alacritty_terminal::term::{SizeInfo, Term, TermMode};
+ use alacritty_terminal::term::{ClipboardType, SizeInfo, Term, TermMode};
+ use crate::clipboard::Clipboard;
use crate::config::{ClickHandler, Config};
use crate::event::{ClickState, Mouse};
use crate::url::{Url, Urls};
@@ -909,6 +910,7 @@ mod tests {
pub selection: &'a mut Option<Selection>,
pub size_info: &'a SizeInfo,
pub mouse: &'a mut Mouse,
+ pub clipboard: &'a mut Clipboard,
pub message_buffer: &'a mut MessageBuffer,
pub received_count: usize,
pub suppress_chars: bool,
@@ -1020,6 +1022,10 @@ mod tests {
unimplemented!();
}
+ fn clipboard(&mut self) -> &mut Clipboard {
+ self.clipboard
+ }
+
fn launch_url(&self, _: Url) {
unimplemented!();
}
@@ -1057,7 +1063,9 @@ mod tests {
dpr: 1.0,
};
- let mut terminal = Term::new(&cfg, &size, Clipboard::new_nop(), MockEventProxy);
+ let mut clipboard = Clipboard::new_nop();
+
+ let mut terminal = Term::new(&cfg, &size, MockEventProxy);
let mut mouse = Mouse::default();
mouse.click_state = $initial_state;
@@ -1071,6 +1079,7 @@ mod tests {
selection: &mut selection,
mouse: &mut mouse,
size_info: &size,
+ clipboard: &mut clipboard,
received_count: 0,
suppress_chars: false,
modifiers: Default::default(),
diff --git a/alacritty/src/main.rs b/alacritty/src/main.rs
index a7f53c2a..9587aec3 100644
--- a/alacritty/src/main.rs
+++ b/alacritty/src/main.rs
@@ -23,7 +23,6 @@ use log::{error, info};
#[cfg(windows)]
use winapi::um::wincon::{AttachConsole, FreeConsole, ATTACH_PARENT_PROCESS};
-use alacritty_terminal::clipboard::Clipboard;
use alacritty_terminal::event::Event;
use alacritty_terminal::event_loop::{self, EventLoop, Msg};
#[cfg(target_os = "macos")]
@@ -35,6 +34,7 @@ use alacritty_terminal::term::Term;
use alacritty_terminal::tty;
mod cli;
+mod clipboard;
mod config;
mod cursor;
mod display;
@@ -136,18 +136,12 @@ fn run(window_event_loop: GlutinEventLoop<Event>, config: Config) -> Result<(),
info!("PTY dimensions: {:?} x {:?}", display.size_info.lines(), display.size_info.cols());
- // Create new native clipboard.
- #[cfg(not(any(target_os = "macos", windows)))]
- let clipboard = Clipboard::new(display.window.wayland_display());
- #[cfg(any(target_os = "macos", windows))]
- let clipboard = Clipboard::new();
-
// Create the terminal.
//
// This object contains all of the state about what's being displayed. It's
// wrapped in a clonable mutex since both the I/O loop and display need to
// access it.
- let terminal = Term::new(&config, &display.size_info, clipboard, event_proxy.clone());
+ let terminal = Term::new(&config, &display.size_info, event_proxy.clone());
let terminal = Arc::new(FairMutex::new(terminal));
// Create the PTY.
diff --git a/alacritty_terminal/Cargo.toml b/alacritty_terminal/Cargo.toml
index f6f0f365..04eba7e5 100644
--- a/alacritty_terminal/Cargo.toml
+++ b/alacritty_terminal/Cargo.toml
@@ -22,7 +22,6 @@ log = "0.4"
unicode-width = "0.1"
base64 = "0.11.0"
terminfo = "0.7.1"
-copypasta = { version = "0.7.0", default-features = false }
[target.'cfg(unix)'.dependencies]
nix = "0.17.0"
@@ -42,9 +41,7 @@ mio-anonymous-pipes = "0.1"
objc = "0.2.2"
[features]
-default = ["x11", "wayland", "winpty"]
-x11 = ["copypasta/x11"]
-wayland = ["copypasta/wayland"]
+default = ["winpty"]
nightly = []
bench = []
diff --git a/alacritty_terminal/src/ansi.rs b/alacritty_terminal/src/ansi.rs
index fe0cc162..619b1d39 100644
--- a/alacritty_terminal/src/ansi.rs
+++ b/alacritty_terminal/src/ansi.rs
@@ -307,11 +307,11 @@ pub trait Handler {
/// Reset an indexed color to original value.
fn reset_color(&mut self, _: usize) {}
- /// Set the clipboard.
- fn set_clipboard(&mut self, _: u8, _: &[u8]) {}
+ /// Store data into clipboard.
+ fn clipboard_store(&mut self, _: u8, _: &[u8]) {}
- /// Write clipboard data to child.
- fn write_clipboard<W: io::Write>(&mut self, _: u8, _: &mut W, _: &str) {}
+ /// Load data from clipboard.
+ fn clipboard_load(&mut self, _: u8, _: &str) {}
/// Run the decaln routine.
fn decaln(&mut self) {}
@@ -892,8 +892,8 @@ where
let clipboard = params[1].get(0).unwrap_or(&b'c');
match params[2] {
- b"?" => self.handler.write_clipboard(*clipboard, writer, terminator),
- base64 => self.handler.set_clipboard(*clipboard, base64),
+ b"?" => self.handler.clipboard_load(*clipboard, terminator),
+ base64 => self.handler.clipboard_store(*clipboard, base64),
}
},
diff --git a/alacritty_terminal/src/event.rs b/alacritty_terminal/src/event.rs
index 68a3282e..20b105cd 100644
--- a/alacritty_terminal/src/event.rs
+++ b/alacritty_terminal/src/event.rs
@@ -1,21 +1,42 @@
use std::borrow::Cow;
+use std::fmt::{self, Debug, Formatter};
use std::path::PathBuf;
+use std::sync::Arc;
use crate::message_bar::Message;
-use crate::term::SizeInfo;
+use crate::term::{ClipboardType, SizeInfo};
-#[derive(Clone, Debug, PartialEq)]
+#[derive(Clone)]
pub enum Event {
DPRChanged(f64, (u32, u32)),
ConfigReload(PathBuf),
MouseCursorDirty,
Message(Message),
Title(String),
+ ClipboardStore(ClipboardType, String),
+ ClipboardLoad(ClipboardType, Arc<dyn Fn(&str) -> String + Sync + Send + 'static>),
Wakeup,
Urgent,
Exit,
}
+impl Debug for Event {
+ fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
+ match self {
+ Event::DPRChanged(scale, size) => write!(f, "DPRChanged({}, {:?})", scale, size),
+ Event::ConfigReload(path) => write!(f, "ConfigReload({:?})", path),
+ Event::MouseCursorDirty => write!(f, "MouseCursorDirty"),
+ Event::Message(msg) => write!(f, "Message({:?})", msg),
+ Event::Title(title) => write!(f, "Title({})", title),
+ Event::ClipboardStore(ty, text) => write!(f, "ClipboardStore({:?}, {})", ty, text),
+ Event::ClipboardLoad(ty, _) => write!(f, "ClipboardLoad({:?})", ty),
+ Event::Wakeup => write!(f, "Wakeup"),
+ Event::Urgent => write!(f, "Urgent"),
+ Event::Exit => write!(f, "Exit"),
+ }
+ }
+}
+
/// Byte sequences are sent to a `Notify` in response to some events.
pub trait Notify {
/// Notify that an escape sequence should be written to the PTY.
diff --git a/alacritty_terminal/src/lib.rs b/alacritty_terminal/src/lib.rs
index 6c847588..1d2fe551 100644
--- a/alacritty_terminal/src/lib.rs
+++ b/alacritty_terminal/src/lib.rs
@@ -9,7 +9,6 @@
extern crate objc;
pub mod ansi;
-pub mod clipboard;
pub mod config;
pub mod event;
pub mod event_loop;
diff --git a/alacritty_terminal/src/selection.rs b/alacritty_terminal/src/selection.rs
index b1fd147c..7e1e108e 100644
--- a/alacritty_terminal/src/selection.rs
+++ b/alacritty_terminal/src/selection.rs
@@ -372,7 +372,6 @@ impl Selection {
mod tests {
use super::*;
- use crate::clipboard::Clipboard;
use crate::config::MockConfig;
use crate::event::{Event, EventListener};
use crate::index::{Column, Line, Point, Side};
@@ -393,7 +392,7 @@ mod tests {
padding_y: 0.0,
dpr: 1.0,
};
- Term::new(&MockConfig::default(), &size, Clipboard::new_nop(), Mock)
+ Term::new(&MockConfig::default(), &size, Mock)
}
/// Test case of single cell selection.
diff --git a/alacritty_terminal/src/term/mod.rs b/alacritty_terminal/src/term/mod.rs
index 9bb7488c..6aac05d9 100644
--- a/alacritty_terminal/src/term/mod.rs
+++ b/alacritty_terminal/src/term/mod.rs
@@ -2,6 +2,7 @@
use std::cmp::{max, min};
use std::ops::{Index, IndexMut, Range};
+use std::sync::Arc;
use std::time::{Duration, Instant};
use std::{io, mem, ptr, str};
@@ -12,7 +13,6 @@ use unicode_width::UnicodeWidthChar;
use crate::ansi::{
self, Attr, CharsetIndex, Color, CursorStyle, Handler, NamedColor, StandardCharset, TermInfo,
};
-use crate::clipboard::{Clipboard, ClipboardType};
use crate::config::{Config, VisualBellAnimation};
use crate::event::{Event, EventListener};
use crate::grid::{
@@ -777,9 +777,6 @@ pub struct Term<T> {
/// Style of the vi mode cursor.
vi_mode_cursor_style: Option<CursorStyle>,
- /// Clipboard access coupled to the active window.
- clipboard: Clipboard,
-
/// Proxy for sending events to the event loop.
event_proxy: T,
@@ -808,12 +805,7 @@ impl<T> Term<T> {
self.dirty = true;
}
- pub fn new<C>(
- config: &Config<C>,
- size: &SizeInfo,
- clipboard: Clipboard,
- event_proxy: T,
- ) -> Term<T> {
+ pub fn new<C>(config: &Config<C>, size: &SizeInfo, event_proxy: T) -> Term<T> {
let num_cols = size.cols();
let num_lines = size.lines();
@@ -847,7 +839,6 @@ impl<T> Term<T> {
default_cursor_style: config.cursor.style,
vi_mode_cursor_style: config.cursor.vi_mode_style,
dynamic_title: config.dynamic_title(),
- clipboard,
event_proxy,
is_focused: true,
title: None,
@@ -1153,11 +1144,6 @@ impl<T> Term<T> {
self.event_proxy.send_event(Event::Exit);
}
- #[inline]
- pub fn clipboard(&mut self) -> &mut Clipboard {
- &mut self.clipboard
- }
-
/// Toggle the vi mode.
#[inline]
pub fn toggle_vi_mode(&mut self) {
@@ -1802,9 +1788,9 @@ impl<T: EventListener> Handler for Term<T> {
self.color_modified[index] = false;
}
- /// Set the clipboard.
+ /// Store data into clipboard.
#[inline]
- fn set_clipboard(&mut self, clipboard: u8, base64: &[u8]) {
+ fn clipboard_store(&mut self, clipboard: u8, base64: &[u8]) {
let clipboard_type = match clipboard {
b'c' => ClipboardType::Clipboard,
b'p' | b's' => ClipboardType::Selection,
@@ -1812,25 +1798,30 @@ impl<T: EventListener> Handler for Term<T> {
};
if let Ok(bytes) = base64::decode(base64) {
- if let Ok(text) = str::from_utf8(&bytes) {
- self.clipboard.store(clipboard_type, text);
+ if let Ok(text) = String::from_utf8(bytes) {
+ self.event_proxy.send_event(Event::ClipboardStore(clipboard_type, text));
}
}
}
- /// Write clipboard data to child.
+ /// Load data from clipboard.
#[inline]
- fn write_clipboard<W: io::Write>(&mut self, clipboard: u8, writer: &mut W, terminator: &str) {
+ fn clipboard_load(&mut self, clipboard: u8, terminator: &str) {
let clipboard_type = match clipboard {
b'c' => ClipboardType::Clipboard,
b'p' | b's' => ClipboardType::Selection,
_ => return,
};
- let text = self.clipboard.load(clipboard_type);
- let base64 = base64::encode(&text);
- let escape = format!("\x1b]52;{};{}{}", clipboard as char, base64, terminator);
- let _ = writer.write_all(escape.as_bytes());
+ let terminator = terminator.to_owned();
+
+ self.event_proxy.send_event(Event::ClipboardLoad(
+ clipboard_type,
+ Arc::new(move |text| {
+ let base64 = base64::encode(&text);
+ format!("\x1b]52;{};{}{}", clipboard as char, base64, terminator)
+ }),
+ ));
}
#[inline]
@@ -2140,6 +2131,12 @@ impl<T: EventListener> Handler for Term<T> {
}
}
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum ClipboardType {
+ Clipboard,
+ Selection,
+}
+
struct TabStops {
tabs: Vec<bool>,
}
@@ -2195,7 +2192,6 @@ mod tests {
use std::mem;
use crate::ansi::{self, CharsetIndex, Handler, StandardCharset};
- use crate::clipboard::Clipboard;
use crate::config::MockConfig;
use crate::event::{Event, EventListener};
use crate::grid::{Grid, Scroll};
@@ -2219,7 +2215,7 @@ mod tests {
padding_y: 0.0,
dpr: 1.0,
};
- let mut term = Term::new(&MockConfig::default(), &size, Clipboard::new_nop(), Mock);
+ let mut term = Term::new(&MockConfig::default(), &size, Mock);
let mut grid: Grid<Cell> = Grid::new(Line(3), Column(5), 0, Cell::default());
for i in 0..5 {
for j in 0..2 {
@@ -2275,7 +2271,7 @@ mod tests {
padding_y: 0.0,
dpr: 1.0,
};
- let mut term = Term::new(&MockConfig::default(), &size, Clipboard::new_nop(), Mock);
+ let mut term = Term::new(&MockConfig::default(), &size, Mock);
let mut grid: Grid<Cell> = Grid::new(Line(1), Column(5), 0, Cell::default());
for i in 0..5 {
grid[Line(0)][Column(i)].c = 'a';
@@ -2304,7 +2300,7 @@ mod tests {
padding_y: 0.0,
dpr: 1.0,
};
- let mut term = Term::new(&MockConfig::default(), &size, Clipboard::new_nop(), Mock);
+ let mut term = Term::new(&MockConfig::default(), &size, Mock);
let mut grid: Grid<Cell> = Grid::new(Line(3), Column(3), 0, Cell::default());
for l in 0..3 {
if l != 1 {
@@ -2349,7 +2345,7 @@ mod tests {
padding_y: 0.0,
dpr: 1.0,
};
- let mut term = Term::new(&MockConfig::default(), &size, Clipboard::new_nop(), Mock);
+ let mut term = Term::new(&MockConfig::default(), &size, Mock);
let cursor = Point::new(Line(0), Column(0));
term.configure_charset(CharsetIndex::G0, StandardCharset::SpecialCharacterAndLineDrawing);
term.input('a');
@@ -2368,7 +2364,7 @@ mod tests {
padding_y: 0.0,
dpr: 1.0,
};
- let mut term = Term::new(&MockConfig::default(), &size, Clipboard::new_nop(), Mock);
+ let mut term = Term::new(&MockConfig::default(), &size, Mock);
// Add one line of scrollback.
term.grid.scroll_up(&(Line(0)..Line(1)), Line(1), Cell::default());
@@ -2398,7 +2394,7 @@ mod tests {
padding_y: 0.0,
dpr: 1.0,
};
- let mut term = Term::new(&MockConfig::default(), &size, Clipboard::new_nop(), Mock);
+ let mut term = Term::new(&MockConfig::default(), &size, Mock);
// Create 10 lines of scrollback.
for _ in 0..19 {
@@ -2426,7 +2422,7 @@ mod tests {
padding_y: 0.0,
dpr: 1.0,
};
- let mut term = Term::new(&MockConfig::default(), &size, Clipboard::new_nop(), Mock);
+ let mut term = Term::new(&MockConfig::default(), &size, Mock);
// Create 10 lines of scrollback.
for _ in 0..19 {
@@ -2460,7 +2456,7 @@ mod tests {
padding_y: 0.0,
dpr: 1.0,
};
- let mut term = Term::new(&MockConfig::default(), &size, Clipboard::new_nop(), Mock);
+ let mut term = Term::new(&MockConfig::default(), &size, Mock);
// Create 10 lines of scrollback.
for _ in 0..19 {
@@ -2488,7 +2484,7 @@ mod tests {
padding_y: 0.0,
dpr: 1.0,
};
- let mut term = Term::new(&MockConfig::default(), &size, Clipboard::new_nop(), Mock);
+ let mut term = Term::new(&MockConfig::default(), &size, Mock);
// Create 10 lines of scrollback.
for _ in 0..19 {
@@ -2522,7 +2518,7 @@ mod tests {
padding_y: 0.0,
dpr: 1.0,
};
- let mut term = Term::new(&MockConfig::default(), &size, Clipboard::new_nop(), Mock);
+ let mut term = Term::new(&MockConfig::default(), &size, Mock);
// Title None by default.
assert_eq!(term.title, None);
@@ -2576,7 +2572,6 @@ mod benches {
use std::fs;
use std::mem;
- use crate::clipboard::Clipboard;
use crate::config::MockConfig;
use crate::event::{Event, EventListener};
use crate::grid::Grid;
@@ -2617,7 +2612,7 @@ mod benches {
let config = MockConfig::default();
- let mut terminal = Term::new(&config, &size, Clipboard::new_nop(), Mock);
+ let mut terminal = Term::new(&config, &size, Mock);
mem::swap(&mut terminal.grid, &mut grid);
b.iter(|| {
diff --git a/alacritty_terminal/src/vi_mode.rs b/alacritty_terminal/src/vi_mode.rs
index 650c3a8a..6621eda5 100644
--- a/alacritty_terminal/src/vi_mode.rs
+++ b/alacritty_terminal/src/vi_mode.rs
@@ -412,7 +412,6 @@ fn is_boundary<T>(term: &Term<T>, point: Point<usize>, left: bool) -> bool {
mod tests {
use super::*;
- use crate::clipboard::Clipboard;
use crate::config::MockConfig;
use crate::event::Event;
use crate::index::{Column, Line};
@@ -433,7 +432,7 @@ mod tests {
padding_y: 0.0,
dpr: 1.0,
};
- Term::new(&MockConfig::default(), &size, Clipboard::new_nop(), Mock)
+ Term::new(&MockConfig::default(), &size, Mock)
}
#[test]
diff --git a/alacritty_terminal/tests/ref.rs b/alacritty_terminal/tests/ref.rs
index 41959b2f..63cf50f8 100644
--- a/alacritty_terminal/tests/ref.rs
+++ b/alacritty_terminal/tests/ref.rs
@@ -6,7 +6,6 @@ use std::io::{self, Read};
use std::path::Path;
use alacritty_terminal::ansi;
-use alacritty_terminal::clipboard::Clipboard;
use alacritty_terminal::config::MockConfig;
use alacritty_terminal::event::{Event, EventListener};
use alacritty_terminal::index::Column;
@@ -98,7 +97,7 @@ fn ref_test(dir: &Path) {
let mut config = MockConfig::default();
config.scrolling.set_history(ref_config.history_size);
- let mut terminal = Term::new(&config, &size, Clipboard::new_nop(), Mock);
+ let mut terminal = Term::new(&config, &size, Mock);
let mut parser = ansi::Processor::new();
for byte in recording {