Skip to content

breaking: bubbletea/lipgloss/bubbles v2#51

Draft
lrstanley wants to merge 9 commits intomasterfrom
v2-exp
Draft

breaking: bubbletea/lipgloss/bubbles v2#51
lrstanley wants to merge 9 commits intomasterfrom
v2-exp

Conversation

@lrstanley
Copy link
Owner

@lrstanley lrstanley commented Apr 29, 2025

Warning

THIS SHOULD NOT BE MERGED UNTIL the Charm team has fully released all of the associated charm libraries.
This PR is currently tagged as github.com/lrstanley/bubblezone/v2 @ v2.0.0-alpha.3. Use with:

go get github.com/lrstanley/bubblezone/v2@v2.0.0-alpha.3

You can find the API for v2 here: https://pkg.go.dev/github.com/lrstanley/bubblezone/v2@v2.0.0-alpha.3


🚀 Changes proposed by this PR

  • Switch the following deps to v2 variants (breaking change):
    • charm.land/bubbletea/v2
    • charm.land/lipgloss/v2
    • charm.land/bubbles/v2

TODO

  • Move away from the lipgloss compat for v2, and switch examples away from adaptive.
  • Investigate better alternatives to all of the type casting WRT tea.Model and tea.ViewModel -- everything I have now is just temporary for now I think.
  • See if we can replace the usage of github.com/muesli/ansi
  • Update examples to use v2 of this library.
  • Update readme to use v2 of this library.

🔗 Related bug reports/feature requests

🧰 Type of change

  • Bug fix (non-breaking change which fixes an issue).
  • New feature (non-breaking change which adds functionality).
  • Breaking change (fix or feature that causes existing functionality to not work as expected).
  • This change requires (or is) a documentation update.

🤝 Requirements

  • ✍ I have read and agree to this projects Code of Conduct.
  • ✍ I have read and agree to this projects Contribution Guidelines.
  • ✍ I have read and agree to the Developer Certificate of Origin.
  • 🔎 I have performed a self-review of my own changes.
  • 🎨 My changes follow the style guidelines of this project.
  • 💬 My changes as properly commented, primarily for hard-to-understand areas.
  • 📝 I have made corresponding changes to the documentation.
  • 🧪 I have included tests (if necessary) for this change.

- ref: #50

Signed-off-by: Liam Stanley <liam@liam.sh>
@lrstanley lrstanley self-assigned this Apr 29, 2025
@codecov
Copy link

codecov bot commented Apr 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.19%. Comparing base (0250061) to head (7266b25).
⚠️ Report is 9 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #51      +/-   ##
==========================================
- Coverage   94.07%   93.19%   -0.89%     
==========================================
  Files           5        5              
  Lines         270      235      -35     
==========================================
- Hits          254      219      -35     
  Misses         15       15              
  Partials        1        1              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: Liam Stanley <liam@liam.sh>
Signed-off-by: Liam Stanley <liam@liam.sh>
@aymanbagabas
Copy link

Hey @lrstanley, just want to drop this in and let you know that we're using this branch and patches in Soft Serve v2 https://github.com/aymanbagabas/bubblezone/tree/v2-exp. Please let me know if you have any comments or concerns 🙂

Signed-off-by: Liam Stanley <liam@liam.sh>
Signed-off-by: Liam Stanley <liam@liam.sh>
…ound color message

Signed-off-by: Liam Stanley <liam@liam.sh>
* chore: bump dependencies to charm.land modules

* fix: update examples and tests with new bubbletea v2 logic

Signed-off-by: Liam Stanley <liam@liam.sh>

* feat: update readme for v2

Signed-off-by: Liam Stanley <liam@liam.sh>

---------

Signed-off-by: Liam Stanley <liam@liam.sh>
Co-authored-by: Ayman Bagabas <ayman.bagabas@gmail.com>
@chris-kruining
Copy link

ok, I am really lost now. I migrated to v2-exp but no matter what I seem to do zone.Get always returns nil. and looking at the source code really doesn't make sense, it should just work. I have a minimal repro below

Just to that I'm not going insane: v2-exp should work right? all the checklists I saw in this repo regarding v2 were checked off, that's what I based my conclusion on.

package main

import (
	"time"

	tea "charm.land/bubbletea/v2"
	"charm.land/lipgloss/v2"
	zone "github.com/lrstanley/bubblezone/v2"
)

func main() {
	zone.NewGlobal()
	tea.NewProgram(model{}).Run()
}

// Just a generic tea.Model to demo terminal information of ssh.
type model struct {
	width   int
	height  int
	message string
}

func (m model) Init() tea.Cmd {
	return nil
}

type resetMessage struct{}

func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
	switch msg := msg.(type) {
	case resetMessage:
		m.message = ""
	case tea.MouseReleaseMsg:
		if msg.Button == tea.MouseLeft && zone.Get("button").InBounds(msg) {
			m.message = "Clicked"

			return m, tea.Tick(time.Millisecond*500, func(t time.Time) tea.Msg {
				return resetMessage{}
			})
		}
	case tea.KeyPressMsg:
		if msg.Text == "q" {
			return m, tea.Quit
		}
	case tea.WindowSizeMsg:
		m.height = msg.Height
		m.width = msg.Width
	}

	return m, nil
}

func (m model) View() tea.View {
	button := lipgloss.NewLayer(zone.Mark("button", lipgloss.NewStyle().Background(lipgloss.Blue).Render("Click me!")))
	message := lipgloss.NewLayer(m.message)
	quit := lipgloss.NewLayer(lipgloss.NewStyle().Foreground(lipgloss.Color("8")).Render("Press 'q' to quit\n"))

	c := lipgloss.NewCanvas(
		button,
		message.Y(button.GetHeight()+1),
		quit.Y(m.height-1),
	)

	v := tea.NewView(c.Render())
	v.AltScreen = true
	v.MouseMode = tea.MouseModeAllMotion

	return v
}

@lrstanley
Copy link
Owner Author

ok, I am really lost now. I migrated to v2-exp but no matter what I seem to do zone.Get always returns nil. and looking at the source code really doesn't make sense, it should just work. I have a minimal repro below

Just to that I'm not going insane: v2-exp should work right? all the checklists I saw in this repo regarding v2 were checked off, that's what I based my conclusion on.

You're missing the main zone.Scan(), which should be wrapped around your root view, as shown here (in your case, tea.NewView(zone.Scan(c.Render()))):

view.SetContent(zone.Scan(s.Render(

That said, I will say that using layers and more complex compositing, which is available with lipgloss/bubbletea v2, you may encounter issues with bubblezone v2 -- zone markers may get cut when other layers are on top of another layer. Specifically, when you use multiple z-indexed layers. There is a more native approach to mouse event tracking with layers/compositing, but I have yet to work through the support for it yet in bubblezone. However, I have been experimenting.

@chris-kruining
Copy link

chris-kruining commented Jan 20, 2026

I'm such an idiot sometimes. I had commented out the zone.Scan line in my code for some reason. Works like a charm now. Sorry to waste your time like this...

edit: ok, so not a complete idiot after all, I forgot it in my repro. but zone.Get does return nil when using the new canvas and layers

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.

feature: Support V2 BETA feature: workflow for de-duplicating mouse events when within a given zone

3 participants