Skip to content

Ref: change renderer impl & add Renderer() to style#174

Merged
aymanbagabas merged 2 commits intomasterfrom
rendererpp
Mar 8, 2023
Merged

Ref: change renderer impl & add Renderer() to style#174
aymanbagabas merged 2 commits intomasterfrom
rendererpp

Conversation

@aymanbagabas
Copy link
Copy Markdown
Member

@aymanbagabas aymanbagabas commented Mar 2, 2023

A renderer determines the terminal color capabilities using Termenv. You can force a specific terminal color profile using renderer.SetColorProfile()

Add style.Renderer() to return a new style with the given renderer.

@meowgorithm
Copy link
Copy Markdown
Member

I wonder if something along the lines of AttachRenderer() better describes Clone() so that there's no ambiguity between Clone and Copy.

@maaslalani
Copy link
Copy Markdown
Contributor

maaslalani commented Mar 3, 2023

👍 to renaming Clone() to AttachRenderer(), another option would be to have WithRenderer (on the style)

func (s Style) WithRenderer(r Renderer) Style {
  // ...
}

@meowgorithm
Copy link
Copy Markdown
Member

meowgorithm commented Mar 3, 2023

another option would be to have WithRenderer (on the style)

@aymanbagabas, correct me if I'm wrong, but I believe the use case here is actually to associate styles with a specific renderer, or to change the renderer on a style.

style := lipgloss.NewStyle().Reverse()

r := lipgloss.NewRenderer()
style = style.AttachRenderer(r)

@muesli
Copy link
Copy Markdown
Contributor

muesli commented Mar 3, 2023

I agree that a different name might be better suited here. My only gripe would be that the imperative Attach as the function name's prefix suggests it's changing the renderer on the style, instead of returning a new copy.

@meowgorithm
Copy link
Copy Markdown
Member

Just to close the loop here, let’s go with Renderer for consistency with the rest of the API.

s := lipgloss.NewStyle()
r := lipgloss.NewRenderer()
s = s.Bold(true).Underline(true).Renderer(r)

@aymanbagabas aymanbagabas changed the title ref(renderer): rename renderer options & add clone Ref: change renderer impl & add Renderer() to style Mar 3, 2023
@aymanbagabas aymanbagabas merged commit b3440ac into master Mar 8, 2023
@aymanbagabas aymanbagabas deleted the rendererpp branch March 8, 2023 17:54
renovate Bot referenced this pull request in sheldonhull/az-pr 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
[https://github.com/charmbracelet/lipgloss/pull/179](https://togithub.com/charmbracelet/lipgloss/pull/179)
- chore: bump termenv to v0.15.1 by
[@&#8203;muesli](https://togithub.com/muesli) in
[https://github.com/charmbracelet/lipgloss/pull/180](https://togithub.com/charmbracelet/lipgloss/pull/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
[https://github.com/charmbracelet/lipgloss/pull/140](https://togithub.com/charmbracelet/lipgloss/pull/140)
and
[https://github.com/charmbracelet/lipgloss/pull/174](https://togithub.com/charmbracelet/lipgloss/pull/174)
- add BlockBorder, OuterHalfBlockBorder, and InnerHalfBlockBorder border
styles by [@&#8203;VictorBersy](https://togithub.com/VictorBersy) in
[https://github.com/charmbracelet/lipgloss/pull/120](https://togithub.com/charmbracelet/lipgloss/pull/120)

##### Fixed

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

#### New Contributors

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants