aboutsummaryrefslogtreecommitdiff
path: root/helix-view
diff options
context:
space:
mode:
authorKirawi2021-06-30 08:11:56 +0000
committerGitHub2021-06-30 08:11:56 +0000
commitacaf22d00548c39c5bc86eea58cf523508a9c3b6 (patch)
treee36ddb2558c8c5cb95afa68d5e747ee52848b658 /helix-view
parentb39e452d7714a74419e02195183a659ae4efb1f6 (diff)
Added native Windows clipboard support (#373)
* Added native Windows clipboard support * make conditional wip better conditional wip wip wip wip make conditional
Diffstat (limited to 'helix-view')
-rw-r--r--helix-view/Cargo.toml3
-rw-r--r--helix-view/src/clipboard.rs27
2 files changed, 29 insertions, 1 deletions
diff --git a/helix-view/Cargo.toml b/helix-view/Cargo.toml
index b4379952..cb2032de 100644
--- a/helix-view/Cargo.toml
+++ b/helix-view/Cargo.toml
@@ -38,5 +38,8 @@ log = "~0.4"
which = "4.1"
+[target.'cfg(windows)'.dependencies]
+clipboard-win = { version = "4.2", features = ["std"] }
+
[dev-dependencies]
helix-tui = { path = "../helix-tui" }
diff --git a/helix-view/src/clipboard.rs b/helix-view/src/clipboard.rs
index e32933e3..401c0459 100644
--- a/helix-view/src/clipboard.rs
+++ b/helix-view/src/clipboard.rs
@@ -77,7 +77,11 @@ pub fn get_clipboard_provider() -> Box<dyn ClipboardProvider> {
copy => "tmux", "load-buffer", "-";
}
} else {
- Box::new(provider::NopProvider)
+ #[cfg(target_os = "windows")]
+ return Box::new(provider::WindowsProvider);
+
+ #[cfg(not(target_os = "windows"))]
+ return Box::new(provider::NopProvider);
}
}
@@ -120,6 +124,27 @@ mod provider {
}
}
+ #[cfg(target_os = "windows")]
+ #[derive(Debug)]
+ pub struct WindowsProvider;
+
+ #[cfg(target_os = "windows")]
+ impl ClipboardProvider for WindowsProvider {
+ fn name(&self) -> Cow<str> {
+ Cow::Borrowed("clipboard-win")
+ }
+
+ fn get_contents(&self) -> Result<String> {
+ let contents = clipboard_win::get_clipboard(clipboard_win::formats::Unicode)?;
+ Ok(contents)
+ }
+
+ fn set_contents(&self, contents: String) -> Result<()> {
+ clipboard_win::set_clipboard(clipboard_win::formats::Unicode, contents)?;
+ Ok(())
+ }
+ }
+
#[derive(Debug)]
pub struct CommandConfig {
pub prg: &'static str,