Skip to content

Commit

Permalink
Added support for --to-clipboard in Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
AW14Saurabh committed Aug 7, 2020
1 parent c7ffab8 commit 3a74de1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
28 changes: 28 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ log = "0.4.11"
[target.'cfg(target_os = "macos")'.dependencies]
pasteboard = "0.1.1"

[target.'cfg(target_os = "windows")'.dependencies]
clipboard-win = "4.0.2"

[dependencies.image]
version = "0.23"
default-features = false
Expand Down
13 changes: 12 additions & 1 deletion src/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use syntect::util::LinesWithEndings;
use {image::ImageOutputFormat, pasteboard::Pasteboard};
#[cfg(target_os = "linux")]
use {image::ImageOutputFormat, std::process::Command};
#[cfg(target_os = "windows")]
use {image::ImageOutputFormat, clipboard_win::{set_clipboard, formats::RawData}};

pub mod blur;
pub mod config;
Expand Down Expand Up @@ -49,7 +51,16 @@ pub fn dump_image_to_clipboard(image: &DynamicImage) -> Result<(), Error> {
Ok(())
}

#[cfg(not(any(target_os = "linux", target_os = "macos")))]
#[cfg(target_os = "windows")]
pub fn dump_image_to_clipboard(image: &DynamicImage) -> Result<(), Error> {
let mut temp: Vec<u8> = Vec::new();
image.write_to(&mut temp, ImageOutputFormat::Png)?;
set_clipboard(RawData(49488), &temp)
.map_err(|e| format_err!("Failed to access clipboard {}", e))?;
Ok(())
}

#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
pub fn dump_image_to_clipboard(_image: &DynamicImage) -> Result<(), Error> {
Err(format_err!(
"This feature hasn't been implemented for your system"
Expand Down

0 comments on commit 3a74de1

Please sign in to comment.