@@ -75,6 +75,7 @@ struct Format {
75
75
max_width : usize ,
76
76
max_print : usize ,
77
77
term_integration : TerminalIntegration ,
78
+ unicode : bool ,
78
79
}
79
80
80
81
/// Controls terminal progress integration via OSC sequences.
@@ -229,6 +230,7 @@ impl<'gctx> Progress<'gctx> {
229
230
// even on narrow (e.g. 80 char) terminals.
230
231
max_print : 50 ,
231
232
term_integration : TerminalIntegration :: from_config ( gctx) ,
233
+ unicode : gctx. shell ( ) . err_unicode ( ) ,
232
234
} ,
233
235
name : name. to_string ( ) ,
234
236
done : false ,
@@ -261,8 +263,7 @@ impl<'gctx> Progress<'gctx> {
261
263
/// * `cur` should be how far along the progress is.
262
264
/// * `max` is the maximum value for the progress bar.
263
265
/// * `msg` is a small piece of text to display at the end of the progress
264
- /// bar. It will be truncated with `...` if it does not fit on the
265
- /// terminal.
266
+ /// bar. It will be truncated with `…` if it does not fit on the terminal.
266
267
///
267
268
/// This may not actually update the display if `tick` is being called too
268
269
/// quickly.
@@ -521,20 +522,23 @@ impl Format {
521
522
fn render ( & self , string : & mut String , msg : & str ) {
522
523
let mut avail_msg_len = self . max_width - string. len ( ) - 15 ;
523
524
let mut ellipsis_pos = 0 ;
524
- if avail_msg_len <= 3 {
525
+
526
+ let ( ellipsis, ellipsis_width) = if self . unicode { ( "…" , 1 ) } else { ( "..." , 3 ) } ;
527
+
528
+ if avail_msg_len <= ellipsis_width {
525
529
return ;
526
530
}
527
531
for c in msg. chars ( ) {
528
532
let display_width = c. width ( ) . unwrap_or ( 0 ) ;
529
533
if avail_msg_len >= display_width {
530
534
avail_msg_len -= display_width;
531
535
string. push ( c) ;
532
- if avail_msg_len >= 3 {
536
+ if avail_msg_len >= ellipsis_width {
533
537
ellipsis_pos = string. len ( ) ;
534
538
}
535
539
} else {
536
540
string. truncate ( ellipsis_pos) ;
537
- string. push_str ( "..." ) ;
541
+ string. push_str ( ellipsis ) ;
538
542
break ;
539
543
}
540
544
}
@@ -569,6 +573,7 @@ fn test_progress_status() {
569
573
max_print : 40 ,
570
574
max_width : 60 ,
571
575
term_integration : TerminalIntegration :: new ( false ) ,
576
+ unicode : true ,
572
577
} ;
573
578
assert_eq ! (
574
579
format. progress_status( 0 , 4 , "" ) ,
@@ -610,7 +615,7 @@ fn test_progress_status() {
610
615
) ;
611
616
assert_eq ! (
612
617
format. progress_status( 3 , 4 , ": msg that's just fit" ) ,
613
- Some ( "[=============> ] 3/4: msg that's just... " . to_string( ) )
618
+ Some ( "[=============> ] 3/4: msg that's just f… " . to_string( ) )
614
619
) ;
615
620
616
621
// combining diacritics have width zero and thus can fit max_width.
@@ -623,16 +628,16 @@ fn test_progress_status() {
623
628
// some non-ASCII ellipsize test
624
629
assert_eq ! (
625
630
format. progress_status( 3 , 4 , "_123456789123456e\u{301} \u{301} 8\u{301} 90a" ) ,
626
- Some ( "[=============> ] 3/4_123456789123456e\u{301} \u{301} ... " . to_string( ) )
631
+ Some ( "[=============> ] 3/4_123456789123456e\u{301} \u{301} 8 \u{301} 9… " . to_string( ) )
627
632
) ;
628
633
assert_eq ! (
629
634
format. progress_status( 3 , 4 , ":每個漢字佔據了兩個字元" ) ,
630
- Some ( "[=============> ] 3/4:每個漢字佔據了... " . to_string( ) )
635
+ Some ( "[=============> ] 3/4:每個漢字佔據了兩… " . to_string( ) )
631
636
) ;
632
637
assert_eq ! (
633
638
// handle breaking at middle of character
634
639
format. progress_status( 3 , 4 , ":-每個漢字佔據了兩個字元" ) ,
635
- Some ( "[=============> ] 3/4:-每個漢字佔據了... " . to_string( ) )
640
+ Some ( "[=============> ] 3/4:-每個漢字佔據了兩… " . to_string( ) )
636
641
) ;
637
642
}
638
643
@@ -643,6 +648,7 @@ fn test_progress_status_percentage() {
643
648
max_print : 40 ,
644
649
max_width : 60 ,
645
650
term_integration : TerminalIntegration :: new ( false ) ,
651
+ unicode : true ,
646
652
} ;
647
653
assert_eq ! (
648
654
format. progress_status( 0 , 77 , "" ) ,
@@ -669,6 +675,7 @@ fn test_progress_status_too_short() {
669
675
max_print : 25 ,
670
676
max_width : 25 ,
671
677
term_integration : TerminalIntegration :: new ( false ) ,
678
+ unicode : true ,
672
679
} ;
673
680
assert_eq ! (
674
681
format. progress_status( 1 , 1 , "" ) ,
@@ -680,6 +687,7 @@ fn test_progress_status_too_short() {
680
687
max_print : 24 ,
681
688
max_width : 24 ,
682
689
term_integration : TerminalIntegration :: new ( false ) ,
690
+ unicode : true ,
683
691
} ;
684
692
assert_eq ! ( format. progress_status( 1 , 1 , "" ) , None ) ;
685
693
}
0 commit comments