Skip to content

Commit

Permalink
Fix MultiProgress println when having no bars
Browse files Browse the repository at this point in the history
Fixes #447
  • Loading branch information
Ekleog authored and spoutn1k committed Sep 26, 2024
1 parent 5396704 commit d345567
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/draw_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,15 @@ impl DrawState {
if idx != 0 {
term.write_line("")?;
}
term.write_str(line)?;

if idx + 1 != len || self.lines.len() == self.orphan_lines_count {
term.write_line(line)?;
} else {
// Don't append a '\n' if this is the last line and we're not
// just going to orphan all the lines
term.write_str(line)?;
}

if idx + 1 == len {
// Keep the cursor on the right terminal side
// So that next user writes/prints will happen on the next line
Expand Down Expand Up @@ -736,4 +744,22 @@ mod tests {
assert_eq!(result, case.expectation.into(), "case: {:?}", case);
}
}

#[cfg(feature = "in_memory")]
#[test]
fn multi_progress_println_newline() {
let in_mem = crate::InMemoryTerm::new(10, 10);
let mp = MultiProgress::with_draw_target(ProgressDrawTarget::term_like(Box::new(
in_mem.clone(),
)));

mp.println("This line is tooooooo long for the terminal\r\n")
.unwrap();
mp.println("but it should wrap correctly\r\n").unwrap();

assert_eq!(
in_mem.contents(),
"This line\nis toooooo\no long for\n the termi\nnal\nbut it sho\nuld wrap c\norrectly"
);
}
}

0 comments on commit d345567

Please sign in to comment.