Skip to content

Commit 5db7ee8

Browse files
committed
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.
1 parent 08781c3 commit 5db7ee8

File tree

1 file changed

+35
-24
lines changed

1 file changed

+35
-24
lines changed

src/gh_range_diff.rs

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -242,18 +242,24 @@ fn process_old_new(
242242
overflow-x: auto;
243243
}}
244244
.removed-block {{
245-
background-color: rgb(255, 206, 203);
245+
background-color: rgba(255, 150, 150, 1);
246246
white-space: pre;
247247
}}
248248
.added-block {{
249-
background-color: rgb(172, 238, 187);
249+
background-color: rgba(150, 255, 150, 1);
250250
white-space: pre;
251251
}}
252-
.removed-line {{
253-
color: #DE0000;
252+
.removed-line-after {{
253+
color: rgb(220, 0, 0)
254254
}}
255-
.added-line {{
256-
color: #2F6500;
255+
.added-line-after {{
256+
color: rgb(0, 73, 0)
257+
}}
258+
.removed-line-before {{
259+
color: rgb(192, 78, 76)
260+
}}
261+
.added-line-before {{
262+
color: rgb(63, 128, 94)
257263
}}
258264
@media (prefers-color-scheme: dark) {{
259265
body {{
@@ -264,23 +270,31 @@ fn process_old_new(
264270
color: #41a6ff;
265271
}}
266272
.removed-block {{
267-
background-color: rgba(248, 81, 73, 0.1);
273+
background-color: rgba(80, 45, 45, 1);
274+
white-space: pre;
268275
}}
269276
.added-block {{
270-
background-color: rgba(46, 160, 67, 0.15);
277+
background-color: rgba(70, 120, 70, 1);
278+
white-space: pre;
279+
}}
280+
.removed-line-after {{
281+
color: rgba(255, 0, 0, 1);
282+
}}
283+
.added-line-after {{
284+
color: rgba(0, 255, 0, 1);
271285
}}
272-
.removed-line {{
273-
color: #F34848;
286+
.removed-line-before {{
287+
color: rgba(100, 0, 0, 1);
274288
}}
275-
.added-line {{
276-
color: #86D03C;
289+
.added-line-before {{
290+
color: rgba(0, 100, 0, 1);
277291
}}
278292
}}
279293
</style>
280294
</head>
281295
<body>
282296
<h3>range-diff of {oldbase}<wbr>...{oldhead} {newbase}<wbr>...{newhead}</h3>
283-
<p>Bookmarklet: <a href="{bookmarklet}" title="Drag-and-drop me on the bookmarks bar, and use me on GitHub compare page.">range-diff</a> <span title="This javascript bookmark can be used to access this page with the right URL. To use it drag-on-drop the range-diff link to your bookmarks bar and click on it when you are on GitHub's compare page to use range-diff compare.">&#128712;</span> | {ADDED_BLOCK_SIGN}&nbsp;<span class="added-line">+</span> adds a line | {ADDED_BLOCK_SIGN}&nbsp;<span class="removed-line">-</span> removes a line | {REMOVED_BLOCK_SIGN}&nbsp;<span class="removed-line">+</span> removes the added line | {REMOVED_BLOCK_SIGN}&nbsp;- cancel the removal</p>
297+
<p>Bookmarklet: <a href="{bookmarklet}" title="Drag-and-drop me on the bookmarks bar, and use me on GitHub compare page.">range-diff</a> <span title="This javascript bookmark can be used to access this page with the right URL. To use it drag-on-drop the range-diff link to your bookmarks bar and click on it when you are on GitHub's compare page to use range-diff compare.">&#128712;</span> | {REMOVED_BLOCK_SIGN}&nbsp;before | {ADDED_BLOCK_SIGN}&nbsp;after</p>
284298
"#
285299
)?;
286300

@@ -409,19 +423,16 @@ impl HtmlDiffPrinter<'_> {
409423
let is_add = token.starts_with('+');
410424
let is_remove = token.starts_with('-');
411425

412-
// Highlight the whole the line only if it has changes it-self, otherwise
413-
// only highlight the `+`, `-` to avoid distracting users with context
414-
// changes.
426+
// Highlight in the same was as `git range-diff` does for diff-lines
427+
// that changed. (Contrary to `git range-diff` we don't color unchanged
428+
// diff lines though, since then the coloring distracts from what is
429+
// relevant.)
415430
if is_add || is_remove {
416431
let class = match (hunk_token_status, is_add) {
417-
// adds a line
418-
(HunkTokenStatus::Added, true) => "added-line",
419-
// removes a line
420-
(HunkTokenStatus::Added, false) => "removed-line",
421-
// removes the added line
422-
(HunkTokenStatus::Removed, true) => "removed-line",
423-
// removes the removed line, so nothing changed
424-
(HunkTokenStatus::Removed, false) => "",
432+
(HunkTokenStatus::Removed, true) => "added-line-before",
433+
(HunkTokenStatus::Removed, false) => "removed-line-before",
434+
(HunkTokenStatus::Added, true) => "added-line-after",
435+
(HunkTokenStatus::Added, false) => "removed-line-after",
425436
};
426437

427438
write!(f, r#"<span class="{class}">"#)?;

0 commit comments

Comments
 (0)