From adf97e088e38c12eb6c363f674aab5dca1962bbe Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Thu, 3 Mar 2022 16:48:51 +0900 Subject: Simplify get_clipboard_provider by defining one per host --- helix-view/src/clipboard.rs | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/helix-view/src/clipboard.rs b/helix-view/src/clipboard.rs index a492652d..63e2272c 100644 --- a/helix-view/src/clipboard.rs +++ b/helix-view/src/clipboard.rs @@ -56,16 +56,29 @@ macro_rules! command_provider { }}; } +#[cfg(windows)] pub fn get_clipboard_provider() -> Box { - // TODO: support for user-defined provider, probably when we have plugin support by setting a - // variable? + Box::new(provider::WindowsProvider::default()) +} +#[cfg(target_os = "macos")] +pub fn get_clipboard_provider() -> Box { if exists("pbcopy") && exists("pbpaste") { command_provider! { paste => "pbpaste"; copy => "pbcopy"; } - } else if env_var_is_set("WAYLAND_DISPLAY") && exists("wl-copy") && exists("wl-paste") { + } else { + Box::new(provider::NopProvider::new()) + } +} + +#[cfg(not(any(windows, target_os = "macos")))] +pub fn get_clipboard_provider() -> Box { + // TODO: support for user-defined provider, probably when we have plugin support by setting a + // variable? + + if env_var_is_set("WAYLAND_DISPLAY") && exists("wl-copy") && exists("wl-paste") { command_provider! { paste => "wl-paste", "--no-newline"; copy => "wl-copy", "--type", "text/plain"; @@ -88,22 +101,6 @@ pub fn get_clipboard_provider() -> Box { primary_paste => "xsel", "-o"; primary_copy => "xsel", "-i"; } - } else if exists("lemonade") { - command_provider! { - paste => "lemonade", "paste"; - copy => "lemonade", "copy"; - } - } else if exists("doitclient") { - command_provider! { - paste => "doitclient", "wclip", "-r"; - copy => "doitclient", "wclip"; - } - } else if exists("win32yank.exe") { - // FIXME: does it work within WSL? - command_provider! { - paste => "win32yank.exe", "-o", "--lf"; - copy => "win32yank.exe", "-i", "--crlf"; - } } else if exists("termux-clipboard-set") && exists("termux-clipboard-get") { command_provider! { paste => "termux-clipboard-get"; @@ -115,11 +112,7 @@ pub fn get_clipboard_provider() -> Box { copy => "tmux", "load-buffer", "-"; } } else { - #[cfg(target_os = "windows")] - return Box::new(provider::WindowsProvider::default()); - - #[cfg(not(target_os = "windows"))] - return Box::new(provider::NopProvider::new()); + Box::new(provider::NopProvider::new()) } } -- cgit v1.2.3-70-g09d2