feat: allow transparent background via config or flag#392
Conversation
so terminal/IDE themes show through. Adds a `--transparent` CLI flag and a `transparent_background` config key. When set, the diff theme omits the background color and uses the terminal default. Fixes #245
Greptile SummaryThis PR adds
Confidence Score: 3/5The transparent background feature works for most surfaces, but word-diff highlights are visually broken — they render as opaque dark boxes — whenever the flag is active. The word-diff highlight path in pierre.ts silently misinterprets transparent as black, so any user who enables --transparent-background and scrolls through a diff with word-level changes will see solid dark highlight boxes instead of a see-through effect. This is the primary advertised use-case of the feature. src/ui/diff/pierre.ts — the wordDiffHighlightBg function needs a guard for transparent background values before computing color distances. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
CLI["CLI flags\n--transparent-background"] --> ParseCli["parseCli()\ncli.ts"]
Config["config.toml\ntransparent_background"] --> ReadConfig["readConfigPreferences()\nconfig.ts"]
ParseCli --> Merge["mergeOptions()\nconfig.ts"]
ReadConfig --> Merge
Merge --> Bootstrap["AppBootstrap\ninput.options.transparentBackground"]
Bootstrap --> App["App.tsx\nresolveTheme → baseTheme"]
App -->|"transparentBackground === true"| WithTransparent["withTransparentBackground(baseTheme)\nthemes.ts"]
App -->|"transparentBackground === false"| BaseTheme["baseTheme (unchanged)"]
WithTransparent --> ActiveTheme["activeTheme\nall bg fields = 'transparent'"]
BaseTheme --> ActiveTheme
ActiveTheme --> Render["UI rendering"]
ActiveTheme --> WordDiff["wordDiffHighlightBg()\npierre.ts"]
WordDiff -->|"'transparent' treated as black"| BugPath["hexColorDistance / blendHex\nfall back to #000000 ⚠️"]
BugPath --> OpaqueDark["Opaque dark word-diff\nhighlights (bug)"]
|
| const baseTheme = resolveTheme(themeId, detectedThemeMode ?? null, bootstrap.customTheme); | ||
| const activeTheme = useMemo( |
There was a problem hiding this comment.
baseTheme is recomputed on every render because resolveTheme is called without useMemo. For built-in themes resolveTheme returns a stable reference from the THEMES array, so the current activeTheme memo happens to be stable in the common case — but for users with a custom theme buildCustomTheme constructs a fresh object every render, defeating the memo and invoking withTransparentBackground unnecessarily on every render cycle.
| const baseTheme = resolveTheme(themeId, detectedThemeMode ?? null, bootstrap.customTheme); | |
| const activeTheme = useMemo( | |
| const baseTheme = useMemo( | |
| () => resolveTheme(themeId, detectedThemeMode ?? null, bootstrap.customTheme), | |
| [themeId, detectedThemeMode, bootstrap.customTheme], | |
| ); | |
| const activeTheme = useMemo( |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/ui/App.tsx
Line: 141-142
Comment:
`baseTheme` is recomputed on every render because `resolveTheme` is called without `useMemo`. For built-in themes `resolveTheme` returns a stable reference from the `THEMES` array, so the current `activeTheme` memo happens to be stable in the common case — but for users with a custom theme `buildCustomTheme` constructs a fresh object every render, defeating the memo and invoking `withTransparentBackground` unnecessarily on every render cycle.
```suggestion
const baseTheme = useMemo(
() => resolveTheme(themeId, detectedThemeMode ?? null, bootstrap.customTheme),
[themeId, detectedThemeMode, bootstrap.customTheme],
);
const activeTheme = useMemo(
```
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Applied the suggested memoization so custom themes are not rebuilt on every render before transparent-background wrapping.
This comment was generated by Pi using GPT-5.1 Codex
|
Addressed the Greptile findings in 23b2582:
Validated with This comment was generated by Pi using GPT-5.1 Codex |
Summary
--transparent-background/--no-transparent-backgroundCLI flags.transparent_background/transparentBackgroundconfig support.Rebased version of #322 with conflicts resolved against current
main.Tests
bun run typecheckbun testThis PR description was generated by Pi using GPT-5.1 Codex