@@ -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 {
@@ -156,6 +157,27 @@ impl fmt::Display for Info {
156
157
self . license
157
158
) ?;
158
159
160
+ writeln ! (
161
+ buffer,
162
+ "\n {0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15}" ,
163
+ " " . on_black( ) ,
164
+ " " . on_red( ) ,
165
+ " " . on_green( ) ,
166
+ " " . on_yellow( ) ,
167
+ " " . on_blue( ) ,
168
+ " " . on_magenta( ) ,
169
+ " " . on_cyan( ) ,
170
+ " " . on_white( ) ,
171
+ " " . on_bright_black( ) ,
172
+ " " . on_bright_red( ) ,
173
+ " " . on_bright_green( ) ,
174
+ " " . on_bright_yellow( ) ,
175
+ " " . on_bright_blue( ) ,
176
+ " " . on_bright_magenta( ) ,
177
+ " " . on_bright_cyan( ) ,
178
+ " " . on_bright_white( ) ,
179
+ ) ?;
180
+
159
181
let logo = self . get_ascii ( ) ;
160
182
let mut logo_lines = logo. lines ( ) ;
161
183
let mut info_lines = buffer. lines ( ) ;
@@ -378,6 +400,50 @@ fn main() -> Result<()> {
378
400
. takes_value ( true )
379
401
. default_value ( "" )
380
402
. help ( "Overrides showing the dominant language ascii logo" ) )
403
+ . arg ( Arg :: with_name ( "colors" )
404
+ . short ( "c" )
405
+ . long ( "colors" )
406
+ . multiple ( true )
407
+ . takes_value ( true )
408
+ . possible_values ( & [
409
+ "0" ,
410
+ "1" ,
411
+ "2" ,
412
+ "3" ,
413
+ "4" ,
414
+ "5" ,
415
+ "6" ,
416
+ "7" ,
417
+ "8" ,
418
+ "9" ,
419
+ "10" ,
420
+ "11" ,
421
+ "12" ,
422
+ "13" ,
423
+ "14" ,
424
+ "15" ,
425
+ ] )
426
+ . hide_possible_values ( true )
427
+ . help ( & format ! (
428
+ "Specifies a preferred color set. Unspecified colors will remain as default.
429
+ Possible values: [{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15}]" ,
430
+ "0" . black( ) ,
431
+ "1" . red( ) ,
432
+ "2" . green( ) ,
433
+ "3" . yellow( ) ,
434
+ "4" . blue( ) ,
435
+ "5" . magenta( ) ,
436
+ "6" . cyan( ) ,
437
+ "7" . white( ) ,
438
+ "8" . bright_black( ) ,
439
+ "9" . bright_red( ) ,
440
+ "10" . bright_green( ) ,
441
+ "11" . bright_yellow( ) ,
442
+ "12" . bright_blue( ) ,
443
+ "13" . bright_magenta( ) ,
444
+ "14" . bright_cyan( ) ,
445
+ "15" . bright_white( ) ,
446
+ ) ) )
381
447
. get_matches ( ) ;
382
448
let dir = String :: from ( matches. value_of ( "directory" ) . unwrap ( ) ) ;
383
449
let custom_logo: Language = Language :: from_str (
@@ -401,6 +467,11 @@ fn main() -> Result<()> {
401
467
let repo_size = get_packed_size ( & dir) ?;
402
468
let last_change = get_last_change ( & dir) ?;
403
469
let creation_date = get_creation_time ( ) . unwrap ( ) ;
470
+ let custom_colors: Vec < String > = if let Some ( values) = matches. values_of ( "colors" ) {
471
+ values. map ( String :: from) . collect ( )
472
+ } else {
473
+ Vec :: new ( )
474
+ } ;
404
475
405
476
let info = Info {
406
477
project_name : config. repository_name ,
@@ -417,6 +488,7 @@ fn main() -> Result<()> {
417
488
number_of_lines : get_total_loc ( & tokei_langs) ,
418
489
license : project_license ( & dir) ?,
419
490
custom_logo,
491
+ custom_colors,
420
492
} ;
421
493
422
494
println ! ( "{}" , info) ;
@@ -876,7 +948,7 @@ impl Info {
876
948
& self . custom_logo
877
949
} ;
878
950
879
- match language {
951
+ let colors = match language {
880
952
Language :: Assembly => vec ! [ Color :: Cyan ] ,
881
953
Language :: C => vec ! [ Color :: BrightBlue , Color :: Blue ] ,
882
954
Language :: Clojure => vec ! [ Color :: BrightBlue , Color :: BrightGreen ] ,
@@ -914,7 +986,17 @@ impl Info {
914
986
Language :: Php => vec ! [ Color :: BrightWhite ] ,
915
987
Language :: Zig => vec ! [ Color :: Yellow ] ,
916
988
Language :: Unknown => vec ! [ Color :: White ] ,
917
- }
989
+ } ;
990
+
991
+ let colors: Vec < Color > = colors. iter ( ) . enumerate ( ) . map ( |( index, default_color) | {
992
+ if let Some ( color_num) = self . custom_colors . get ( index) {
993
+ if let Some ( color) = num_to_color ( color_num) {
994
+ return color;
995
+ }
996
+ }
997
+ * default_color
998
+ } ) . collect ( ) ;
999
+ colors
918
1000
}
919
1001
}
920
1002
@@ -947,3 +1029,26 @@ impl fmt::Debug for Error {
947
1029
write ! ( f, "{}" , content)
948
1030
}
949
1031
}
1032
+
1033
+ fn num_to_color ( num : & str ) -> Option < Color > {
1034
+ let color = match num {
1035
+ "0" => Color :: Black ,
1036
+ "1" => Color :: Red ,
1037
+ "2" => Color :: Green ,
1038
+ "3" => Color :: Yellow ,
1039
+ "4" => Color :: Blue ,
1040
+ "5" => Color :: Magenta ,
1041
+ "6" => Color :: Cyan ,
1042
+ "7" => Color :: White ,
1043
+ "8" => Color :: BrightBlack ,
1044
+ "9" => Color :: BrightRed ,
1045
+ "10" => Color :: BrightGreen ,
1046
+ "11" => Color :: BrightYellow ,
1047
+ "12" => Color :: BrightBlue ,
1048
+ "13" => Color :: BrightMagenta ,
1049
+ "14" => Color :: BrightCyan ,
1050
+ "15" => Color :: BrightWhite ,
1051
+ _ => return None ,
1052
+ } ;
1053
+ Some ( color)
1054
+ }
0 commit comments