From 5db7ee8c18dc13f52e277dd6242c8bd555a68ee1 Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Fri, 22 Aug 2025 22:11:54 +0200 Subject: [PATCH] Make `/gh-range-diff/...` coloring more similar to `git range-diff` coloring Start using the same coloring strategy as `git range-diff`, except we don't color unchanged diff lines. See corresponding PR discussion for the details. --- src/gh_range_diff.rs | 59 ++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/src/gh_range_diff.rs b/src/gh_range_diff.rs index 5e4fb252..9833daab 100644 --- a/src/gh_range_diff.rs +++ b/src/gh_range_diff.rs @@ -242,18 +242,24 @@ fn process_old_new( overflow-x: auto; }} .removed-block {{ - background-color: rgb(255, 206, 203); + background-color: rgba(255, 150, 150, 1); white-space: pre; }} .added-block {{ - background-color: rgb(172, 238, 187); + background-color: rgba(150, 255, 150, 1); white-space: pre; }} - .removed-line {{ - color: #DE0000; + .removed-line-after {{ + color: rgb(220, 0, 0) }} - .added-line {{ - color: #2F6500; + .added-line-after {{ + color: rgb(0, 73, 0) + }} + .removed-line-before {{ + color: rgb(192, 78, 76) + }} + .added-line-before {{ + color: rgb(63, 128, 94) }} @media (prefers-color-scheme: dark) {{ body {{ @@ -264,23 +270,31 @@ fn process_old_new( color: #41a6ff; }} .removed-block {{ - background-color: rgba(248, 81, 73, 0.1); + background-color: rgba(80, 45, 45, 1); + white-space: pre; }} .added-block {{ - background-color: rgba(46, 160, 67, 0.15); + background-color: rgba(70, 120, 70, 1); + white-space: pre; + }} + .removed-line-after {{ + color: rgba(255, 0, 0, 1); + }} + .added-line-after {{ + color: rgba(0, 255, 0, 1); }} - .removed-line {{ - color: #F34848; + .removed-line-before {{ + color: rgba(100, 0, 0, 1); }} - .added-line {{ - color: #86D03C; + .added-line-before {{ + color: rgba(0, 100, 0, 1); }} }}

range-diff of {oldbase}...{oldhead} {newbase}...{newhead}

-

Bookmarklet: range-diff 🛈 | {ADDED_BLOCK_SIGN} + adds a line | {ADDED_BLOCK_SIGN} - removes a line | {REMOVED_BLOCK_SIGN} + removes the added line | {REMOVED_BLOCK_SIGN} - cancel the removal

+

Bookmarklet: range-diff 🛈 | {REMOVED_BLOCK_SIGN} before | {ADDED_BLOCK_SIGN} after

"# )?; @@ -409,19 +423,16 @@ impl HtmlDiffPrinter<'_> { let is_add = token.starts_with('+'); let is_remove = token.starts_with('-'); - // Highlight the whole the line only if it has changes it-self, otherwise - // only highlight the `+`, `-` to avoid distracting users with context - // changes. + // Highlight in the same was as `git range-diff` does for diff-lines + // that changed. (Contrary to `git range-diff` we don't color unchanged + // diff lines though, since then the coloring distracts from what is + // relevant.) if is_add || is_remove { let class = match (hunk_token_status, is_add) { - // adds a line - (HunkTokenStatus::Added, true) => "added-line", - // removes a line - (HunkTokenStatus::Added, false) => "removed-line", - // removes the added line - (HunkTokenStatus::Removed, true) => "removed-line", - // removes the removed line, so nothing changed - (HunkTokenStatus::Removed, false) => "", + (HunkTokenStatus::Removed, true) => "added-line-before", + (HunkTokenStatus::Removed, false) => "removed-line-before", + (HunkTokenStatus::Added, true) => "added-line-after", + (HunkTokenStatus::Added, false) => "removed-line-after", }; write!(f, r#""#)?;