Wilfred / difftastic

a structural diff that understands syntax 🟥🟩
https://difftastic.wilfred.me.uk/
MIT License
20.59k stars 333 forks source link

Redo of background colors to improve diff readability #690

Open egrieco opened 6 months ago

egrieco commented 6 months ago

This is a complete rewrite of #286 on top of the current version of difftastic (with the exception of the last cargo update which is causing a compilation error for me #689).

Screenshot of default background colors for difftastic.

Previous Issues

Hopefully this addresses the issues that @Wilfred mentioned in the last pull request:

Themes

This pull request lays the groundwork for theming of difftastic in the future. The missing piece here is the ability to parse theme information from a config file. Internally, the various styles are stored in a HashMap and a lookup with fallback is performed when retrieving various values.

Notes and Caveats

While this is a decent proof of concept there are probably a few issues in need of attention:

Reasoning

I'm creating this pull request now, in spite of it not being finished, since I'd like feedback on the above.

gerhardol commented 6 months ago

This looks better. Do you have a plan to create custom themes? To use git colors is one way I prefer.

egrieco commented 6 months ago

Do you have a plan to create custom themes? To use git colors is one way I prefer.

No. If you have more detail about what you'd like to see in custom theme support please share.

Right now, I have implemented this in a way that could support custom themes, specifically yansi::Styles are pulled from a lookup table implemented via a HashMap. The biggest missing pieces are

  1. A format for storing themes on disk: Do we go with TOML, YAML, JSON, etc.
  2. Parsing code to convert user specified theme info into actual yansi::Style types.
egrieco commented 6 months ago

@gerhardol Is this what you have in mind?

gerhardol commented 6 months ago

More or less those links. Git colors are defined in the doc: https://git-scm.com/docs/git-config#Documentation/git-config.txt-colordiffltslotgt But you do not get the hardcoded defaults from Git what I know. Also, getting colors dynamically will be slow (some caching will have to be used).

But using the same names for the slot (with some additions and deletions) would simplify. Maybe not this PR to define the available slots, but maybe the name of them.

Difftastic is more than Git, but as Git is dominant, at least configuration and documentation is simpler if the concepts ar the same.

In my case to use Difftastic as a difftool from within another tool, I would need some way to control tis at runtime, prefeably with environment variables. So a comma separated list with the Git names of the slots is my preference. A user may want other colors from the command line and use other theme colors when embedded in the app.

A sidetrack...

Will try to build and try this branch myself