Repository navigation
refactor: cache lipgloss styles per theme change; auto-select light theme - #856
Merged
Merged
Conversation
When no theme is configured, request the terminal background color on startup (tea.RequestBackgroundColor) and switch to github-light when the terminal reports a light background. The built-in chat.theme default changes from "tokyo-night" to "" meaning auto: the dark default is kept unless a light background is detected; an explicit config or /theme choice always wins. Refs #832
Pre-bake all theme-derived styles into a themedStyles struct built once per theme instead of constructing NewStyle() chains inside every Render* call per frame. Invalidation is a lazy theme-name check per access, so the theme-change flow and every NewProvider call site stay untouched. Rendering output is byte-identical across all four themes. Closes #832
Contributor
|
🎉 This PR is included in version 0.142.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #832.
Style cache (
internal/ui/styles/provider.go): all theme-derived styles are pre-baked into athemedStylesstruct built once per theme bybuildThemedStyles, deduped to 27 fields (methods sharing identical chains share one style).Render*methods only call.Render(); width-parameterized ones apply.Width(w)to the cached base. Invalidation is a lazy theme-name check per access — no event plumbing, so the theme-change flow and all ~15NewProvidercall sites are untouched. Theme-independent styles are package-level vars.NewStyle()now appears only in the builder and that var block (the issue's grep criterion).Background detection (
internal/app/chat.go): when no theme is configured,Initreturnstea.RequestBackgroundColorand a lighttea.BackgroundColorMsgswitches togithub-lightvia the existingupdateAllComponentsWithNewTheme()path. The built-inchat.themedefault changes from"tokyo-night"to""= auto (previously "unconfigured" was undetectable); the container already treats""as "keep the tokyo-night default", so dark terminals see zero change and an explicit config or/themechoice always wins.Verification
Render*calls across all 4 themes before/after the refactor — output was byte-identical./themeswitch to github-light flipped the frame's ANSI palette, proving the cache rebuilds without invalidation wiring.provider_test.go(cache reuse + rebuild on switch),background_theme_test.go(light/dark/configured-theme branches).task test(51 packages),task lint(0 issues),task test:e2eall pass.Note: counterfeiter fakes return
""for the theme name, which collided with using""as the "not built" sentinel — handled with an explicitbuiltflag on the provider.