-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
`ColorProfile` reads the terminal environment every time the function is called. This is inefficient. We only need to read the `$TERM` environment variable once when we initialize the output. So instead, we cache the value we read. Rename `ColorProfile` to `termColorProfile` and rely on `EnvColorProfile` to detect the profile. Ideally, we would rely on the terminal Terminfo to detect the profile and fallback to the environment. But that's for another day :) Make output profile accessible through `ColorProfile`. Use `SetColorProfile` to change the output color profile. Use a mutex to guard output writes. Use pointer receiver since we have a lock in the struct Fixes: charmbracelet/lipgloss#210 Fixes: #145
- Loading branch information
1 parent
3466887
commit c0b676e
Showing
10 changed files
with
127 additions
and
77 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package termenv | ||
|
||
import ( | ||
"io" | ||
"testing" | ||
) | ||
|
||
func TestOutputRace(t *testing.T) { | ||
o := NewOutput(io.Discard) | ||
for i := 0; i < 100; i++ { | ||
t.Run("Test race", func(t *testing.T) { | ||
t.Parallel() | ||
o.Write([]byte("test")) | ||
o.SetColorProfile(ANSI) | ||
o.ColorProfile() | ||
o.HasDarkBackground() | ||
o.TTY() | ||
o.ForegroundColor() | ||
o.BackgroundColor() | ||
}) | ||
} | ||
} |
Oops, something went wrong.