Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cache color profile and background #212

Merged
merged 4 commits into from Aug 4, 2023
Merged

fix: cache color profile and background #212

merged 4 commits into from Aug 4, 2023

Conversation

aymanbagabas
Copy link
Member

Reintroduce caching the color profile and background

Guard accessing the underlying Termenv output behind a mutex. Multiple goroutines can set/get the dark background color causing a race condition.

Needs: muesli/termenv#146
Copy link
Member

@caarlos0 caarlos0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 questions, but looks good to me


if !r.explicitColorProfile {
r.getColorProfile.Do(func() {
r.colorProfile = r.output.EnvColorProfile()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it wlock here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we do, but I think we don't need to since the function would only run once. Maybe @muesli can weigh on this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, the sync.Once already provides its own locking mechanism, so the read-lock should be sufficient. Could maybe add a comment in that regard to prevent further confusion.


if !r.explicitBackgroundColor {
r.getBackgroundColor.Do(func() {
r.hasDarkBackground = r.output.HasDarkBackground()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it wlock here?

Base automatically changed from fix-race to master August 1, 2023 12:23
aymanbagabas added a commit to charmbracelet/log that referenced this pull request Aug 1, 2023
Add `SetColorProfile` to force change the Lip Gloss renderer color profile.

Needs: charmbracelet/lipgloss#212
Fixes: #63
aymanbagabas added a commit to charmbracelet/log that referenced this pull request Aug 1, 2023
Add `SetColorProfile` to force change the Lip Gloss renderer color profile.

Needs: charmbracelet/lipgloss#212
Fixes: #63
@aymanbagabas aymanbagabas merged commit 160ffe8 into master Aug 4, 2023
18 checks passed
@aymanbagabas aymanbagabas deleted the explicit-cp branch August 4, 2023 16:59
aymanbagabas added a commit to charmbracelet/log that referenced this pull request Aug 22, 2023
Add `SetColorProfile` to force change the Lip Gloss renderer color profile.

Needs: charmbracelet/lipgloss#212
Fixes: #63
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants