Skip to content

Commit

Permalink
cli: add label for line numbers in --color-words diff
Browse files Browse the repository at this point in the history
If you want to set a background color on added/removed lines, you
currently get the same style on the line numbers. This patch lets you
specify a different style by overriding it on the line numbers.
  • Loading branch information
martinvonz committed Jun 25, 2024
1 parent 60b35f6 commit 5ba6078
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions cli/src/diff_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,21 +375,25 @@ fn show_color_words_diff_line(
diff_line: &DiffLine,
) -> io::Result<()> {
if diff_line.has_left_content {
write!(
formatter.labeled("removed"),
"{:>4}",
diff_line.left_line_number
)?;
formatter.with_label("removed", |formatter| {
write!(
formatter.labeled("line_number"),
"{:>4}",
diff_line.left_line_number
)
})?;
write!(formatter, " ")?;
} else {
write!(formatter, " ")?;
}
if diff_line.has_right_content {
write!(
formatter.labeled("added"),
"{:>4}",
diff_line.right_line_number
)?;
formatter.with_label("added", |formatter| {
write!(
formatter.labeled("line_number"),
"{:>4}",
diff_line.right_line_number
)
})?;
write!(formatter, ": ")?;
} else {
write!(formatter, " : ")?;
Expand Down

0 comments on commit 5ba6078

Please sign in to comment.