@@ -4,7 +4,7 @@ use std::fs;
4
4
use std:: process:: Command ;
5
5
use std:: str:: FromStr ;
6
6
7
- use colored:: { Color , Colorize } ;
7
+ use colored:: { Color , Colorize , ColoredString } ;
8
8
use git2:: Repository ;
9
9
use license:: License ;
10
10
@@ -32,6 +32,7 @@ pub struct Info {
32
32
custom_logo : Language ,
33
33
custom_colors : Vec < String > ,
34
34
disable_fields : InfoFieldOn ,
35
+ bold_enabled : bool ,
35
36
}
36
37
37
38
impl std:: fmt:: Display for Info {
@@ -55,19 +56,19 @@ impl std::fmt::Display for Info {
55
56
write_buf ( & mut buf, "" , & separator, color) ?;
56
57
}
57
58
if !self . disable_fields . project {
58
- write_buf ( & mut buf, "Project: " , & self . project_name , color ) ?;
59
+ write_buf ( & mut buf, & self . get_formatted_info_label ( "Project: " , color ) , & self . project_name ) ?;
59
60
}
60
61
61
62
if !self . disable_fields . head {
62
- write_buf ( & mut buf, "HEAD: " , & self . current_commit , color ) ?;
63
+ write_buf ( & mut buf, & self . get_formatted_info_label ( "HEAD: " , color ) , & self . current_commit ) ?;
63
64
}
64
65
65
66
if !self . disable_fields . version {
66
- write_buf ( & mut buf, "Version: " , & self . version , color ) ?;
67
+ write_buf ( & mut buf, & self . get_formatted_info_label ( "Version: " , color ) , & self . version ) ?;
67
68
}
68
69
69
70
if !self . disable_fields . created {
70
- write_buf ( & mut buf, "Created: " , & self . creation_date , color ) ?;
71
+ write_buf ( & mut buf, & self . get_formatted_info_label ( "Created: " , color ) , & self . creation_date ) ?;
71
72
}
72
73
73
74
if !self . disable_fields . languages && !self . languages . is_empty ( ) {
@@ -83,9 +84,9 @@ impl std::fmt::Display for Info {
83
84
s = s + & format ! ( "{} ({} %) " , language. 0 , formatted_number) ;
84
85
}
85
86
}
86
- writeln ! ( buf, "{}{}" , title . color ( color) . bold ( ) , s) ?;
87
+ writeln ! ( buf, "{}{}" , & self . get_formatted_info_label ( title , color) , s) ?;
87
88
} else {
88
- write_buf ( & mut buf, "Language: " , & self . dominant_language , color ) ?;
89
+ write_buf ( & mut buf, & self . get_formatted_info_label ( "Language: " , color ) , & self . dominant_language ) ?;
89
90
} ;
90
91
}
91
92
@@ -99,7 +100,7 @@ impl std::fmt::Display for Info {
99
100
writeln ! (
100
101
buf,
101
102
"{}{}% {} {}" ,
102
- title . color ( color) . bold ( ) ,
103
+ & self . get_formatted_info_label ( title , color) ,
103
104
self . authors[ 0 ] . 2 ,
104
105
self . authors[ 0 ] . 0 ,
105
106
self . authors[ 0 ] . 1
@@ -108,10 +109,11 @@ impl std::fmt::Display for Info {
108
109
let title = " " . repeat ( title. len ( ) ) ;
109
110
110
111
for author in self . authors . iter ( ) . skip ( 1 ) {
112
+
111
113
writeln ! (
112
114
buf,
113
115
"{}{}% {} {}" ,
114
- title . color ( color) . bold ( ) ,
116
+ & self . get_formatted_info_label ( & title , color) ,
115
117
author. 2 ,
116
118
author. 0 ,
117
119
author. 1
@@ -120,27 +122,27 @@ impl std::fmt::Display for Info {
120
122
}
121
123
122
124
if !self . disable_fields . last_change {
123
- write_buf ( & mut buf, "Last change: " , & self . last_change , color ) ?;
125
+ write_buf ( & mut buf, & self . get_formatted_info_label ( "Last change: " , color ) , & self . last_change ) ?;
124
126
}
125
127
126
128
if !self . disable_fields . repo {
127
- write_buf ( & mut buf, "Repo: " , & self . repo , color ) ?;
129
+ write_buf ( & mut buf, & self . get_formatted_info_label ( "Repo: " , color ) , & self . repo ) ?;
128
130
}
129
131
130
132
if !self . disable_fields . commits {
131
- write_buf ( & mut buf, "Commits: " , & self . commits , color ) ?;
133
+ write_buf ( & mut buf, & self . get_formatted_info_label ( "Commits: " , color ) , & self . commits ) ?;
132
134
}
133
135
134
136
if !self . disable_fields . lines_of_code {
135
- write_buf ( & mut buf, "Lines of code: " , & self . number_of_lines , color ) ?;
137
+ write_buf ( & mut buf, & self . get_formatted_info_label ( "Lines of code: " , color ) , & self . number_of_lines ) ?;
136
138
}
137
139
138
140
if !self . disable_fields . size {
139
- write_buf ( & mut buf, "Size: " , & self . repo_size , color ) ?;
141
+ write_buf ( & mut buf, & self . get_formatted_info_label ( "Size: " , color ) , & self . repo_size ) ?;
140
142
}
141
143
142
144
if !self . disable_fields . license {
143
- write_buf ( & mut buf, "License: " , & self . license , color ) ?;
145
+ write_buf ( & mut buf, & self . get_formatted_info_label ( "License: " , color ) , & self . license ) ?;
144
146
}
145
147
146
148
writeln ! (
@@ -164,7 +166,7 @@ impl std::fmt::Display for Info {
164
166
" " . on_bright_white( ) ,
165
167
) ?;
166
168
167
- let mut logo_lines = AsciiArt :: new ( self . get_ascii ( ) , self . colors ( ) ) ;
169
+ let mut logo_lines = AsciiArt :: new ( self . get_ascii ( ) , self . colors ( ) , self . bold_enabled ) ;
168
170
let mut info_lines = buf. lines ( ) ;
169
171
170
172
let center_pad = " " ;
@@ -199,6 +201,7 @@ impl Info {
199
201
logo : Language ,
200
202
colors : Vec < String > ,
201
203
disabled : InfoFieldOn ,
204
+ bold_flag : bool ,
202
205
) -> Result < Info > {
203
206
let authors = Info :: get_authors ( & dir, 3 ) ;
204
207
let ( git_v, git_user) = Info :: get_git_info ( & dir) ;
@@ -232,6 +235,7 @@ impl Info {
232
235
custom_logo : logo,
233
236
custom_colors : colors,
234
237
disable_fields : disabled,
238
+ bold_enabled : bold_flag,
235
239
} )
236
240
}
237
241
@@ -573,13 +577,21 @@ impl Info {
573
577
} ;
574
578
Some ( color)
575
579
}
580
+
581
+ /// Returns a formatted info label with the desired color and boldness
582
+ fn get_formatted_info_label ( & self , label : & str , color : Color ) -> ColoredString {
583
+ let mut formatted_label = label. color ( color) ;
584
+ if self . bold_enabled {
585
+ formatted_label = formatted_label. bold ( ) ;
586
+ }
587
+ formatted_label
588
+ }
576
589
}
577
590
578
591
fn write_buf < T : std:: fmt:: Display > (
579
592
buffer : & mut String ,
580
- title : & str ,
593
+ title : & ColoredString ,
581
594
content : T ,
582
- color : Color ,
583
595
) -> std:: fmt:: Result {
584
- writeln ! ( buffer, "{}{}" , title. color ( color ) . bold ( ) , content)
596
+ writeln ! ( buffer, "{}{}" , title, content)
585
597
}
0 commit comments