Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions src/paint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,9 @@ impl<'a> Painter<'a> {
painted_prefix: Option<ansi_term::ANSIString>,
config: &config::Config,
) -> (String, bool) {
let output_line_numbers = config.line_numbers && line_numbers_data.is_some();
let mut handled_prefix = false;
let mut ansi_strings = Vec::new();

let output_line_numbers = config.line_numbers && line_numbers_data.is_some();
if output_line_numbers {
ansi_strings.extend(line_numbers::format_and_paint_line_numbers(
line_numbers_data.as_mut().unwrap(),
Expand All @@ -407,27 +407,40 @@ impl<'a> Painter<'a> {
}
_ => {}
}
let mut is_empty = true;
for (section_style, mut text) in superimpose_style_sections(

let superimposed = superimpose_style_sections(
syntax_sections,
diff_sections,
config.true_color,
config.null_syntect_style,
) {
if !handled_prefix {
if let Some(painted_prefix) = painted_prefix.clone() {
ansi_strings.push(painted_prefix);
);

let mut handled_prefix = false;
for (section_style, text) in &superimposed {
let text = if handled_prefix {
&text
} else {
// Remove what was originally the +/- prefix, see `prepare()`, after
// (if requested) re-inserting it with proper styling.
if let Some(ref painted_prefix) = painted_prefix {
ansi_strings.push(painted_prefix.clone());
}

if !text.is_empty() {
text.remove(0);
&text[1..]
} else {
&text
}
handled_prefix = true;
}
};

if !text.is_empty() {
ansi_strings.push(section_style.paint(text));
is_empty = false;
}
handled_prefix = true;
}

// Only if syntax is empty (implies diff empty) can a line actually be empty.
let is_empty = syntax_sections.is_empty();
(ansi_term::ANSIStrings(&ansi_strings).to_string(), is_empty)
}

Expand Down
9 changes: 1 addition & 8 deletions src/tests/test_example_diffs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1472,14 +1472,7 @@ src/align.rs:71: impl<'a> Alignment<'a> { │
.to_string()
);
} else {
let style = style::Style::from_str(empty_line_marker_style, None, None, true, false);
assert_eq!(
line,
&style
.ansi_term_style
.paint(ansi::ANSI_CSI_CLEAR_TO_BOL)
.to_string()
);
assert_eq!(line, "");
}
}

Expand Down