Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Get::html on macOS (unimplemented on others) #157

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl<F: FnOnce()> Drop for ScopeGuard<F> {
pub(crate) mod private {
// This is currently unused on macOS, so silence the warning which appears
// since there's no extension traits making use of this trait sealing structure.
#[cfg_attr(target_vendor = "apple", allow(unreachable_pub))]
#[cfg_attr(target_vendor = "apple", allow(unreachable_pub, dead_code))]
pub trait Sealed {}

impl Sealed for crate::Get<'_> {}
Expand Down
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ impl Get<'_> {
self.platform.text()
}

/// Completes the "get" operation by fetching HTML from the clipboard.
pub fn html(self) -> Result<String, Error> {
self.platform.html()
}

/// Completes the "get" operation by fetching image data from the clipboard and returning the
/// decoded pixels.
///
Expand Down
4 changes: 4 additions & 0 deletions src/platform/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ impl<'clipboard> Get<'clipboard> {
}
}

pub(crate) fn html(self) -> Result<String, Error> {
unimplemented!()
}

#[cfg(feature = "image-data")]
pub(crate) fn image(self) -> Result<ImageData<'static>, Error> {
match self.clipboard {
Expand Down
22 changes: 22 additions & 0 deletions src/platform/osx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,28 @@ impl<'clipboard> Get<'clipboard> {
})
}

pub(crate) fn html(self) -> Result<String, Error> {
autoreleasepool(|_| {
// XXX: We explicitly use `pasteboardItems` and not `stringForType` since the latter will concat
// multiple strings, if present, into one and return it instead of reading just the first which is `arboard`'s
// historical behavior.
let contents =
unsafe { self.clipboard.pasteboard.pasteboardItems() }.ok_or_else(|| {
Error::Unknown {
description: String::from("NSPasteboard#pasteboardItems errored"),
}
})?;

for item in contents {
if let Some(string) = unsafe { item.stringForType(NSPasteboardTypeHTML) } {
return Ok(string.to_string());
}
}

Err(Error::ContentNotAvailable)
})
}

#[cfg(feature = "image-data")]
pub(crate) fn image(self) -> Result<ImageData<'static>, Error> {
use objc2_app_kit::NSPasteboardTypeTIFF;
Expand Down
4 changes: 4 additions & 0 deletions src/platform/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,10 @@ impl<'clipboard> Get<'clipboard> {
String::from_utf16(&out[..bytes_read]).map_err(|_| Error::ConversionFailure)
}

pub(crate) fn html(self) -> Result<String, Error> {
unimplemented!()
}

#[cfg(feature = "image-data")]
pub(crate) fn image(self) -> Result<ImageData<'static>, Error> {
const FORMAT: u32 = clipboard_win::formats::CF_DIBV5;
Expand Down
Loading