From fee57d71d97591b79b461afa03941dee2b09216d Mon Sep 17 00:00:00 2001 From: sharkdp Date: Fri, 14 Dec 2018 21:23:27 +0100 Subject: [PATCH] Print ANSI-reset code before newline fixes #379 --- src/printer.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/printer.rs b/src/printer.rs index 1fc0343e68..0cf63a7c80 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -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') { @@ -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, );