1//! Access the clipboard.
2use crate::core::clipboard::Kind;
3use crate::futures::futures::channel::oneshot;
4use crate::task::{self, Task};
56/// A clipboard action to be performed by some [`Task`].
7///
8/// [`Task`]: crate::Task
9#[derive(Debug)]
10pub enum Action {
11/// Read the clipboard and produce `T` with the result.
12Read {
13/// The clipboard target.
14target: Kind,
15/// The channel to send the read contents.
16channel: oneshot::Sender<Option<String>>,
17 },
1819/// Write the given contents to the clipboard.
20Write {
21/// The clipboard target.
22target: Kind,
23/// The contents to be written.
24contents: String,
25 },
26}
2728/// Read the current contents of the clipboard.
29pub fn read() -> Task<Option<String>> {
30 task::oneshot(|channel| {
31crate::Action::Clipboard(Action::Read {
32 target: Kind::Standard,
33 channel,
34 })
35 })
36}
3738/// Read the current contents of the primary clipboard.
39pub fn read_primary() -> Task<Option<String>> {
40 task::oneshot(|channel| {
41crate::Action::Clipboard(Action::Read {
42 target: Kind::Primary,
43 channel,
44 })
45 })
46}
4748/// Write the given contents to the clipboard.
49pub fn write<T>(contents: String) -> Task<T> {
50 task::effect(crate::Action::Clipboard(Action::Write {
51 target: Kind::Standard,
52 contents,
53 }))
54}
5556/// Write the given contents to the primary clipboard.
57pub fn write_primary<Message>(contents: String) -> Task<Message> {
58 task::effect(crate::Action::Clipboard(Action::Write {
59 target: Kind::Primary,
60 contents,
61 }))
62}