@@ -4,6 +4,7 @@ use regex::Regex;
4
4
use rodio:: { OutputStream , Sink , Source } ;
5
5
use std:: collections:: HashMap ;
6
6
use std:: env;
7
+ use clipboard:: { ClipboardContext , ClipboardProvider } ;
7
8
use std:: fs:: { self , File } ;
8
9
use std:: io:: { self , Error , Read , Write } ;
9
10
use std:: path:: Path ;
@@ -1398,6 +1399,42 @@ impl Executor {
1398
1399
} )
1399
1400
}
1400
1401
1402
+ // Set value in the clipboard
1403
+ "set-clipboard" => {
1404
+ let mut ctx: ClipboardContext ;
1405
+ if let Ok ( i) = ClipboardProvider :: new ( ) {
1406
+ ctx = i
1407
+ } else {
1408
+ self . stack . push ( Type :: Error ( "set-clipboard" . to_string ( ) ) ) ;
1409
+ return
1410
+ } ;
1411
+
1412
+ let value = self . pop_stack ( ) . get_string ( ) ;
1413
+ if ctx. set_contents ( value. clone ( ) ) . is_ok ( ) {
1414
+ self . stack . push ( Type :: String ( value) ) ;
1415
+ } else {
1416
+ self . stack . push ( Type :: Error ( "get-clipboard" . to_string ( ) ) )
1417
+ } ;
1418
+ }
1419
+
1420
+ // Get value in the clipboard
1421
+ "get-clipboard" => {
1422
+ let mut ctx: ClipboardContext ;
1423
+ if let Ok ( i) = ClipboardProvider :: new ( ) {
1424
+ ctx = i
1425
+ } else {
1426
+ self . stack . push ( Type :: Error ( "set-clipboard" . to_string ( ) ) ) ;
1427
+ return
1428
+ } ;
1429
+
1430
+
1431
+ if let Ok ( contents) = ctx. get_contents ( ) {
1432
+ self . stack . push ( Type :: String ( contents) ) ;
1433
+ } else {
1434
+ self . stack . push ( Type :: Error ( "get-clipboard" . to_string ( ) ) )
1435
+ }
1436
+ }
1437
+
1401
1438
// If it is not recognized as a command, use it as a string.
1402
1439
_ => self . stack . push ( Type :: String ( command) ) ,
1403
1440
}
0 commit comments