Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customizable diff colors #1006

Closed
p5nbTgip0r opened this issue Sep 27, 2019 · 4 comments
Closed

Customizable diff colors #1006

p5nbTgip0r opened this issue Sep 27, 2019 · 4 comments

Comments

@p5nbTgip0r
Copy link

Describe the change you'd like
The green and red colors when viewing commit diffs should have a customization option to choose different colors in place of the default green and red.
image

Additional context
People who suffer from color blindness may find it difficult or impossible to distinguish green and red from each other. This becomes an issue when looking at commit diffs since it relies mostly on color to show changes, with a + or - at the start of the line to indicate additions and deletions as the only non-color reliant way of indicating changes.

There is a userstyle that aims to help fix this issue for the default light GitHub, but it is incompatible with this theme. To solve this I'm requesting a customization option to change the colors used in diff views be added so users who have any form of color blindness/deficiency can adjust these defaults and allow easier readability of code changes for them.

@Mottie
Copy link
Member

Mottie commented Sep 27, 2019

Hi @p5nbTgip0r!

Try adding this usercss. I used selectors that will override GitHub-Dark's diff colors (including hover highlighting):

/* ==UserStyle==
@name        GitHub Diff Color Customizer
@namespace   StylishThemes
@version     1.0.0
@description Add diff color customization
@license     CC-BY-SA-4.0
@author      StylishThemes
@advanced color deleted-line "Deleted Line Bkgd" #ffcc33
@advanced color deleted-text "Deleted Line Text" #979797
@advanced color deleted-code "Deleted Code Bkgd" #ffd96359
@advanced color deleted-hover "Deleted Hover Bkgd" #805f0059
@advanced color added-line "Added Line Bkgd" #3986ff
@advanced color added-text "Added Line Text" #fff
@advanced color added-code "Added Code Bkgd" #3986ff59
@advanced color added-hover "Added Hover Bkgd" #004cc159
@preprocessor default
==/UserStyle== */
@-moz-document regexp("^https?://((gist|guides|help|lab|launch-editor|raw|resources|status|developer)\\.)?github\\.com/((?!generated_pages/preview).)*$") {

  /*** Based on https://userstyles.org/styles/149864/github-diff-colorblind-friendly ***
  .blob-num sets the colors in the number columns on the left 
  .blob-code sets the color of the rest of the line
  .blob-code .x sets the word-diff highlight color
  ***/
  .highlight .blob-num-deletion,
  .highlight .blob-code-deletion .x {
    background-color: var(--deleted-line) !important;
    color: var(--deleted-text) !important;
  }

  .highlight .blob-code-deletion {
    background-color: var(--deleted-code) !important;
    color: var(--deleted-text) !important;
  }

  body .highlight:not(.lines) tr:not(.inline-comments):hover td.blob-num-deletion:not(.line-age),
  body .highlight:not(.lines) tr:not(.inline-comments):hover td.blob-code-deletion:not(.line-age) {
    background: var(--deleted-hover) !important;
  }

  body .highlight:not(.lines) tr:not(.inline-comments):hover td.blob-num-deletion:not(.line-age):before {
    color: var(--deleted-text) !important;
  }

  .highlight .blob-num-addition,
  .highlight .blob-code-addition .x {
    background-color: var(--added-line) !important;
    color: var(--added-text) !important;
  }

  .highlight .blob-code-addition {
    background-color: var(--added-code) !important;
    color: var(--added-text) !important;
  }

  body .highlight:not(.lines) tr:not(.inline-comments):hover td.blob-num-addition:not(.line-age),
  body .highlight:not(.lines) tr:not(.inline-comments):hover td.blob-code-addition:not(.line-age) {
    background: var(--added-hover) !important;
  }

  body .highlight:not(.lines) tr:not(.inline-comments):hover td.blob-num-addition:not(.line-age):before {
    color: var(--added-text) !important;
  }
}

Let me know if there is anything that needs to be changed. We can create a new repository with this style if you find it useful.

@p5nbTgip0r
Copy link
Author

@Mottie While I'm not colorblind myself, I know a few people who are and would likely appreciate a repository to allow for this sort of customization.

I'd probably suggest a change of the default colors with the style, the current colors don't seem to work well with the dark theme and cause lots of near-unreadable text. Playing around with the colors, I found the following values to work well with the dark theme as well as the default GitHub light theme while still accommodating for red-green color blindness through a colorblind simulator. Obviously I can't speak for whether these would fully work for people who do have color blindness, but I think they're a step in the right direction:

@advanced color deleted-line "Deleted Line Bkgd" #ffcc33
@advanced color deleted-text "Deleted Line Text" #979797
@advanced color deleted-code "Deleted Code Bkgd" #ffd96359
@advanced color deleted-hover "Deleted Hover Bkgd" #805f0059
@advanced color added-line "Added Line Bkgd" #3986ff
@advanced color added-text "Added Line Text" #fff
@advanced color added-code "Added Code Bkgd" #3986ff59
@advanced color added-hover "Added Hover Bkgd" #004cc159

Lastly, thank you so much for making this! I'm sure many people will find this useful and I'll definitely use it myself.

@Mottie
Copy link
Member

Mottie commented Sep 27, 2019

Looks good! I've updated the snippet.

We're talking about making a repo that will contain a bunch of customization usercss. We'll let you know when it's available.

@the-j0k3r
Copy link
Member

the-j0k3r commented Nov 11, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants