Skip to content

Commit

Permalink
Fix MultiProgress println when having no bars
Browse files Browse the repository at this point in the history
  • Loading branch information
Ekleog committed Feb 6, 2023
1 parent 1cbb573 commit 025a566
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/draw_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,11 @@ impl DrawState {

let len = self.lines.len();
for (idx, line) in self.lines.iter().enumerate() {
if idx + 1 != len {
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
// 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)?;
// Keep the cursor on the right terminal side
// So that next user writes/prints will happen on the next line
Expand Down Expand Up @@ -512,4 +513,17 @@ mod tests {
assert!(mp.is_hidden());
assert!(pb.is_hidden());
}

#[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 025a566

Please sign in to comment.