Repository navigation
Conversation
With theme none, side-by-side was enabled with delta's --side-by-side flag. Delta gathers features from command-line flags before the [delta] features list and gives earlier ones higher priority, so the builtin side-by-side feature (and the line-numbers feature it pulls in) overrode the line-number formats and styles from the user's own features. The flag also could not turn side-by-side off when the user's config enables it. Set delta.side-by-side through GIT_CONFIG_PARAMETERS instead, as `git -c delta.side-by-side=...` does. Delta reads it as a main [delta] section value, so the builtin feature ranks below the user's features, and false turns side-by-side off. Existing GIT_CONFIG_PARAMETERS entries are kept. Also drop --max-line-length=0 and --wrap-max-lines=unlimited on this path so the user's own truncation and wrapping settings apply. Themed rendering is unchanged.
|
Hmm, how about we only disable delta theming but keep the rest of the ui themed? |
|
Yes, that's actually what I'm after: I have my delta config heavily tuned (syntax theme, line-number formats, plus/minus colors), and the theme flags override all of it. I'll rework this into a separate opt-in option, One thing that applies to everyone: a small fix so that late delta results for a file you've already moved away from (or from a cancelled theme preview) don't overwrite the current view. |
|
@dlvhdr updated as suggested: In the "after" GIF, the diff uses my delta config: line numbers like |
|
@pablospe I think |
| node, ok := m.cache[msg.cacheKey] | ||
| if !ok || node != msg.node { | ||
| // Stale result: a theme change, resize or reload has replaced this node since. | ||
| break | ||
| } | ||
| node.diff = msg.lines | ||
| if node == m.file || node == m.dir { | ||
| m.fvp.SetObjects(msg.lines) |
There was a problem hiding this comment.
Not strictly. It fixes a race that exists on main: delta runs async, so a slow result (e.g. after a resize, a theme preview, or switching files quickly) can overwrite the current view. I hit it while testing this PR. I'll move it to a separate PR, if you prefer. Let me know.
| return env | ||
| } | ||
| param := fmt.Sprintf("'delta.side-by-side'='%t'", sideBySide) | ||
| if prev := os.Getenv("GIT_CONFIG_PARAMETERS"); prev != "" { |
There was a problem hiding this comment.
What is GIT_CONFIG_PARAMETERS, I couldn't find info about it
There was a problem hiding this comment.
It's how git passes git -c key=value to the pager. It isn't really documented, but delta reads it (src/env.rs) and treats it as if it were in the gitconfig. So setting GIT_CONFIG_PARAMETERS="'delta.side-by-side'='true'" is the same as having side-by-side = true in your [delta] config.
Why not just --side-by-side? Two problems with the flag:
- it also turns on delta's built-in side-by-side feature, which replaces the user's line-number format with delta's default
- there's no flag to turn side-by-side off, so if your config has it on,
scan't switch back to unified
With the env var, s works both ways and the user's styling stays as it is. It's only used with ui.useUserDeltaTheme; the themed path still uses --side-by-side. I'll shorten the code comment too.
|
Also, the PR has many tests, are they all necessary or we're just being verbose here? |
Agreed, |
|
ok, I'll trim the tests to the ones that guard real behavior: the delta args in each mode, the side-by-side env override, and one config/env test, and drop the rest (also shorten the comments). |
Summary
Since the theme picker (#152), diffnav passes delta a full set of style flags derived from the active theme (
--syntax-theme,--plus-style,--minus-style, line-number and hunk-header styles, etc.). Command-line flags take precedence over[delta]in gitconfig, so users who had delta configured to their liking lost that styling, and there is no way to opt out. Fixes #158.This adds an opt-in option,
ui.useUserDeltaTheme: true(orDIFFNAV_USE_USER_DELTA_THEME=1, which overrides the config). With it, the diff is rendered with the user's own delta config, and the rest of the UI keepsui.theme. diffnav then only passes delta--paging=never,-w=Nand--wrap-max-lines=unlimited. Unlimited wrapping is kept because the diff pane is narrower than the terminal and can't scroll sideways, so delta's default (wrap twice, then cut) would lose text on long side-by-side lines. Without the option, delta gets exactly the same args and env as today.Side-by-side needs special handling in this mode. The
--side-by-sideCLI flag enables delta's built-inside-by-sidefeature, which takes precedence over the user's ownfeaturesand replaces their line-number formats and styles with delta's defaults. It also can't turn side-by-side off when the user's config enables it. So with the option on, diffnav setsdelta.side-by-side=true/falsethroughGIT_CONFIG_PARAMETERS(appending to any existing value) instead. Delta treats it like gitconfig, so the user's styling is kept andstoggles both ways.One change applies to everyone: delta runs asynchronously, and a slow result could overwrite the current view. Examples: a file you already moved away from, a cancelled theme preview, or an older run of the same file after a resize or watch reload. Each result now carries the cache node it was started for and is dropped unless that node is still current. Delta args/env are also built before the command runs, not inside it.
How Did You Test this Change?
go test -race ./...and golangci-lint pass.ui.theme: catppuccin_frappe+ui.useUserDeltaTheme: trueagainst my own delta config: the diff uses my line-number format, colors and hunk headers in both unified and side-by-side,stoggles between them, and the tree/borders keep the Catppuccin theme. With the option off, rendering is unchanged.Images/Videos
Before:

After:

AI disclosure
Claude Code was used to write the code and tests. I reviewed the changes and tested them manually.