Skip to content

Commit

Permalink
Print ANSI-reset code before newline
Browse files Browse the repository at this point in the history
fixes #379
  • Loading branch information
sharkdp committed Dec 14, 2018
1 parent 5d3205a commit fee57d7
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,13 @@ impl<'a> Printer for InteractivePrinter<'a> {

for &(style, region) in regions.iter() {
let text = &*self.preprocess(region, &mut cursor_total);
let text_trimmed = text.trim_end_matches(|c| c == '\r' || c == '\n');
write!(
handle,
"{}",
as_terminal_escaped(style, &*text, true_color, colored_output, italics,)
as_terminal_escaped(style, text_trimmed, true_color, colored_output, italics,)
)?;
write!(handle, "{}", &text[text_trimmed.len()..])?;
}

if line.bytes().next_back() != Some(b'\n') {
Expand Down Expand Up @@ -342,7 +344,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
// Regular text.
(text, false) => {
let text = self.preprocess(
text.trim_right_matches(|c| c == '\r' || c == '\n'),
text.trim_end_matches(|c| c == '\r' || c == '\n'),
&mut cursor_total,
);

Expand Down

0 comments on commit fee57d7

Please sign in to comment.