File tree 3 files changed +34
-9
lines changed
3 files changed +34
-9
lines changed Original file line number Diff line number Diff line change @@ -138,6 +138,7 @@ impl Cli {
138
138
. long ( "image-backend" )
139
139
. value_name ( "BACKEND" )
140
140
. takes_value ( true )
141
+ . requires ( "image" )
141
142
. max_values ( 1 )
142
143
. possible_values ( & possible_backends)
143
144
. help ( "Which image BACKEND to use." ) ,
@@ -218,6 +219,7 @@ impl Cli {
218
219
219
220
let image_backend = if image. is_some ( ) {
220
221
if let Some ( backend_name) = matches. value_of ( "image-backend" ) {
222
+ image_backends:: check_if_supported ( backend_name) ?;
221
223
image_backends:: get_image_backend ( backend_name)
222
224
} else {
223
225
image_backends:: get_best_backend ( )
@@ -226,6 +228,10 @@ impl Cli {
226
228
None
227
229
} ;
228
230
231
+ if image. is_some ( ) && image_backend. is_none ( ) {
232
+ return Err ( "Could not detect a supported image backend" . into ( ) ) ;
233
+ }
234
+
229
235
let image_colors = if let Some ( value) = matches. value_of ( "color-resolution" ) {
230
236
usize:: from_str ( value) . unwrap ( )
231
237
} else {
Original file line number Diff line number Diff line change @@ -24,15 +24,11 @@ impl<W: Write> Printer<W> {
24
24
if self . info . config . art_off {
25
25
buf. push_str ( & info_str) ;
26
26
} else if let Some ( custom_image) = & self . info . config . image {
27
- if let Some ( image_backend) = & self . info . config . image_backend {
28
- buf. push_str ( & image_backend. add_image (
29
- info_lines. map ( |s| format ! ( "{}{}" , center_pad, s) ) . collect ( ) ,
30
- custom_image,
31
- self . info . config . image_colors ,
32
- ) ) ;
33
- } else {
34
- panic ! ( "No image backend found" )
35
- }
27
+ buf. push_str ( & self . info . config . image_backend . as_ref ( ) . unwrap ( ) . add_image (
28
+ info_lines. map ( |s| format ! ( "{}{}" , center_pad, s) ) . collect ( ) ,
29
+ custom_image,
30
+ self . info . config . image_colors ,
31
+ ) ) ;
36
32
} else {
37
33
let mut logo_lines = if let Some ( custom_ascii) = & self . info . config . ascii_input {
38
34
AsciiArt :: new ( custom_ascii, & colors, !self . info . config . no_bold )
Original file line number Diff line number Diff line change
1
+ use crate :: onefetch:: error:: * ;
1
2
use image:: DynamicImage ;
2
3
3
4
#[ cfg( not( windows) ) ]
@@ -20,6 +21,28 @@ pub fn get_best_backend() -> Option<Box<dyn ImageBackend>> {
20
21
}
21
22
}
22
23
24
+ pub fn check_if_supported ( backend_name : & str ) -> Result < ( ) > {
25
+ #[ cfg( windows) ]
26
+ return Err ( format ! ( "{} image backend is not supported" , backend_name) . into ( ) ) ;
27
+
28
+ #[ cfg( not( windows) ) ]
29
+ match backend_name {
30
+ "kitty" => {
31
+ if !kitty:: KittyBackend :: supported ( ) {
32
+ return Err ( "Kitty image backend is not supported" . into ( ) ) ;
33
+ }
34
+ }
35
+ "sixel" => {
36
+ if !sixel:: SixelBackend :: supported ( ) {
37
+ return Err ( "Sixel image backend is not supported" . into ( ) ) ;
38
+ }
39
+ }
40
+ _ => unreachable ! ( ) ,
41
+ } ;
42
+
43
+ Ok ( ( ) )
44
+ }
45
+
23
46
pub fn get_image_backend ( backend_name : & str ) -> Option < Box < dyn ImageBackend > > {
24
47
#[ cfg( not( windows) ) ]
25
48
let backend = Some ( match backend_name {
You can’t perform that action at this time.
0 commit comments