From fdac82abf01e8a6153a207237ddec259c2cda4a8 Mon Sep 17 00:00:00 2001 From: Urgau Date: Sat, 9 May 2026 14:45:13 +0200 Subject: [PATCH] Improve our range-diff header with colors and better description --- src/gh_range_diff.rs | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/gh_range_diff.rs b/src/gh_range_diff.rs index 7e55d6dc..1d7713fc 100644 --- a/src/gh_range_diff.rs +++ b/src/gh_range_diff.rs @@ -209,10 +209,8 @@ fn process_old_new( // Create the HTML buffer with a very rough approximation for the capacity let mut html: String = String::with_capacity(800 + old.files.len() * 100); - let a_oldbase = a_github_commit(owner, repo, oldbase); - let a_oldhead = a_github_commit(owner, repo, oldhead); - let a_newbase = a_github_commit(owner, repo, newbase); - let a_newhead = a_github_commit(owner, repo, newhead); + let a_compare_before = a_github_compare("compare-before", owner, repo, oldbase, oldhead); + let a_compare_after = a_github_compare("compare-after", owner, repo, newbase, newhead); // Write HTML header, style, ... writeln!( @@ -236,10 +234,16 @@ fn process_old_new( overflow-wrap: break-word; white-space: normal; }} - .commit {{ + .compare {{ text-decoration: none; color: unset; }} + .compare-before {{ + color: rgb(255, 93, 93); + }} + .compare-after {{ + color: rgb(55, 227, 55); + }} .diff-content {{ overflow-x: auto; }} @@ -297,6 +301,12 @@ fn process_old_new( a {{ color: #41a6ff; }} + .compare-before {{ + color: rgb(255, 93, 93); + }} + .compare-after {{ + color: rgb(88, 177, 88); + }} .filename-block {{ background-color: #5f8fe5; }} @@ -340,8 +350,8 @@ fn process_old_new( -

range-diff of {a_oldbase}..{a_oldhead} {a_newbase}..{a_newhead} in {owner}/{repo}

-Legend: {REMOVED_BLOCK_SIGN} before | {ADDED_BLOCK_SIGN} after +

range-diff of {a_compare_before} {a_compare_after} in {owner}/{repo}

+Legend: {REMOVED_BLOCK_SIGN} Removed from previous diff | {ADDED_BLOCK_SIGN} Added in new diff
"# )?; @@ -766,10 +776,11 @@ fn contains_diff_marker(input: &InternedInput<&str>, mut hunk: Hunk) -> bool { || hunk.after.any(|i| contains_diff_marker(i, &input.after)) } -// function to create a to a GitHub commit -fn a_github_commit(owner: &str, repo: &str, ref_: &str) -> String { +// Function to create an link to a GitHub compare +fn a_github_compare(class: &str, owner: &str, repo: &str, base: &str, head: &str) -> String { format!( - r#"{}"#, - &ref_[..=6] + r#"{base_6}..{head_6}"#, + base_6 = &base[..base.len().min(7)], + head_6 = &head[..head.len().min(7)] ) }