use crate::platform::Platform;
#[derive(Clone)]
pub struct ClipboardCommand {
pub binary: &'static str,
pub args: &'static [&'static str],
pub paste_hint: &'static str,
}
pub fn get_platform_clipboard_command() -> Option<ClipboardCommand> {
get_platform_clipboard_command_with_executor(&crate::RealProcessExecutor::new())
}
pub fn get_platform_clipboard_command_with_executor(
executor: &dyn crate::ProcessExecutor,
) -> Option<ClipboardCommand> {
let platform = Platform::detect_with_executor(executor);
match platform {
Platform::MacWithBrew | Platform::MacWithoutBrew => Some(ClipboardCommand {
binary: "pbcopy",
args: &[],
paste_hint: "pbpaste to view",
}),
Platform::DebianLinux
| Platform::RhelLinux
| Platform::ArchLinux
| Platform::GenericLinux => {
if executor.command_exists("wl-copy") {
Some(ClipboardCommand {
binary: "wl-copy",
args: &[],
paste_hint: "wl-paste to view",
})
} else if executor.command_exists("xclip") {
Some(ClipboardCommand {
binary: "xclip",
args: &["-selection", "clipboard"],
paste_hint: "xclip -o -selection clipboard to view",
})
} else {
None
}
}
Platform::Windows => Some(ClipboardCommand {
binary: "clip",
args: &[],
paste_hint: "paste to view",
}),
Platform::Unknown => None,
}
}