mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-25 10:56:19 +04:00
Added native Windows clipboard support (#373)
* Added native Windows clipboard support * make conditional wip better conditional wip wip wip wip make conditional
This commit is contained in:
parent
b39e452d77
commit
acaf22d005
28
Cargo.lock
generated
28
Cargo.lock
generated
@ -100,6 +100,17 @@ dependencies = [
|
|||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clipboard-win"
|
||||||
|
version = "4.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4e4ea1881992efc993e4dc50a324cdbd03216e41bdc8385720ff47efc9bd2ca8"
|
||||||
|
dependencies = [
|
||||||
|
"error-code",
|
||||||
|
"str-buf",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crossbeam-utils"
|
name = "crossbeam-utils"
|
||||||
version = "0.8.5"
|
version = "0.8.5"
|
||||||
@ -172,6 +183,16 @@ dependencies = [
|
|||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "error-code"
|
||||||
|
version = "2.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b5115567ac25674e0043e472be13d14e537f37ea8aa4bdc4aef0c89add1db1ff"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"str-buf",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "etcetera"
|
name = "etcetera"
|
||||||
version = "0.3.2"
|
version = "0.3.2"
|
||||||
@ -383,6 +404,7 @@ dependencies = [
|
|||||||
"anyhow",
|
"anyhow",
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"chardetng",
|
"chardetng",
|
||||||
|
"clipboard-win",
|
||||||
"crossterm",
|
"crossterm",
|
||||||
"encoding_rs",
|
"encoding_rs",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
@ -871,6 +893,12 @@ version = "1.6.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e"
|
checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "str-buf"
|
||||||
|
version = "1.0.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d44a3643b4ff9caf57abcee9c2c621d6c03d9135e0d8b589bd9afb5992cb176a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.73"
|
version = "1.0.73"
|
||||||
|
@ -38,5 +38,8 @@ log = "~0.4"
|
|||||||
|
|
||||||
which = "4.1"
|
which = "4.1"
|
||||||
|
|
||||||
|
[target.'cfg(windows)'.dependencies]
|
||||||
|
clipboard-win = { version = "4.2", features = ["std"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
helix-tui = { path = "../helix-tui" }
|
helix-tui = { path = "../helix-tui" }
|
||||||
|
@ -77,7 +77,11 @@ pub fn get_clipboard_provider() -> Box<dyn ClipboardProvider> {
|
|||||||
copy => "tmux", "load-buffer", "-";
|
copy => "tmux", "load-buffer", "-";
|
||||||
}
|
}
|
||||||
} else {
|
} 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 @@ fn set_contents(&self, _: String) -> Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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)]
|
#[derive(Debug)]
|
||||||
pub struct CommandConfig {
|
pub struct CommandConfig {
|
||||||
pub prg: &'static str,
|
pub prg: &'static str,
|
||||||
|
Loading…
Reference in New Issue
Block a user