use crate::platform_impl::Clipboard as ClipboardPlatform;
#[derive(Debug, Clone, Default)]
pub struct Clipboard(ClipboardPlatform);
impl Clipboard {
pub fn new() -> Self {
Self::default()
}
pub fn write_text(&mut self, s: impl AsRef<str>) {
self.0.write_text(s);
}
pub fn read_text(&self) -> Option<String> {
self.0.read_text()
}
}
pub(crate) type FormatId = &'static str;
#[derive(Debug, Clone)]
pub(crate) struct ClipboardFormat {
pub(crate) identifier: FormatId,
pub(crate) data: Vec<u8>,
}
impl ClipboardFormat {
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub const TEXT: &'static str = "public.utf8-plain-text";
#[cfg(any(target_os = "windows", target_os = "android"))]
pub const TEXT: &'static str = "text/plain";
#[cfg(target_os = "linux")]
pub const TEXT: &'static str = "UTF8_STRING";
}
impl ClipboardFormat {
pub fn new(identifier: FormatId, data: impl Into<Vec<u8>>) -> Self {
let data = data.into();
ClipboardFormat { identifier, data }
}
}
impl From<String> for ClipboardFormat {
fn from(src: String) -> ClipboardFormat {
let data = src.into_bytes();
ClipboardFormat::new(ClipboardFormat::TEXT, data)
}
}
impl From<&str> for ClipboardFormat {
fn from(src: &str) -> ClipboardFormat {
src.to_string().into()
}
}