diff options
author | Dan Davison <dandavison7@gmail.com> | 2019-09-03 14:04:14 +0100 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2019-09-03 14:10:13 +0100 |
commit | c2a3e921bdf7cdd8389849fa863c4adbb7147f63 (patch) | |
tree | 9de6525c7248cb95f04711be9208215e2771edbc /src/paint.rs | |
parent | da75f535aae3add7e2f8deb2a8f44762ba3dd094 (diff) |
Only trim terminating newline when it was added articificially
Diffstat (limited to 'src/paint.rs')
-rw-r--r-- | src/paint.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/paint.rs b/src/paint.rs index 6a88e9c1..e081c7d6 100644 --- a/src/paint.rs +++ b/src/paint.rs @@ -63,6 +63,7 @@ impl<'a> Painter<'a> { minus_line_diff_style_sections, self.config, self.config.minus_style_modifier, + true, ); } if !self.plus_lines.is_empty() { @@ -72,6 +73,7 @@ impl<'a> Painter<'a> { plus_line_diff_style_sections, self.config, self.config.plus_style_modifier, + true, ); } self.minus_lines.clear(); @@ -86,6 +88,7 @@ impl<'a> Painter<'a> { diff_style_sections: Vec<Vec<(StyleModifier, &str)>>, config: &config::Config, background_style_modifier: StyleModifier, + lines_have_terminating_newline_character: bool, ) { use std::fmt::Write; for (syntax_sections, diff_sections) in @@ -98,9 +101,11 @@ impl<'a> Painter<'a> { text_width += text.graphemes(true).count(); } } - // Remove the terminating newline whose presence was necessary for the syntax - // highlighter to work correctly. - output_buffer.truncate(output_buffer.len() - 1); + if lines_have_terminating_newline_character { + // Remove the terminating newline whose presence was necessary for the syntax + // highlighter to work correctly. + output_buffer.truncate(output_buffer.len() - 1); + } match config.width { Some(width) if width > text_width => { // Right pad to requested width with spaces. |