Skip to content

Commit

Permalink
Handle terminal line wrap to avoid new line
Browse files Browse the repository at this point in the history
  • Loading branch information
RDruon authored and djc committed May 9, 2023
1 parent 4987fc5 commit 80fd142
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/draw_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,13 @@ impl DrawState {
};

let len = self.lines.len();
let mut real_len = 0;
for (idx, line) in self.lines.iter().enumerate() {
// Calculate real length based on terminal width
// This take in account linewrap from terminal
real_len +=
(console::measure_text_width(line) as f64 / term.width() as f64).ceil() as usize;

if idx + 1 != len {
term.write_line(line)?;
} else {
Expand All @@ -509,7 +515,7 @@ impl DrawState {
}

term.flush()?;
*last_line_count = self.lines.len() - self.orphan_lines_count + shift;
*last_line_count = real_len - self.orphan_lines_count + shift;
Ok(())
}

Expand Down

0 comments on commit 80fd142

Please sign in to comment.