1
1
use base64:: { engine:: general_purpose, Engine as _} ;
2
2
use copypasta_ext:: prelude:: * ;
3
+ use copypasta_ext:: wayland_bin:: WaylandBinClipboardContext ;
3
4
use copypasta_ext:: x11_bin:: ClipboardContext as BinClipboardContext ;
4
5
use copypasta_ext:: x11_fork:: ClipboardContext as ForkClipboardContext ;
5
6
use crossterm:: style:: Print ;
@@ -90,15 +91,8 @@ pub fn verified_password(message: &str, minimum_length: usize) -> String {
90
91
}
91
92
}
92
93
93
- fn in_ssh_shell ( ) -> bool {
94
- return !env:: var ( "SSH_CONNECTION" )
95
- . unwrap_or_default ( )
96
- . trim ( )
97
- . is_empty ( ) ;
98
- }
99
-
100
94
pub fn copy_string_to_clipboard ( content : String ) -> Result < CopyType , ( ) > {
101
- if in_ssh_shell ( )
95
+ if env_var_set ( "SSH_CONNECTION" )
102
96
&& crossterm:: execute!(
103
97
io:: stdout( ) ,
104
98
Print ( format!(
@@ -111,6 +105,12 @@ pub fn copy_string_to_clipboard(content: String) -> Result<CopyType, ()> {
111
105
// We do not use copypasta_ext::osc52 module because we have enabled terminal raw mode, so we print with crossterm utilities
112
106
// Check https://github.com/timvisee/rust-clipboard-ext/blob/371df19d2f961882a21c957f396d1e24548d1f28/src/osc52.rs#L92
113
107
Ok ( CopyType :: OSC52 )
108
+ } else if env_var_set ( "WAYLAND_DISPLAY" )
109
+ && WaylandBinClipboardContext :: new ( )
110
+ . and_then ( |mut ctx| ctx. set_contents ( content. clone ( ) ) )
111
+ . is_ok ( )
112
+ {
113
+ Ok ( CopyType :: Native )
114
114
} else if BinClipboardContext :: new ( )
115
115
. and_then ( |mut ctx| ctx. set_contents ( content. clone ( ) ) )
116
116
. is_ok ( )
@@ -123,3 +123,9 @@ pub fn copy_string_to_clipboard(content: String) -> Result<CopyType, ()> {
123
123
Err ( ( ) )
124
124
}
125
125
}
126
+
127
+ fn env_var_set ( env_var : & str ) -> bool {
128
+ env:: var ( env_var)
129
+ . map ( |v| !v. trim ( ) . is_empty ( ) )
130
+ . unwrap_or ( false )
131
+ }
0 commit comments