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: don't concurrently change output profiles #172

Merged
merged 1 commit into from Feb 22, 2023
Merged

Conversation

muesli
Copy link
Member

@muesli muesli commented Feb 22, 2023

Multiple lipgloss renderer instances can end up using the same default termenv.Output. This leads to a race condition when manipulating the ColorProfile concurrently.

We could mutex protect the standard output in termenv, but it feels like a weak promise, as the rest of the Output wouldn't (and probably shouldn't) get protected. Protecting it in lipgloss itself would require a global lock however.

I can't come up with a proper use-case for this scenario, and therefore we shift this responsibility to the user.

Multiple lipgloss renderer instances can end up using the same default
termenv.Output. This leads to a race condition when manipulating the
ColorProfile concurrently.

We could mutex protect the standard output in termenv, but it feels like
a weak promise, as the rest of the Output wouldn't (and probably
shouldn't) get protected. Protecting it in lipgloss itself would require
a global lock however.

I can't come up with a proper use-case for this scenario, and therefore
we shift this responsibility to the user.
@muesli muesli added the bug Something isn't working label Feb 22, 2023
@muesli muesli merged commit a74950e into master Feb 22, 2023
@muesli muesli deleted the concurrency-test branch February 22, 2023 16:28
renovate bot added a commit to sheldonhull/az-pr that referenced this pull request Apr 3, 2023
…s to v0.7.1 (#7)

[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
|
[github.com/charmbracelet/lipgloss](https://togithub.com/charmbracelet/lipgloss)
| require | minor | `v0.6.0` -> `v0.7.1` |

---

### Release Notes

<details>
<summary>charmbracelet/lipgloss</summary>

###
[`v0.7.1`](https://togithub.com/charmbracelet/lipgloss/releases/tag/v0.7.1)

[Compare
Source](https://togithub.com/charmbracelet/lipgloss/compare/v0.7.0...v0.7.1)

This bugfix release fixes a problem introduced in v0.7.0 where
applications could freeze or hang on start-up.

#### What's Changed

- fix(renderer): use termenv default renderer by
[@&#8203;aymanbagabas](https://togithub.com/aymanbagabas) in
[charmbracelet/lipgloss#179
- chore: bump termenv to v0.15.1 by
[@&#8203;muesli](https://togithub.com/muesli) in
[charmbracelet/lipgloss#180

**Full Changelog**:
charmbracelet/lipgloss@v0.7.0...v0.7.1

###
[`v0.7.0`](https://togithub.com/charmbracelet/lipgloss/releases/tag/v0.7.0)

[Compare
Source](https://togithub.com/charmbracelet/lipgloss/compare/v0.6.0...v0.7.0)

### Custom Renderers

We're pleased to introduce custom renders for Lip Gloss! Custom
renderers allow you to render to a specific outputs, which is
particularly important when you want to detect the color profile and
dark background status for multiple different outputs at runtime, such
as in a server-client situation.

Here's what it looks like:

```go
func myLittleHandler(sess ssh.Session) {
    // Create a renderer for the client.
    renderer := lipgloss.NewRenderer(sess)

    // Create a new style on the renderer.
    style := renderer.NewStyle().Background(lipgloss.AdaptiveColor{Light: "63", Dark: "228"})

    // Render. The color profile and dark background state will be correctly detected.
    io.WriteString(sess, style.Render("Heyyyyyyy"))
}
```

For a full example on using a custom renderer over SSH with
[Wish](https://togithub.com/charmbracelet/wish) see the [SSH
example](https://togithub.com/charmbracelet/lipgloss/blob/master/examples/ssh).

#### New API Stuff

-   `type Renderer struct`
-   `NewRenderer(io.Writer)`
-   `DefaultRenderer()`
-   `SetDefaultRenderer(*lipgloss.Renderer)`
-   `style.Renderer(*lipgloss.Renderer) Style`

#### What's Changed

##### New

- lipgloss renderer by
[@&#8203;aymanbagabas](https://togithub.com/aymanbagabas) in
[charmbracelet/lipgloss#140
and
[charmbracelet/lipgloss#174
- add BlockBorder, OuterHalfBlockBorder, and InnerHalfBlockBorder border
styles by [@&#8203;VictorBersy](https://togithub.com/VictorBersy) in
[charmbracelet/lipgloss#120

##### Fixed

- RGBA implementations for non-hex color values by
[@&#8203;muesli](https://togithub.com/muesli) in
[charmbracelet/lipgloss#126
- unify get border size function names by
[@&#8203;nerg4l](https://togithub.com/nerg4l) in
[charmbracelet/lipgloss#148
- reduce dependencies by
[@&#8203;caarlos0](https://togithub.com/caarlos0) in
[charmbracelet/lipgloss#146
- don't concurrently change output profiles by
[@&#8203;muesli](https://togithub.com/muesli) in
[charmbracelet/lipgloss#172

#### New Contributors

- [@&#8203;dependabot](https://togithub.com/dependabot) made their first
contribution in
[charmbracelet/lipgloss#133
- [@&#8203;winder](https://togithub.com/winder) made their first
contribution in
[charmbracelet/lipgloss#147
- [@&#8203;VictorBersy](https://togithub.com/VictorBersy) made their
first contribution in
[charmbracelet/lipgloss#120
- [@&#8203;nervo](https://togithub.com/nervo) made their first
contribution in
[charmbracelet/lipgloss#156
- [@&#8203;caarlos0](https://togithub.com/caarlos0) made their first
contribution in
[charmbracelet/lipgloss#146
- [@&#8203;Isti115](https://togithub.com/Isti115) made their first
contribution in
[charmbracelet/lipgloss#170
- [@&#8203;nerg4l](https://togithub.com/nerg4l) made their first
contribution in
[charmbracelet/lipgloss#148

**Full Changelog**:
charmbracelet/lipgloss@v0.6.0...v0.7.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "before 3am on Monday" (UTC),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://app.renovatebot.com/dashboard#github/sheldonhull/az-pr).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4yMi4xIiwidXBkYXRlZEluVmVyIjoiMzUuMjIuMSJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant