Skip to content

Commit 66a90a6

Browse files
RDruondjc
authored andcommitted
Handle MultiProgress println
1 parent 80fd142 commit 66a90a6

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/multi.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,14 @@ impl MultiState {
259259
if panicking() {
260260
return Ok(());
261261
}
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+
}
262270

263271
// Assumption: if extra_lines is not None, then it has at least one line
264272
debug_assert_eq!(
@@ -279,9 +287,8 @@ impl MultiState {
279287
let line_count = member
280288
.draw_state
281289
.as_ref()
282-
.map(|d| d.lines.len())
290+
.map(|d| real_len(&d.lines, width))
283291
.unwrap_or_default();
284-
285292
// Track the total number of zombie lines on the screen.
286293
self.zombie_lines_count += line_count;
287294

@@ -300,7 +307,7 @@ impl MultiState {
300307
self.zombie_lines_count = 0;
301308
}
302309

303-
let orphan_lines_count = self.orphan_lines.len();
310+
let orphan_lines_count = real_len(&self.orphan_lines, width);
304311
force_draw |= orphan_lines_count > 0;
305312
let mut drawable = match self.draw_target.drawable(force_draw, now) {
306313
Some(drawable) => drawable,
@@ -313,7 +320,7 @@ impl MultiState {
313320

314321
if let Some(extra_lines) = &extra_lines {
315322
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);
317324
}
318325

319326
// Add lines from `ProgressBar::println` call.

0 commit comments

Comments
 (0)