Bubble Tea v2 Beta: What’s New in v2 + How to Upgrade #1374
Replies: 3 comments 8 replies
-
Congratulations on the release, just a quick question - are bugfixes for main branch (V1) code still actively wanted or should pull requests be tailored directly to v2-exp branch (V2) code? Just asking for problems that may exist both in V1 and V2 code - would you like respective pull requests for both branches or just V2? Is V1 now EOL or are there still going to be (bugfix) releases? 😉 |
Beta Was this translation helpful? Give feedback.
-
Looking forward to upgrade! But, the link full v2 release notes and upgrade guide. is pointing to example.com |
Beta Was this translation helpful? Give feedback.
-
FYI I tried
From
The following works without any issues: by commit:
by branch:
|
Beta Was this translation helpful? Give feedback.
-
Welcome to Bubble Tea v2
We're very excited to announce the forthcoming second major release of Bubble Tea! This document outlines the changes and improvements in Bubble Tea v2.0.0 and generally serves as a migration guide.
Note
We don't take API changes lightly 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 Cursed Renderer
Bubble Tea v2 ships with the all-new Cursed Renderer which was built from the ground up. It's based on the ncurses rendering algorithm and is highly optimized for speed, efficiency, and accuracy and is built on an enormous amount of research and development.
Optimized renders also means that Wish users get big performance benefits and lower bandwidth usage by orders of magnitude.
To take advantage of the new Cursed Renderer you don't need to do anything at all except keep on using the Bubble Tea you know and love.
✌️ Key handling is way better now
Newer terminals can now take advantage of all sorts keyboard input via progressive keyboard enhancements. You can now map all sorts of keys and modifiers like shift+enter and super+space. You can also detect key releases (we're looking at you, game developers).
It's easy to detect support for supporting terminals and add fallbacks for those that don't. For details, see keyboard enhancements below.
🥊 No more fighting
In the past, Bubble Tea and Lip Gloss would often fight over i/o. Bubble Tea wanted to read keyboard input and Lip Gloss wanted to query for the background color. This means that things this could get messy. Not anymore! In v2, Lip Gloss is now pure, which means, Bubble Tea manages i/o and gives orders to Lip Gloss. In short, we only need one lib to call the shots call the shots, and in the context of this relationship, that lib is Bubble Tea.
But what about color downsampling? That's a great question.
👨🏻🎨 Built-in Color Downsampling
We sneakily released a little library called colorprofile that will detect the terminal's color profile and auto-downsample any ANSI styling that flows through it to the best available color profile. This means that color will "just work" (and not misbehave) no matter where the ANSI styling comes from.
Downsampling is built-into Bubble Tea and is automatically enabled.
API Updates
Keyboard Enhancements
Progressive keyboard enhancements, allow you to receive key events not normally possible in traditional terminals. For example, you can now listen for the super key (aka, the Windows key on Windows and the Command key on macOS), as well as previously unavailable key combinations like the covetted shift+enter.
To enable this feature use the
tea.WithKeyboardEnhancements
option when creating a new program to get all the keys, in supported terminals only.You can enable enhanced keyboard support by passing the
tea.WithKeyboardEnhancements
option totea.NewProgram
or by using thetea.RequestKeyboardEnhancements
command.By default, only key disambiguation is enabled. What does that even mean? Historically, certain key combinations in terminals map to control codes. For example, ctrl+h outputs a backspace by default, which means you can't normally bind a key event to ctrl+h. With key disambiguation, you can now actually bind events to those key combinations.
Release events aren't included by default when you enable keyboard enhancements, but you can opt-into them with the
tea.WithKeyReleases
flag:You can detect if a terminal supports keyboard enhancements by listening for
tea.KeyboardEnhancementsMsg
after enabling progressive enhancements.Note
This feature is enabled by default on Windows due to the fact that we use the Windows Console API to support other Windows features.
Which terminals support progressive enhancement?
Uniform Key Handling
When targeting users on different platforms and keyboard layouts, it's important to have a consistent and reliable way to handle key events. With this release, you can now use
tea.WithUniformKeyLayout
keyboard enhancement to ensure that your program works as expected across different keyboard layouts.For example, on a multi-layout QWERTY keyboard, ctrl+a should always trigger a
ctrl+a
event, regardless of the layout language. Similarly, shift+h should send ashift+h
event with the letterH
as its printable value. But what happens when you press shift+h in a different QWERTY layout?Let's take the PC-101 QWERTY Arabic layout as an example. In this layout, shift+h corresponds to the Arabic letter
أ
. If you're building a game or an application that relies on key events where you don't really care about the actual printable value of the key press, you'd want to ensure that shift+h always sends ashift+h
event despite the layout language.This will also respect the keyboard layout and send the correct printable value for the key press. For example, on a US QWERTY keyboard, ctrl+a corresponds to the first letter on the second row of the keyboard. On a French AZERTY keyboard, the same key combinations correspond to ctrl+q.
To achieve this, you can use the
tea.WithUniformKeyLayout
option and let Bubble Tea handle the rest.Changed: Key Messages
Key messages are now split into
tea.KeyPressMsg
andtea.KeyReleaseMsg
. Usetea.KeyMsg
to match against both.We also no longer have
key.Type
andkey.Runes
fields. These have been replaced withkey.Code
andkey.Text
respectively. A key code is just arune
that represents the key message. It can be a special key liketea.KeyEnter
,tea.KeyTab
,tea.KeyEscape
, or a printable rune.The new
key.Text
field signifies a printable key event. If the key event has a non-emptyText
field, it means the key event is a printable key event. In that case,key.Code
is always going to be the first rune ofkey.Text
.Instead of matching against
msg.Type == tea.KeyCtrl...
keys, key modifiers are now part of the key event itself askey.Mod
. Shifted keys now have their own key code inkey.ShiftedCode
. Typing shift+b will producekey.Code == 'b'
,key.ShiftedCode == 'B'
,key.Text == "B"
, andkey.Mod == tea.ModShift
.The easiest way to match against key press/release events is to use
msg.String()
:Oh, and we finally changed space bar to return
"space"
instead of" "
. In this case,key.Code == ' '
andkey.Text == " "
.Paste messages
Bubble Tea v1 supports bracketed-paste mode by default. It sends paste events as a
tea.KeyMsg
withmsg.Paste
flag set totrue
, which to be honest, was pretty confusing.In Bubble Tea v2, paste events are sent as their own
tea.PasteMsg
message. You can listen also listen to pastetea.PasteStartMsg
andtea.PasteEndMsg
events to detect paste start and end events.Mouse messages
We've also improved the mouse API, which is a breaking change. Use
tea.MouseMsg
to match against different types of mouse events. Mouse messages are split intotea.MouseClickMsg
,tea.MouseReleaseMsg
,tea.MouseWheelMsg
, andtea.MouseMotionMsg
.An Actual Cursor
Another nice feature in Bubble Tea v2 is the ability to control the cursor. Now, the
tea.Model
interface is split intotea.Model
andtea.ViewModel
. Or if you're interested in controlling the cursor, you can use thetea.CursorModel
interface.The
tea.CursorModel
interface returns a*tea.Cursor
struct that contains the cursor's position, style, and visibility. Do you want it hidden? Sure, just returnnil
and everything will be taken care of.Other new things
Native clipboard support
Bubble Tea now supports native clipboard operations, also known as OSC52. This means you can even copy and paste over SSH!
X11 and Wayland users can also use
tea.SetPrimaryClipboard
to set the primary clipboard. Note that this is a very niche sort of thing and may or may not work on macOS, Windows, and other platforms without the notion of more than one clipboard.Terminal colors
You can now read and set the terminal's foreground, background, and cursor colors. This is useful for creating advanced terminal applications.
To change the terminal's colors, use
tea.SetForegroundColor
,tea.SetBackgroundColor
, andtea.SetCursorColor
.Terminal version and name
Don't know what terminal you're running in?
$TERM
is too vague? Bubble Tea now has atea.TerminalVersion
command that queries the terminal for its name and version using XTVERSION control sequence.Note
This feature is not supported by all terminals.
Terminfo and Termcap capabilities
Sometimes you need to know what capabilities the terminal has. Bubble Tea now has a
tea.RequestCapability
command that queries the terminal for a specific terminfo/termcap capability.Note
This feature is not supported by all terminals.
Detecting the color profile
Need to use the detected color profile in your app? Listen to
tea.ColorProfileMsg
inUpdate
:Manually applying a color profile
What's that you say? You want to manually set a color profile for testing? Now you can, on the program level.
Want to hard detect the color profile in Wish? We bet you do.
🍇 Grapheme Clustering
Grapheme what? In short, grapheme clustering is a way to handle Unicode text segmentation and boundaries. It's useful when you want to determine the terminal cell width a string or a grapheme cluster occupies. The algorithm is defined in the Unicode Text Segmentation UAX #29.
For example, '🧑🌾' is a single grapheme cluster, but it's made up of 3 UTF-8 codepoints. Terminals that support grapheme clustering will treat this as a 2 cell wide character, while those that don't might treat it as 2, 4, 5, or even 6 cells wide. Our friend Mitchell Hashimoto has a great blog post on this topic: Grapheme Clusters and Terminal Emulators.
We've added grapheme clustering and mode 2027 support in the previous alpha.1 release, and it was on by default. We've noticed that some terminals, like Apple Terminal, don't play well with this feature. Specifically, with the
DECRQM
control sequence. Not cool.Now we're making the feature opt-in and off by default. You can still enable it by using the
tea.WithGraphemeClustering
option.Want to learn more about grapheme clusters? Mitchell Hashimoto has a great post about it.
Feedback
Have thoughts on Bubble Tea v2 Alpha? We’d love to hear about it. Let us know on…
Part of Charm.
Charm热爱开源 • Charm loves open source • نحنُ نحب المصادر المفتوحة
Beta Was this translation helpful? Give feedback.
All reactions