v2.0.0-beta.1
Pre-releaseReady for Bubbles v2 Beta?
We're excited to share Bubbles v2.0.0-beta.1 with you! This release builds on the last alpha release and includes a few more API changes and improvements. As usual, the upgrade path is pretty straightforward, but let us know if you have any questions.
Bear in mind you’ll want to use this updates alongside v2.0.0-beta.1 versions of Bubble Tea and Lip Gloss.
# Collect them all
go get github.com/charmbracelet/bubbletea@v2.0.0-beta.1
go get github.com/charmbracelet/bubbles@v2.0.0-beta.1
go get github.com/charmbracelet/lipgloss@v2.0.0-beta.1Let’s dive in!
The Init you know and love is back
After spending time with many different forms of Init, we've decided the v1 signature is the right way to go after all. Init is a bit too redundant for our tastes given that initialization is already happening in New. Note that this change is in alignment with current shape of Init in Bubble Tea.
// Before in alpha.2
func (m Model) Init() (Model, tea.Cmd)
// After
func (m Model) Init() tea.CmdWhat’s Changed?
In general, we've made a lot of small changes to Bubbles for consistency and future proofing. There are a lot of changes here, but we've found upgrading pretty easy regardless. If you're having trouble with anything let us know in the discussions.
🥕 List
Styles.FilterCursorandStyles.FilterPrompthave been removed and consolidated into the newStyles.Filter
👟 Progress
- The
Model.EmptyColorandModel.FullColormembers have been changed fromstringtoimage/color.Color Model.Updatenow returns aModelinstead of atea.ModelWithColorProfilehas been removed (Bubble Tea now manages this automatically)WithSolidFillnow takes ancolor.Color(from theimagepackage) instead of astring
✏️ Textarea
The big change to textarea is that you now have the option to use a real cursor per Bubble Tea v2.0.0-beta1. The feature is opt-in, so by default if you don't do anything your programs will continue to use the easy-breezy virtual cursor.
To get an idea of how to use a real cursor with textarea see
the v2 textarea example.
Model.Cursoris now a function that returns a*tea.Cursor(formerly, it was the virtual cursor model)Model.SetCursorhas been renamed toModel.SetCursorColumnCursorStylehas been added to define the cursor styleModel.VirtualCursor(abool) has been added to define whether the textarea should render a virtual cursor; set tofalsewhen using a real cursorStyles.Cursorhas been added to define the cursor style
📜 Textinput
Most of the changes in textinput are to bring it to parity with textarea,
including support for a real cursor. For an example illustrating the use of
textinput with a real cursor see
the v2 textinput example.
Most styling has been moved into StyleState which contains styling for
focused and blurred states.
Model.CompletionStylehas been moved toStylesState.SuggestionModel.PlaceholderStylehas been moved toStylesState.PlaceholderModel.PromptStylehas been and moved toStyleState.PromptModel.TextStylehas been moved toStyleState.TextCursorStylehas been added to define the cursor styleModel.VirtualCursorwas added; use it to disable the virtual cursorModel.Styles(andStyles) was added to house all styling.StyleStatewas added to manage styling for focused and blurred statesModel.Cursoris now afunc() *tea.Cursorfor real cursor support (formerly, it was the virtual cursor model)DefaultStyleshas been addedDefaultDarkStyleshas been addedDefaultLightStyleshas been added
📦 Viewport
The new viewport now supports horizontal scrolling as well as setting a custom gutter column! You can also now scroll horizontally with the left and right arrow keys. Finally, you can now highlight parts of what's being viewed based on regex.
vp := viewport.New()
vp.SetContent("hello world")
// Show line numbers:
vp.LeftGutterFunc = func(info viewport.GutterContext) string {
if info.Soft {
return " │ "
}
if info.Index >= info.TotalLines {
return " ~ │ "
}
return fmt.Sprintf("%4d │ ", info.Index+1)
}
// Highlight things:
vp.SetHighlights(regexp.MustCompile("hello").FindAllStringIndex(vp.GetContent(), -1))
vp.HighlightNext() // highlight and navigate to next match
vp.HighlightPrevious() // highlight and navigate to previous match
vp.ClearHighlights() // clear all highlightsYou may now also let viewport do the soft wrapping for you:
vp := viewport.New()
vp.SoftWrap = true
vp.SetContent("hello world from a very long line")But, if you need more fine control on soft wrapping, you can also use the SetContentLines method. This method allows you to set "virtual lines", which may contain \n in them. These lines are automatically treated as soft wraps, and scrolling also takes then into consideration.
Like details?
Here’s the full changelog since v2.0.0-alpha.2
💝 That’s a wrap!
Feel free to reach out, ask questions, give feedback, and let us know how it's going. We’d love to know what you think.
Part of Charm.
Charm热爱开源 • Charm loves open source • نحنُ نحب المصادر المفتوحة
