@@ -259,6 +259,14 @@ impl MultiState {
259
259
if panicking ( ) {
260
260
return Ok ( ( ) ) ;
261
261
}
262
+ let width = self . width ( ) as f64 ;
263
+ // Calculate real length based on terminal width
264
+ // This take in account linewrap from terminal
265
+ fn real_len ( lines : & [ String ] , width : f64 ) -> usize {
266
+ lines. iter ( ) . fold ( 0 , |sum, val| {
267
+ sum + ( console:: measure_text_width ( val) as f64 / width) . ceil ( ) as usize
268
+ } )
269
+ }
262
270
263
271
// Assumption: if extra_lines is not None, then it has at least one line
264
272
debug_assert_eq ! (
@@ -279,9 +287,8 @@ impl MultiState {
279
287
let line_count = member
280
288
. draw_state
281
289
. as_ref ( )
282
- . map ( |d| d. lines . len ( ) )
290
+ . map ( |d| real_len ( & d. lines , width ) )
283
291
. unwrap_or_default ( ) ;
284
-
285
292
// Track the total number of zombie lines on the screen.
286
293
self . zombie_lines_count += line_count;
287
294
@@ -300,7 +307,7 @@ impl MultiState {
300
307
self . zombie_lines_count = 0 ;
301
308
}
302
309
303
- let orphan_lines_count = self . orphan_lines . len ( ) ;
310
+ let orphan_lines_count = real_len ( & self . orphan_lines , width ) ;
304
311
force_draw |= orphan_lines_count > 0 ;
305
312
let mut drawable = match self . draw_target . drawable ( force_draw, now) {
306
313
Some ( drawable) => drawable,
@@ -313,7 +320,7 @@ impl MultiState {
313
320
314
321
if let Some ( extra_lines) = & extra_lines {
315
322
draw_state. lines . extend_from_slice ( extra_lines. as_slice ( ) ) ;
316
- draw_state. orphan_lines_count += extra_lines . len ( ) ;
323
+ draw_state. orphan_lines_count += real_len ( extra_lines , width ) ;
317
324
}
318
325
319
326
// Add lines from `ProgressBar::println` call.
0 commit comments