@@ -46,7 +46,7 @@ struct Info {
46
46
license : String ,
47
47
custom_logo : Language ,
48
48
custom_colors : Vec < String > ,
49
- disable_fields : Vec < InfoFields > ,
49
+ disable_fields : InfoFieldOn ,
50
50
}
51
51
52
52
impl fmt:: Display for Info {
@@ -57,7 +57,7 @@ impl fmt::Display for Info {
57
57
None => Color :: White ,
58
58
} ;
59
59
60
- if !self . disable_fields . contains ( & InfoFields :: Project ) {
60
+ if !self . disable_fields . project {
61
61
writeln ! (
62
62
buffer,
63
63
"{}{}" ,
@@ -66,7 +66,7 @@ impl fmt::Display for Info {
66
66
) ?;
67
67
}
68
68
69
- if !self . disable_fields . contains ( & InfoFields :: HEAD ) {
69
+ if !self . disable_fields . head {
70
70
writeln ! (
71
71
buffer,
72
72
"{}{}" ,
@@ -75,7 +75,7 @@ impl fmt::Display for Info {
75
75
) ?;
76
76
}
77
77
78
- if !self . disable_fields . contains ( & InfoFields :: Version ) {
78
+ if !self . disable_fields . version {
79
79
writeln ! (
80
80
buffer,
81
81
"{}{}" ,
@@ -84,7 +84,7 @@ impl fmt::Display for Info {
84
84
) ?;
85
85
}
86
86
87
- if !self . disable_fields . contains ( & InfoFields :: Created ) {
87
+ if !self . disable_fields . created {
88
88
writeln ! (
89
89
buffer,
90
90
"{}{}" ,
@@ -93,7 +93,7 @@ impl fmt::Display for Info {
93
93
) ?;
94
94
}
95
95
96
- if !self . disable_fields . contains ( & InfoFields :: Languages ) && !self . languages . is_empty ( ) {
96
+ if !self . disable_fields . languages && !self . languages . is_empty ( ) {
97
97
if self . languages . len ( ) > 1 {
98
98
let title = "Languages: " ;
99
99
let pad = " " . repeat ( title. len ( ) ) ;
@@ -118,7 +118,7 @@ impl fmt::Display for Info {
118
118
} ;
119
119
}
120
120
121
- if !self . disable_fields . contains ( & InfoFields :: Authors ) && !self . authors . is_empty ( ) {
121
+ if !self . disable_fields . authors && !self . authors . is_empty ( ) {
122
122
let title = if self . authors . len ( ) > 1 {
123
123
"Authors: "
124
124
} else {
@@ -134,7 +134,7 @@ impl fmt::Display for Info {
134
134
}
135
135
}
136
136
137
- if !self . disable_fields . contains ( & InfoFields :: LastChange ) {
137
+ if !self . disable_fields . last_change {
138
138
writeln ! (
139
139
buffer,
140
140
"{}{}" ,
@@ -143,11 +143,11 @@ impl fmt::Display for Info {
143
143
) ?;
144
144
}
145
145
146
- if !self . disable_fields . contains ( & InfoFields :: Repo ) {
146
+ if !self . disable_fields . repo {
147
147
writeln ! ( buffer, "{}{}" , "Repo: " . color( color) . bold( ) , self . repo) ?;
148
148
}
149
149
150
- if !self . disable_fields . contains ( & InfoFields :: Commits ) {
150
+ if !self . disable_fields . commits {
151
151
writeln ! (
152
152
buffer,
153
153
"{}{}" ,
@@ -156,7 +156,7 @@ impl fmt::Display for Info {
156
156
) ?;
157
157
}
158
158
159
- if !self . disable_fields . contains ( & InfoFields :: LinesOfCode ) {
159
+ if !self . disable_fields . lines_of_code {
160
160
writeln ! (
161
161
buffer,
162
162
"{}{}" ,
@@ -165,7 +165,7 @@ impl fmt::Display for Info {
165
165
) ?;
166
166
}
167
167
168
- if !self . disable_fields . contains ( & InfoFields :: Size ) {
168
+ if !self . disable_fields . size {
169
169
writeln ! (
170
170
buffer,
171
171
"{}{}" ,
@@ -174,7 +174,7 @@ impl fmt::Display for Info {
174
174
) ?;
175
175
}
176
176
177
- if !self . disable_fields . contains ( & InfoFields :: License ) {
177
+ if !self . disable_fields . license {
178
178
writeln ! (
179
179
buffer,
180
180
"{}{}" ,
@@ -320,6 +320,22 @@ impl fmt::Display for CommitInfo {
320
320
}
321
321
}
322
322
323
+ #[ derive( Default ) ]
324
+ struct InfoFieldOn {
325
+ project : bool ,
326
+ head : bool ,
327
+ version : bool ,
328
+ created : bool ,
329
+ languages : bool ,
330
+ authors : bool ,
331
+ last_change : bool ,
332
+ repo : bool ,
333
+ commits : bool ,
334
+ lines_of_code : bool ,
335
+ size : bool ,
336
+ license : bool ,
337
+ }
338
+
323
339
#[ derive( PartialEq , Eq , EnumString , EnumCount , EnumIter , IntoStaticStr ) ]
324
340
#[ strum( serialize_all = "snake_case" ) ]
325
341
enum InfoFields {
@@ -509,15 +525,31 @@ Possible values: [{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15}]",
509
525
. unwrap ( )
510
526
. to_lowercase ( ) )
511
527
. unwrap_or ( Language :: Unknown ) ;
512
- let disable_fields: Vec < InfoFields > = matches. values_of ( "disable_field" )
528
+ let mut disable_fields = InfoFieldOn { ..Default :: default ( ) } ;
529
+
530
+ matches. values_of ( "disable_field" )
513
531
. unwrap ( )
514
532
. map ( String :: from)
515
- . filter_map ( |field : String | {
533
+ . for_each ( |field : String | {
516
534
let item = InfoFields :: from_str ( field. to_lowercase ( ) . as_str ( ) )
517
535
. unwrap_or ( InfoFields :: UnrecognizedField ) ;
518
- if item == InfoFields :: UnrecognizedField { None } else { Some ( item) }
519
- } )
520
- . collect ( ) ;
536
+
537
+ match item {
538
+ InfoFields :: Project => disable_fields. project = true ,
539
+ InfoFields :: HEAD => disable_fields. head = true ,
540
+ InfoFields :: Version => disable_fields. version = true ,
541
+ InfoFields :: Created => disable_fields. created = true ,
542
+ InfoFields :: Languages => disable_fields. languages = true ,
543
+ InfoFields :: Authors => disable_fields. authors = true ,
544
+ InfoFields :: LastChange => disable_fields. last_change = true ,
545
+ InfoFields :: Repo => disable_fields. repo = true ,
546
+ InfoFields :: Commits => disable_fields. commits = true ,
547
+ InfoFields :: LinesOfCode => disable_fields. lines_of_code = true ,
548
+ InfoFields :: Size => disable_fields. size = true ,
549
+ InfoFields :: License => disable_fields. license = true ,
550
+ _ => ( ) ,
551
+ }
552
+ } ) ;
521
553
522
554
let tokei_langs = project_languages ( & dir) ;
523
555
let languages_stat = get_languages_stat ( & tokei_langs) . ok_or ( Error :: SourceCodeNotFound ) ?;
0 commit comments