@@ -248,7 +248,7 @@ impl fmt::Display for Info {
248
248
None => "" ,
249
249
} ;
250
250
251
- let ( logo_line, extra_pad) = colorize_str ( logo_line, self . colors ( ) ) ;
251
+ let ( logo_line, extra_pad) = colorize_str ( logo_line, self . colors ( ) , self . bold_enabled ) ;
252
252
// If the string is empty the extra padding should not be added
253
253
let pad = if logo_line. is_empty ( ) {
254
254
left_pad
@@ -267,15 +267,18 @@ fn count_newlines(s: &str) -> usize {
267
267
}
268
268
269
269
/// Transforms a string with color format into one with proper
270
- /// escape characters for color display.
270
+ /// escape characters for color display. This function is also
271
+ /// responsible for formatting the string as bold depending on
272
+ /// whether or not the user explicitly turned off boldness for
273
+ /// onefetch.
271
274
///
272
275
/// Colors are specified with {0}, {1}... where the number represents
273
276
/// the nth element in the colors Vec provided to the function.
274
277
/// If there are more colors in the ascii than in the Vec it
275
278
/// defaults to white.
276
279
/// The usize in the tuple refers to the extra padding needed
277
280
/// which comes from the added escape characters.
278
- fn colorize_str ( line : & str , colors : Vec < Color > ) -> ( String , usize ) {
281
+ fn colorize_str ( line : & str , colors : Vec < Color > , bold : bool ) -> ( String , usize ) {
279
282
// Extract colors from string coded with {n}
280
283
let mut colors_in_str: Vec < Color > = line. split ( '{' ) . fold ( Vec :: new ( ) , |mut acc, s| {
281
284
if s. len ( ) > 2 {
@@ -301,11 +304,25 @@ fn colorize_str(line: &str, colors: Vec<Color>) -> (String, usize) {
301
304
Some ( & c) => c,
302
305
None => Color :: White ,
303
306
} ;
304
- acc. push_str ( & format ! ( "{}" , s. color( c) . bold( ) ) ) ;
307
+
308
+ // Make the string bold if boldness flag is set to 'on'
309
+ if bold {
310
+ acc. push_str ( & format ! ( "{}" , s. color( c) . bold( ) ) ) ;
311
+ } else {
312
+ acc. push_str ( & format ! ( "{}" , s. color( c) ) ) ;
313
+ }
314
+
305
315
}
306
316
acc
307
317
} ) ;
308
- ( out_str, colors_in_str. len ( ) * 11 )
318
+
319
+ // Adjust the extra padding for the line. Use 2 less characters if not bold.
320
+ let padding_constant = if bold {
321
+ 11
322
+ } else {
323
+ 9
324
+ } ;
325
+ ( out_str, colors_in_str. len ( ) * padding_constant )
309
326
}
310
327
311
328
/// Returns the true length of a string after substracting the {n}
0 commit comments