Skip to content

Commit

Permalink
wrap content in terminal instead of truncating
Browse files Browse the repository at this point in the history
  • Loading branch information
sumit2bk committed Aug 25, 2022
1 parent 2f5b5bf commit 404b83b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/sinks/terminal/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,18 @@ impl Display for LogLine {

match self.content.len() {
x if x > max_width => {
let partial: String = self.content.chars().take(max_width - 3).collect();
partial.with(Color::Grey).fmt(f)?;
f.write_str("...")?;
let chunks = (x as f32 / max_width as f32).ceil() as usize;
let wrapped: String = self.content
.chars()
.enumerate()
.fold(String::new(), |acc, (i, c)| {
if i != 0 && i == chunks {
format!("{}\n{}", acc, c)
} else {
format!("{}{}", acc, c)
}
});
wrapped.with(Color::Grey).fmt(f)?;
}
_ => {
let full = &self.content[..];
Expand Down

0 comments on commit 404b83b

Please sign in to comment.