8
8
#![ allow( clippy:: redundant_closure_for_method_calls) ]
9
9
#![ allow( clippy:: wildcard_imports) ]
10
10
11
- use clap:: error:: ErrorKind :: MissingRequiredArgument ;
12
11
use clap:: builder:: NonEmptyStringValueParser ;
12
+ use clap:: error:: ErrorKind :: MissingRequiredArgument ;
13
+ use clap:: value_parser;
14
+ use gifski:: { Repeat , Settings } ;
13
15
use std:: io:: stdin;
14
16
use std:: io:: BufRead ;
15
17
use std:: io:: BufReader ;
16
18
use std:: io:: IsTerminal ;
17
19
use std:: io:: Read ;
18
20
use std:: io:: StdinLock ;
19
21
use std:: io:: Stdout ;
20
- use gifski:: { Settings , Repeat } ;
21
- use clap:: value_parser;
22
22
23
23
#[ cfg( feature = "video" ) ]
24
24
mod ffmpeg_source;
25
- mod png;
26
25
mod gif_source;
27
- mod y4m_source ;
26
+ mod png ;
28
27
mod source;
28
+ mod y4m_source;
29
29
use crate :: source:: Source ;
30
30
31
31
use gifski:: progress:: { NoProgress , ProgressReporter } ;
32
32
33
33
pub type BinResult < T , E = Box < dyn std:: error:: Error + Send + Sync > > = Result < T , E > ;
34
34
35
- use clap:: { Command , Arg , ArgAction } ;
35
+ use clap:: { Arg , ArgAction , Command } ;
36
36
37
37
use std:: env;
38
38
use std:: fmt;
@@ -239,8 +239,7 @@ fn bin_main() -> BinResult<()> {
239
239
240
240
if fps > 100.0 || fps <= 0.0 {
241
241
return Err ( "100 fps is maximum" . into ( ) ) ;
242
- }
243
- else if !quiet && fps > 50.0 {
242
+ } else if !quiet && fps > 50.0 {
244
243
eprintln ! ( "warning: web browsers support max 50 fps" ) ;
245
244
}
246
245
@@ -285,7 +284,7 @@ fn bin_main() -> BinResult<()> {
285
284
}
286
285
SrcPath :: Stdin ( BufReader :: new ( fd) )
287
286
} else {
288
- SrcPath :: Path ( path. to_path_buf ( ) )
287
+ SrcPath :: Path ( path. clone ( ) )
289
288
} ;
290
289
match file_type ( & mut src) . unwrap_or ( FileType :: Other ) {
291
290
FileType :: PNG | FileType :: JPEG => return Err ( "Only a single image file was given as an input. This is not enough to make an animation." . into ( ) ) ,
@@ -413,7 +412,7 @@ fn panic_err(err: Box<dyn std::any::Any + Send>) -> String {
413
412
}
414
413
415
414
fn parse_color ( c : & str ) -> Result < rgb:: RGB8 , String > {
416
- let c = c. trim_matches ( |c : char | c. is_ascii_whitespace ( ) ) ;
415
+ let c = c. trim_matches ( |c : char | c. is_ascii_whitespace ( ) ) ;
417
416
let c = c. strip_prefix ( '#' ) . unwrap_or ( c) ;
418
417
419
418
if c. len ( ) != 6 {
@@ -429,15 +428,15 @@ fn parse_color(c: &str) -> Result<rgb::RGB8, String> {
429
428
}
430
429
431
430
fn parse_colors ( colors : & str ) -> Result < Vec < rgb:: RGB8 > , String > {
432
- colors. split ( | c : char | c == ' ' || c == ',' )
431
+ colors. split ( [ ' ' , ',' ] )
433
432
. filter ( |c| !c. is_empty ( ) )
434
433
. map ( parse_color)
435
434
. collect ( )
436
435
}
437
436
438
437
#[ test]
439
438
fn color_parser ( ) {
440
- assert_eq ! ( parse_colors( "#123456 78abCD,, ," ) . unwrap( ) , vec![ rgb:: RGB8 :: new( 0x12 , 0x34 , 0x56 ) , rgb:: RGB8 :: new( 0x78 , 0xab , 0xcd ) ] ) ;
439
+ assert_eq ! ( parse_colors( "#123456 78abCD,, ," ) . unwrap( ) , vec![ rgb:: RGB8 :: new( 0x12 , 0x34 , 0x56 ) , rgb:: RGB8 :: new( 0x78 , 0xab , 0xcd ) ] ) ;
441
440
assert ! ( parse_colors( "#12345" ) . is_err( ) ) ;
442
441
}
443
442
@@ -456,7 +455,7 @@ fn file_type(src: &mut SrcPath) -> BinResult<FileType> {
456
455
_ => {
457
456
let mut file = std:: fs:: File :: open ( path) ?;
458
457
file. read_exact ( & mut buf) ?;
459
- }
458
+ } ,
460
459
} ,
461
460
SrcPath :: Stdin ( stdin) => {
462
461
let buf_in = stdin. fill_buf ( ) ?;
@@ -494,18 +493,15 @@ fn check_if_paths_exist(paths: &[PathBuf]) -> BinResult<()> {
494
493
} ;
495
494
let canon = path. canonicalize ( ) ;
496
495
if let Some ( parent) = canon. as_deref ( ) . unwrap_or ( path) . parent ( ) {
497
- if parent. as_os_str ( ) != "" {
498
- if let Ok ( false ) = path. try_exists ( ) {
499
- use std:: fmt:: Write ;
500
- if msg. len ( ) > 80 {
501
- msg. push ( '\n' ) ;
502
- }
503
- write ! ( & mut msg, " (directory \" {}\" doesn't exist either)" , parent. display( ) ) ?;
504
-
496
+ if parent. as_os_str ( ) != "" && matches ! ( path. try_exists( ) , Ok ( false ) ) {
497
+ use std:: fmt:: Write ;
498
+ if msg. len ( ) > 80 {
499
+ msg. push ( '\n' ) ;
505
500
}
501
+ write ! ( & mut msg, " (directory \" {}\" doesn't exist either)" , parent. display( ) ) ?;
506
502
}
507
503
}
508
- if path. to_str ( ) . map_or ( false , |p| p. contains ( [ '*' , '?' , '[' ] ) ) {
504
+ if path. to_str ( ) . is_some_and ( |p| p. contains ( [ '*' , '?' , '[' ] ) ) {
509
505
msg += "\n The wildcard pattern did not match any files." ;
510
506
} else if path. is_relative ( ) {
511
507
use std:: fmt:: Write ;
@@ -514,7 +510,7 @@ fn check_if_paths_exist(paths: &[PathBuf]) -> BinResult<()> {
514
510
if path. extension ( ) == Some ( "gif" . as_ref ( ) ) {
515
511
msg = format ! ( "\n Did you mean to use -o \" {}\" to specify it as the output file instead?" , path. display( ) ) ;
516
512
}
517
- return Err ( msg. into ( ) )
513
+ return Err ( msg. into ( ) ) ;
518
514
}
519
515
Ok ( ( ) )
520
516
}
@@ -571,7 +567,7 @@ fn get_video_decoder(ftype: FileType, src: SrcPath, fps: source::Fps, _: Setting
571
567
SrcPath :: Path ( path) => path,
572
568
SrcPath :: Stdin ( _) => Path :: new ( "video.mp4" ) ,
573
569
} ;
574
- let rel_path = path. file_name ( ) . map ( Path :: new) . unwrap_or ( path ) ;
570
+ let rel_path = path. file_name ( ) . map_or ( path , Path :: new) ;
575
571
Err ( format ! ( r#"Video support is permanently disabled in this distribution of gifski.
576
572
577
573
The only 'video' format supported at this time is YUV4MPEG2, which can be piped from ffmpeg:
@@ -627,12 +623,12 @@ impl ProgressReporter for ProgressBar {
627
623
let total_size = bytes * self . pb . total / self . frames ;
628
624
let new_estimate = if total_size >= self . previous_estimate { total_size } else { ( self . previous_estimate + total_size) / 2 } ;
629
625
self . previous_estimate = new_estimate;
630
- if self . displayed_estimate . abs_diff ( new_estimate) > new_estimate/ 10 {
626
+ if self . displayed_estimate . abs_diff ( new_estimate) > new_estimate / 10 {
631
627
self . displayed_estimate = new_estimate;
632
628
let ( num, unit, x) = if new_estimate > 1_000_000 {
633
- ( new_estimate as f64 / 1_000_000. , "MB" , if new_estimate > 10_000_000 { 0 } else { 1 } )
629
+ ( new_estimate as f64 / 1_000_000. , "MB" , if new_estimate > 10_000_000 { 0 } else { 1 } )
634
630
} else {
635
- ( new_estimate as f64 / 1_000. , "KB" , 0 )
631
+ ( new_estimate as f64 / 1_000. , "KB" , 0 )
636
632
} ;
637
633
self . pb . message ( & format ! ( "{num:.x$}{unit} GIF; Frame " ) ) ;
638
634
}
0 commit comments