@@ -23,6 +23,7 @@ pub struct ProgressStyle {
23
23
// how unicode-big each char in progress_chars is
24
24
char_width : usize ,
25
25
format_map : HashMap < & ' static str , fn ( & ProgressState ) -> String > ,
26
+ tab_width : usize ,
26
27
}
27
28
28
29
#[ cfg( feature = "unicode-segmentation" ) ]
@@ -91,6 +92,7 @@ impl ProgressStyle {
91
92
char_width,
92
93
template,
93
94
format_map : HashMap :: default ( ) ,
95
+ tab_width : 4 ,
94
96
}
95
97
}
96
98
@@ -140,6 +142,12 @@ impl ProgressStyle {
140
142
self
141
143
}
142
144
145
+ /// Sets the number of spaces to which tabs will be expanded. Default: 4
146
+ pub fn with_tab_width ( mut self , tab_width : usize ) -> ProgressStyle {
147
+ self . tab_width = tab_width;
148
+ self
149
+ }
150
+
143
151
/// Sets the template string for the progress bar
144
152
///
145
153
/// Review the [list of template keys](./index.html#templates) for more information.
@@ -327,6 +335,8 @@ impl ProgressStyle {
327
335
continue ;
328
336
}
329
337
338
+ buf = buf. replace ( '\t' , & " " . repeat ( self . tab_width ) ) ;
339
+
330
340
match width {
331
341
Some ( width) => {
332
342
let padded = PaddedStringDisplay {
@@ -348,7 +358,9 @@ impl ProgressStyle {
348
358
} ,
349
359
}
350
360
}
351
- TemplatePart :: Literal ( s) => cur. push_str ( s) ,
361
+ TemplatePart :: Literal ( s) => {
362
+ cur. push_str ( & s. replace ( '\t' , & " " . repeat ( self . tab_width ) ) )
363
+ }
352
364
TemplatePart :: NewLine => lines. push ( match wide {
353
365
Some ( inner) => {
354
366
inner. expand ( mem:: take ( & mut cur) , self , state, & mut buf, target_width)
@@ -398,7 +410,7 @@ impl<'a> WideElement<'a> {
398
410
buf. write_fmt ( format_args ! (
399
411
"{}" ,
400
412
PaddedStringDisplay {
401
- str : & style. message,
413
+ str : & style. message. replace ( '\t' , & " " . repeat ( style . tab_width ) ) ,
402
414
width: left,
403
415
align: * align,
404
416
truncate: true ,
0 commit comments