Lip Gloss v2 Beta: What’s New + How to Upgrade #506
Replies: 2 comments
-
Hey! I have been using v2 alpha for a bit and I loved the migration of the Init function to be able to return the model and a command. I just upgraded to the beta and I see that Init now just returns a command. Was this a mistake or did I miss a change announcement? https://github.com/charmbracelet/bubbletea/blob/v2.0.0-beta.1/tea.go EDIT: Turns out I posted this way too late and should have went to bed. I found the announcement in the Bubbletea release notes. Please ignore this. |
Beta Was this translation helpful? Give feedback.
-
Hi, thanks for the great work on I'm wondering if there's any interest or plan to support an HTML-like tag syntax for inline styling within a single string, similar to how Print("<fg=11aa23;op=bold>Hello</> <cyan>World</>\n") This kind of syntax is quite convenient when working with mixed styles in a single line of text, and it can help reduce the verbosity of manually splitting and styling segments with multiple Is this something that could be considered for lipgloss v2, or do you see it as outside the scope of the library? Thanks again! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Do you think you can handle Lip Gloss v2?
We’re really excited for you to try Lip Gloss v2! Read on for new features and a guide to upgrading.
Note
We take API changes seriously and strive to make the upgrade process as simple as possible. We believe the changes bring necessary improvements as well as pave the way for the future. If something feels way off, let us know.
What’s new?
The big changes are that Styles are now deterministic (λipgloss!) and you can be much more intentional with your inputs and outputs. Why does this matter?
Playing nicely with others
v2 gives you precise control over I/O. One of the issues we saw with the Lip Gloss and Bubble Tea v1s is that they could fight over the same inputs and outputs, producing lock-ups. The v2s now operate in lockstep.
Querying the right inputs and outputs
In v1, Lip Gloss defaulted to looking at
stdin
andstdout
when downsampling colors and querying for the background color. This was not always necessarily what you wanted. For example, if your application was writing tostderr
while redirectingstdout
to a file, the program would erroneously think output was not a TTY and strip colors. Lip Gloss v2 gives you control over this.Going beyond localhost
Did you know TUIs and CLIs can be served over the network? For example, Wish allows you to serve Bubble Tea and Lip Gloss over SSH. In these cases, you need to work with the input and output of the connected clients as opposed to
stdin
andstdout
, which belong to the server. Lip Gloss v2 gives you flexibility around this in a more natural way.🧋 Using Lip Gloss with Bubble Tea?
Make sure you get all the latest v2s as they’ve been designed to work together.
# Collect the whole set. go get github.com/charmbracelet/bubbletea/v2 go get github.com/charmbracelet/bubbles/v2 go get github.com/charmbracelet/lipgloss/v2
🐇 Quick upgrade
If you don't have time for changes and just want to upgrade to Lip Gloss v2 as fast as possible? Here’s a quick guide:
Use the
compat
packageThe
compat
package provides adaptive colors, complete colors, and complete adaptive colors:compat
works by looking atstdin
andstdout
on a global basis. Want to change the inputs and outputs? Knock yourself out:Use the new Lip Gloss writer
If you’re using Bubble Tea with Lip Gloss you can skip this step. If you're using Lip Gloss in a standalone fashion, however, you'll want to use
lipgloss.Println
(andlipgloss.Printf
and so on) when printing your output:Why? Because
lipgloss.Println
will automatically downsample colors based on the environment.That’s it!
Yep, you’re done. All this said, we encourage you to read on to get the full benefit of v2.
👀 What’s changing?
Only a couple main things that are changing in Lip Gloss v2:
🪄 Downsampling colors with a writer
One of the best things about Lip Gloss is that it can automatically downsample colors to the best available profile, stripping colors (and ANSI) entirely when output is not a TTY.
If you're using Lip Gloss with Bubble Tea there's nothing to do here: downsampling is built into Bubble Tea v2. If you're not using Bubble Tea you now need to use a writer to downsample colors. Lip Gloss writers are a drop-in replacement for the usual functions found in the
fmt
package:🌛 Background color detection and adaptive colors
Rendering different colors depending on whether the terminal has a light or dark background is an awesome power. Lip Gloss v2 gives you more control over this progress. This especially matters when input and output are not
stdin
andstdout
.If that doesn’t matter to you and you're only working with
stdout
you skip this viacompat
above, though we encourage you to explore this new functionality.With Bubble Tea
In Bubble Tea, request the background color, listen for a
BackgroundColorMsg
in your update, and respond accordingly.Standalone
If you're not using Bubble Tea you simply can perform the query manually:
🥕 Other stuff
Colors are now
color.Color
lipgloss.Color()
now produces an idiomaticcolor.Color
, whereas before colors were typelipgloss.TerminalColor
. Generally speaking, this is more of an implementation detail, but it’s worth noting the structural differences.🌈 Feedback
That's a wrap! Feel free to reach out, ask questions, and let us know how it's going. We'd love to know what you think.
Part of Charm.
Charm热爱开源 • Charm loves open source • نحنُ نحب المصادر المفتوحة
Beta Was this translation helpful? Give feedback.
All reactions