Skip to content

Allow telling diff renderers whether the terminal is dark or light - #6063

Merged
stefanhaller merged 4 commits into
masterfrom
diff-renderer-color-scheme
Sep 27, 2026
Merged

stefanhaller merged 4 commits into
masterfrom
diff-renderer-color-scheme

Conversation

@stefanhaller

Copy link
Copy Markdown
Collaborator

Renderers like delta and difftastic pick their colors for either a dark or a light background, and they can't find out which one the terminal has, because lazygit runs them with TERM=dumb, and in a pty that doesn't answer their queries.

Add {{colorScheme}} to the commands of diff renderers. It is 'dark' or 'light', based on what the terminal reports (which can be overridden by gui.colorScheme if the terminal doesn't support the query). It can be passed to delta as --{{colorScheme}} and to difftastic as --background={{colorScheme}}; other renderers can choose between options with a template expression.

@stefanhaller
stefanhaller added this pull request to stack #6064 September 26, 2026 17:20
@stefanhaller stefanhaller added the enhancement New feature or request label Sep 26, 2026
@stefanhaller
stefanhaller force-pushed the diff-renderer-color-scheme branch from dafcc12 to 1f62f98 Compare September 27, 2026 06:09
Base automatically changed from better-author-colors to master September 27, 2026 06:09
stefanhaller and others added 4 commits September 27, 2026 08:09
The getters for the stdin filter and the external diff command each
take the values they fill in as parameters of their own, and each
builds the placeholders for them. The next commit checks the commands
when the config is loaded, and for that it needs to resolve a command
whatever its kind. A value that both kinds can use comes after that.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The command of a diff renderer can refer to values like the width it
renders at, as {{width}}. They are filled in by plain replacement, so a
command can't choose between options depending on them. The next commit
adds a value that needs this: whether the terminal is dark or light.
delta takes --dark or --light, but for other renderers the choice has to
be spelled out differently, for example as the name of a syntax theme.

Resolve the command as a Go template instead. The values become its
variables, so that {{if gt .width 160}} --side-by-side{{end}} works too.
To keep the existing commands working, a variable can still be written
without the leading dot.

A mistake in a template, such as a misspelled variable, now makes
resolving the command fail, instead of leaving the placeholder in it.
Check the commands when the config is loaded, by resolving each of them
with made-up values, so that the mistake shows up as an invalid config.
This also rejects a variable that the kind of renderer doesn't have,
such as {{columnWidth}} in the command of an external diff; until now,
it reached the renderer as it was.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The next commit needs to render the diff again when the terminal
switches between dark and light, with the same care not to replace
whatever else the main view might show.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Renderers like delta and difftastic pick their colors for either a dark
or a light background, and they can't find out which one the terminal
has. Lazygit runs them with TERM=dumb, in a pty that doesn't answer
their queries. So the colors come from the config, and when the
terminal switches between dark and light, the diff keeps the ones it
has.

Add {{colorScheme}} to the commands of diff renderers. It is 'dark' or
'light', going by gui.colorScheme, or by the terminal if that is
'auto'. It can be passed to delta as --{{colorScheme}} and to
difftastic as --background={{colorScheme}}; other renderers can choose
between options with a template expression. When the terminal switches
between dark and light, render the diff again.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@stefanhaller
stefanhaller force-pushed the diff-renderer-color-scheme branch from 1f62f98 to d38248d Compare September 27, 2026 06:09
@stefanhaller
stefanhaller merged commit 5ed0345 into master Sep 27, 2026
12 checks passed
@stefanhaller
stefanhaller deleted the diff-renderer-color-scheme branch September 27, 2026 06:16
@Makihataima-Ken Makihataima-Ken mentioned this pull request Sep 30, 2026
7 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant