@@ -44,6 +44,7 @@ struct Info {
44
44
number_of_lines : usize ,
45
45
license : String ,
46
46
custom_logo : Language ,
47
+ custom_colors : Vec < String > ,
47
48
}
48
49
49
50
impl fmt:: Display for Info {
@@ -376,6 +377,50 @@ fn main() -> Result<()> {
376
377
. takes_value ( true )
377
378
. default_value ( "" )
378
379
. help ( "Overrides showing the dominant language ascii logo" ) )
380
+ . arg ( Arg :: with_name ( "colors" )
381
+ . short ( "c" )
382
+ . long ( "colors" )
383
+ . multiple ( true )
384
+ . takes_value ( true )
385
+ . possible_values ( & [
386
+ "0" ,
387
+ "1" ,
388
+ "2" ,
389
+ "3" ,
390
+ "4" ,
391
+ "5" ,
392
+ "6" ,
393
+ "7" ,
394
+ "8" ,
395
+ "9" ,
396
+ "10" ,
397
+ "11" ,
398
+ "12" ,
399
+ "13" ,
400
+ "14" ,
401
+ "15" ,
402
+ ] )
403
+ . hide_possible_values ( true )
404
+ . help ( & format ! (
405
+ "Specifies a preferred color set. Unspecified colors will remain as default.
406
+ Possible values: [{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15}]" ,
407
+ "0" . black( ) ,
408
+ "1" . red( ) ,
409
+ "2" . green( ) ,
410
+ "3" . yellow( ) ,
411
+ "4" . blue( ) ,
412
+ "5" . magenta( ) ,
413
+ "6" . cyan( ) ,
414
+ "7" . white( ) ,
415
+ "8" . bright_black( ) ,
416
+ "9" . bright_red( ) ,
417
+ "10" . bright_green( ) ,
418
+ "11" . bright_yellow( ) ,
419
+ "12" . bright_blue( ) ,
420
+ "13" . bright_magenta( ) ,
421
+ "14" . bright_cyan( ) ,
422
+ "15" . bright_white( ) ,
423
+ ) ) )
379
424
. get_matches ( ) ;
380
425
let dir = String :: from ( matches. value_of ( "directory" ) . unwrap ( ) ) ;
381
426
let custom_logo: Language = Language :: from_str (
@@ -399,6 +444,11 @@ fn main() -> Result<()> {
399
444
let repo_size = get_packed_size ( & dir) ?;
400
445
let last_change = get_last_change ( & dir) ?;
401
446
let creation_date = get_creation_time ( ) . unwrap ( ) ;
447
+ let custom_colors: Vec < String > = if let Some ( values) = matches. values_of ( "colors" ) {
448
+ values. map ( String :: from) . collect ( )
449
+ } else {
450
+ Vec :: new ( )
451
+ } ;
402
452
403
453
let info = Info {
404
454
project_name : config. repository_name ,
@@ -415,6 +465,7 @@ fn main() -> Result<()> {
415
465
number_of_lines : get_total_loc ( & tokei_langs) ,
416
466
license : project_license ( & dir) ?,
417
467
custom_logo,
468
+ custom_colors,
418
469
} ;
419
470
420
471
println ! ( "{}" , info) ;
@@ -871,7 +922,7 @@ impl Info {
871
922
& self . custom_logo
872
923
} ;
873
924
874
- match language {
925
+ let colors = match language {
875
926
Language :: Assembly => vec ! [ Color :: Cyan ] ,
876
927
Language :: C => vec ! [ Color :: BrightBlue , Color :: Blue ] ,
877
928
Language :: Clojure => vec ! [ Color :: BrightBlue , Color :: BrightGreen ] ,
@@ -908,7 +959,17 @@ impl Info {
908
959
Language :: Php => vec ! [ Color :: BrightWhite ] ,
909
960
Language :: Zig => vec ! [ Color :: Yellow ] ,
910
961
Language :: Unknown => vec ! [ Color :: White ] ,
911
- }
962
+ } ;
963
+
964
+ let colors: Vec < Color > = colors. iter ( ) . enumerate ( ) . map ( |( index, default_color) | {
965
+ if let Some ( color_num) = self . custom_colors . get ( index) {
966
+ if let Some ( color) = num_to_color ( color_num) {
967
+ return color;
968
+ }
969
+ }
970
+ * default_color
971
+ } ) . collect ( ) ;
972
+ colors
912
973
}
913
974
}
914
975
@@ -941,3 +1002,26 @@ impl fmt::Debug for Error {
941
1002
write ! ( f, "{}" , content)
942
1003
}
943
1004
}
1005
+
1006
+ fn num_to_color ( num : & str ) -> Option < Color > {
1007
+ let color = match num {
1008
+ "0" => Color :: Black ,
1009
+ "1" => Color :: Red ,
1010
+ "2" => Color :: Green ,
1011
+ "3" => Color :: Yellow ,
1012
+ "4" => Color :: Blue ,
1013
+ "5" => Color :: Magenta ,
1014
+ "6" => Color :: Cyan ,
1015
+ "7" => Color :: White ,
1016
+ "8" => Color :: BrightBlack ,
1017
+ "9" => Color :: BrightRed ,
1018
+ "10" => Color :: BrightGreen ,
1019
+ "11" => Color :: BrightYellow ,
1020
+ "12" => Color :: BrightBlue ,
1021
+ "13" => Color :: BrightMagenta ,
1022
+ "14" => Color :: BrightCyan ,
1023
+ "15" => Color :: BrightWhite ,
1024
+ _ => return None ,
1025
+ } ;
1026
+ Some ( color)
1027
+ }
0 commit comments