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(output): cache lipgloss renderers #52

Merged
merged 2 commits into from
Mar 22, 2023
Merged

fix(output): cache lipgloss renderers #52

merged 2 commits into from
Mar 22, 2023

Conversation

aymanbagabas
Copy link
Member

Cache and reuse lipgloss renderers to avoid concurrently querying the terminal for background colors. Lipgloss HasDarkBackground function queries the terminal for the background color. Creating multiple logger instances with the same output will query the output multiple times causing Log to hange and/or freeze.

To solve this, we store and retrieve the Lipgloss renderer in a global sync.Map for each output along with caching the background/foreground colors of the underlying Termenv Output.

Fixes: #50

@aymanbagabas aymanbagabas requested review from muesli and caarlos0 March 21, 2023 18:50
@codecov
Copy link

codecov bot commented Mar 21, 2023

Codecov Report

Merging #52 (023bb73) into main (89a61d4) will increase coverage by 0.22%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main      #52      +/-   ##
==========================================
+ Coverage   76.03%   76.25%   +0.22%     
==========================================
  Files          11       11              
  Lines         630      636       +6     
==========================================
+ Hits          479      485       +6     
  Misses        136      136              
  Partials       15       15              
Impacted Files Coverage Δ
pkg.go 88.04% <ø> (ø)
logger.go 84.26% <100.00%> (+0.49%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

logger.go Outdated Show resolved Hide resolved
logger.go Outdated Show resolved Hide resolved
aymanbagabas and others added 2 commits March 22, 2023 14:00
Cache and reuse lipgloss renderers to avoid concurrently querying the
terminal for background colors. Lipgloss HasDarkBackground function
queries the terminal for the background color. Creating multiple logger
instances with the same output will query the output multiple times
causing Log to hange and/or freeze.

To solve this, we store and retrieve the Lipgloss renderer in a global
sync.Map for each output along with caching the background/foreground
colors of the underlying Termenv Output.

Fixes: #50
Co-authored-by: Carlos Alexandro Becker <[email protected]>
@aymanbagabas aymanbagabas merged commit 6e534d0 into main Mar 22, 2023
@aymanbagabas aymanbagabas deleted the terminal-conc branch March 22, 2023 18:03
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.

The log output is incorrect.
2 participants