@@ -38,20 +38,13 @@ pub struct Info {
38
38
impl std:: fmt:: Display for Info {
39
39
fn fmt ( & self , f : & mut std:: fmt:: Formatter ) -> std:: fmt:: Result {
40
40
if !self . config . disabled_fields . git_info
41
- && !& self . git_username . is_empty ( )
42
- && !& self . git_version . is_empty ( )
41
+ && ( !& self . git_username . is_empty ( ) || !& self . git_version . is_empty ( ) )
43
42
{
44
- let git_info_length = self . git_username . len ( ) + self . git_version . len ( ) + 3 ;
43
+ let git_info_field = self . get_git_info_field ( ) ;
45
44
46
- writeln ! (
47
- f,
48
- "{} {} {}" ,
49
- & self . bold( & self . git_username) . color( self . text_colors. title) ,
50
- & self . bold( "~" ) . color( self . text_colors. tilde) ,
51
- & self . bold( & self . git_version) . color( self . text_colors. title)
52
- ) ?;
45
+ writeln ! ( f, "{}" , git_info_field. 0 ) ?;
53
46
54
- let separator = "-" . repeat ( git_info_length ) ;
47
+ let separator = "-" . repeat ( git_info_field . 1 ) ;
55
48
56
49
writeln ! ( f, "{}" , separator. color( self . text_colors. underline) ) ?;
57
50
}
@@ -289,6 +282,31 @@ impl Info {
289
282
}
290
283
}
291
284
285
+ fn get_git_info_field ( & self ) -> ( String , usize ) {
286
+ let git_info_length = self . git_username . len ( ) + self . git_version . len ( ) ;
287
+
288
+ if !& self . git_username . is_empty ( ) && !& self . git_version . is_empty ( ) {
289
+ (
290
+ format ! (
291
+ "{} {} {}" ,
292
+ & self . bold( & self . git_username) . color( self . text_colors. title) ,
293
+ & self . bold( "~" ) . color( self . text_colors. tilde) ,
294
+ & self . bold( & self . git_version) . color( self . text_colors. title)
295
+ ) ,
296
+ git_info_length + 3 ,
297
+ )
298
+ } else {
299
+ (
300
+ format ! (
301
+ "{}{}" ,
302
+ & self . bold( & self . git_username) . color( self . text_colors. title) ,
303
+ & self . bold( & self . git_version) . color( self . text_colors. title)
304
+ ) ,
305
+ git_info_length,
306
+ )
307
+ }
308
+ }
309
+
292
310
fn get_author_field ( & self , title : & str ) -> String {
293
311
let mut author_field = String :: from ( "" ) ;
294
312
0 commit comments