11//! Access the clipboard.
22use crate :: command:: { self , Command } ;
3+ use crate :: core:: clipboard:: Kind ;
34use crate :: futures:: MaybeSend ;
45
56use std:: fmt;
@@ -9,10 +10,10 @@ use std::fmt;
910/// [`Command`]: crate::Command
1011pub enum Action < T > {
1112 /// Read the clipboard and produce `T` with the result.
12- Read ( Box < dyn Fn ( Option < String > ) -> T > ) ,
13+ Read ( Box < dyn Fn ( Option < String > ) -> T > , Kind ) ,
1314
1415 /// Write the given contents to the clipboard.
15- Write ( String ) ,
16+ Write ( String , Kind ) ,
1617}
1718
1819impl < T > Action < T > {
@@ -25,17 +26,19 @@ impl<T> Action<T> {
2526 T : ' static ,
2627 {
2728 match self {
28- Self :: Read ( o) => Action :: Read ( Box :: new ( move |s| f ( o ( s) ) ) ) ,
29- Self :: Write ( content) => Action :: Write ( content) ,
29+ Self :: Read ( o, target) => {
30+ Action :: Read ( Box :: new ( move |s| f ( o ( s) ) ) , target)
31+ }
32+ Self :: Write ( content, target) => Action :: Write ( content, target) ,
3033 }
3134 }
3235}
3336
3437impl < T > fmt:: Debug for Action < T > {
3538 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
3639 match self {
37- Self :: Read ( _) => write ! ( f, "Action::Read" ) ,
38- Self :: Write ( _) => write ! ( f, "Action::Write" ) ,
40+ Self :: Read ( _, target ) => write ! ( f, "Action::Read{target:?} " ) ,
41+ Self :: Write ( _, target ) => write ! ( f, "Action::Write({target:?}) " ) ,
3942 }
4043 }
4144}
@@ -44,10 +47,34 @@ impl<T> fmt::Debug for Action<T> {
4447pub fn read < Message > (
4548 f : impl Fn ( Option < String > ) -> Message + ' static ,
4649) -> Command < Message > {
47- Command :: single ( command:: Action :: Clipboard ( Action :: Read ( Box :: new ( f) ) ) )
50+ Command :: single ( command:: Action :: Clipboard ( Action :: Read (
51+ Box :: new ( f) ,
52+ Kind :: Standard ,
53+ ) ) )
54+ }
55+
56+ /// Read the current contents of the primary clipboard.
57+ pub fn read_primary < Message > (
58+ f : impl Fn ( Option < String > ) -> Message + ' static ,
59+ ) -> Command < Message > {
60+ Command :: single ( command:: Action :: Clipboard ( Action :: Read (
61+ Box :: new ( f) ,
62+ Kind :: Primary ,
63+ ) ) )
4864}
4965
5066/// Write the given contents to the clipboard.
5167pub fn write < Message > ( contents : String ) -> Command < Message > {
52- Command :: single ( command:: Action :: Clipboard ( Action :: Write ( contents) ) )
68+ Command :: single ( command:: Action :: Clipboard ( Action :: Write (
69+ contents,
70+ Kind :: Standard ,
71+ ) ) )
72+ }
73+
74+ /// Write the given contents to the primary clipboard.
75+ pub fn write_primary < Message > ( contents : String ) -> Command < Message > {
76+ Command :: single ( command:: Action :: Clipboard ( Action :: Write (
77+ contents,
78+ Kind :: Primary ,
79+ ) ) )
5380}
0 commit comments