1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-24 13:52:55 +03:00

window: fixup clipboard on macos

This commit is contained in:
Wez Furlong 2019-11-29 12:47:56 -08:00
parent 2b795aa08d
commit c03eda1279
3 changed files with 21 additions and 6 deletions

View File

@ -57,6 +57,7 @@ memmap = {version="0.7", optional=true}
[target.'cfg(target_os="macos")'.dependencies]
cocoa = "0.20"
objc = "0.2"
clipboard = "0.5"
core-foundation = "0.7"
core-graphics = "0.19"
cgl = { version = "0.3", optional = true }

View File

@ -222,14 +222,10 @@ pub trait WindowOps {
R: Send + 'static;
/// Initiate textual transfer from the clipboard
fn get_clipboard(&self) -> Future<String> {
Future::err(failure::err_msg("no clip"))
}
fn get_clipboard(&self) -> Future<String>;
/// Set some text in the clipboard
fn set_clipboard(&self, _text: String) -> Future<()> {
Future::err(failure::err_msg("no clip"))
}
fn set_clipboard(&self, text: String) -> Future<()>;
}
pub trait WindowOpsMut {

View File

@ -463,6 +463,24 @@ impl WindowOps for Window {
}
})
}
fn get_clipboard(&self) -> Future<String> {
use clipboard::ClipboardProvider;
Future::result(
clipboard::ClipboardContext::new()
.and_then(|mut ctx| ctx.get_contents())
.map_err(|e| failure::format_err!("Failed to get clipboard: {}", e)),
)
}
fn set_clipboard(&self, text: String) -> Future<()> {
use clipboard::ClipboardProvider;
Future::result(
clipboard::ClipboardContext::new()
.and_then(|mut ctx| ctx.set_contents(text))
.map_err(|e| failure::format_err!("Failed to set clipboard: {}", e)),
)
}
}
/// Convert from a macOS screen coordinate with the origin in the bottom left