diff options
Diffstat (limited to 'runtime/src/clipboard.rs')
-rw-r--r-- | runtime/src/clipboard.rs | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/runtime/src/clipboard.rs b/runtime/src/clipboard.rs index 49044a0f..dd47c47d 100644 --- a/runtime/src/clipboard.rs +++ b/runtime/src/clipboard.rs @@ -1,5 +1,6 @@ //! Access the clipboard. use crate::command::{self, Command}; +use crate::core::clipboard::Kind; use crate::futures::MaybeSend; use std::fmt; @@ -9,10 +10,10 @@ use std::fmt; /// [`Command`]: crate::Command pub enum Action<T> { /// Read the clipboard and produce `T` with the result. - Read(Box<dyn Fn(Option<String>) -> T>), + Read(Box<dyn Fn(Option<String>) -> T>, Kind), /// Write the given contents to the clipboard. - Write(String), + Write(String, Kind), } impl<T> Action<T> { @@ -25,8 +26,10 @@ impl<T> Action<T> { T: 'static, { match self { - Self::Read(o) => Action::Read(Box::new(move |s| f(o(s)))), - Self::Write(content) => Action::Write(content), + Self::Read(o, target) => { + Action::Read(Box::new(move |s| f(o(s))), target) + } + Self::Write(content, target) => Action::Write(content, target), } } } @@ -34,8 +37,8 @@ impl<T> Action<T> { impl<T> fmt::Debug for Action<T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Self::Read(_) => write!(f, "Action::Read"), - Self::Write(_) => write!(f, "Action::Write"), + Self::Read(_, target) => write!(f, "Action::Read{target:?}"), + Self::Write(_, target) => write!(f, "Action::Write({target:?})"), } } } @@ -44,24 +47,34 @@ impl<T> fmt::Debug for Action<T> { pub fn read<Message>( f: impl Fn(Option<String>) -> Message + 'static, ) -> Command<Message> { - Command::single(command::Action::Clipboard(Action::Read(Box::new(f)))) + Command::single(command::Action::Clipboard(Action::Read( + Box::new(f), + Kind::Standard, + ))) } -/// Write the given contents to the clipboard. -pub fn write<Message>(contents: String) -> Command<Message> { - Command::single(command::Action::Clipboard(Action::Write(contents))) -} - -/// Read the current contents of primary. +/// Read the current contents of the primary clipboard. pub fn read_primary<Message>( f: impl Fn(Option<String>) -> Message + 'static, ) -> Command<Message> { - Command::single(command::Action::ClipboardPrimary(Action::Read(Box::new( - f, - )))) + Command::single(command::Action::Clipboard(Action::Read( + Box::new(f), + Kind::Primary, + ))) +} + +/// Write the given contents to the clipboard. +pub fn write<Message>(contents: String) -> Command<Message> { + Command::single(command::Action::Clipboard(Action::Write( + contents, + Kind::Standard, + ))) } -/// Write the given contents to primary. +/// Write the given contents to the primary clipboard. pub fn write_primary<Message>(contents: String) -> Command<Message> { - Command::single(command::Action::ClipboardPrimary(Action::Write(contents))) + Command::single(command::Action::Clipboard(Action::Write( + contents, + Kind::Primary, + ))) } |