@@ -8,9 +8,9 @@ use crate::{
8
8
strings, try_or_popup,
9
9
ui:: { self , calc_scroll_top, style:: SharedTheme } ,
10
10
} ;
11
+ use anyhow:: Result ;
11
12
use asyncgit:: { hash, sync, DiffLine , DiffLineType , FileDiff , CWD } ;
12
13
use bytesize:: ByteSize ;
13
- use clipboard:: { ClipboardContext , ClipboardProvider } ;
14
14
use crossterm:: event:: Event ;
15
15
use std:: { borrow:: Cow , cell:: Cell , cmp, path:: Path } ;
16
16
use tui:: {
@@ -21,8 +21,6 @@ use tui::{
21
21
Frame ,
22
22
} ;
23
23
24
- use anyhow:: { anyhow, Result } ;
25
-
26
24
#[ derive( Default ) ]
27
25
struct Current {
28
26
path : String ,
@@ -244,18 +242,6 @@ impl DiffComponent {
244
242
Ok ( ( ) )
245
243
}
246
244
247
- fn copy_string ( string : String ) -> Result < ( ) > {
248
- let mut ctx: ClipboardContext = ClipboardProvider :: new ( )
249
- . map_err ( |_| {
250
- anyhow ! ( "failed to get access to clipboard" )
251
- } ) ?;
252
- ctx. set_contents ( string) . map_err ( |_| {
253
- anyhow ! ( "failed to set clipboard contents" )
254
- } ) ?;
255
-
256
- Ok ( ( ) )
257
- }
258
-
259
245
fn copy_selection ( & self ) -> Result < ( ) > {
260
246
if let Some ( diff) = & self . diff {
261
247
let lines_to_copy: Vec < & str > = diff
@@ -281,7 +267,9 @@ impl DiffComponent {
281
267
try_or_popup ! (
282
268
self ,
283
269
"copy to clipboard error:" ,
284
- Self :: copy_string( lines_to_copy. join( "\n " ) )
270
+ crate :: clipboard:: copy_string(
271
+ lines_to_copy. join( "\n " )
272
+ )
285
273
) ;
286
274
}
287
275
@@ -616,11 +604,13 @@ impl Component for DiffComponent {
616
604
self . focused ,
617
605
) ) ;
618
606
619
- out. push ( CommandInfo :: new (
620
- strings:: commands:: copy ( & self . key_config ) ,
621
- true ,
622
- self . focused ,
623
- ) ) ;
607
+ if crate :: clipboard:: is_supported ( ) {
608
+ out. push ( CommandInfo :: new (
609
+ strings:: commands:: copy ( & self . key_config ) ,
610
+ true ,
611
+ self . focused ,
612
+ ) ) ;
613
+ }
624
614
625
615
out. push (
626
616
CommandInfo :: new (
@@ -700,7 +690,9 @@ impl Component for DiffComponent {
700
690
}
701
691
}
702
692
Ok ( true )
703
- } else if e == self . key_config . copy {
693
+ } else if e == self . key_config . copy
694
+ && crate :: clipboard:: is_supported ( )
695
+ {
704
696
self . copy_selection ( ) ?;
705
697
Ok ( true )
706
698
} else {
0 commit comments