charmbracelet / bubbletea

A powerful little TUI framework 🏗
MIT License
25.65k stars 744 forks source link

Flickering on Windows when using bubbletea >=0.26.0 #1019

Closed supleed2 closed 2 months ago

supleed2 commented 2 months ago

Describe the bug I tried updating to Bubbletea v0.26.0 (and also .1/.2) but the output seems to flicker a lot when running on Windows.

Setup Please complete the following information along with version numbers, if applicable.

To Reproduce I don't have a minimal reproducible example yet, but noticed this while updating dependencies on my project, linked below. Specifically the client binary which uses bubbletea for the UI.

Source Code Available here: supleed2/go-chat

Expected behavior Stable output as with v0.25.0, observed with binaries available at: https://github.com/supleed2/go-chat/releases/tag/v0.1.2

Ideally with the new ability to resize :)

Screenshots GIF to demonstrate:

clip

meowgorithm commented 2 months ago

Okay awesome, thanks for reporting this. There's seems to be a bug in Windows where going in and out of the altscreen will incorrectly fire off a WindowResizeMsg. This wasn't the case in prior versions of Bubble Tea because resize events weren't possible.

In your case the flickering is happening because of this line, which seems to have been left in by mistake:

diff --git a/client/main.go b/client/main.go
index b8fe61a..37b8bd7 100644
--- a/client/main.go
+++ b/client/main.go
@@ -246,7 +246,6 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
            m.input.Reset()
        }
    case tea.WindowSizeMsg:
-       clCmd = tea.Sequence(tea.ExitAltScreen, tea.EnterAltScreen)
        m.history.Height = msg.Height - 2
        m.history.Width = msg.Width
        m.history.GotoBottom()

Of course, WindowSizeMsgs shouldn't be fired off at all during altscreen toggles, so we'll also make the corrections in Bubble Tea.

supleed2 commented 2 months ago

🤦 I just have to say thank you so much for digging through and noticing what was wrong with my code.

Yes that was left in, from a previous attempt where I thought maybe exiting and re-entering altscreen would cause new Height/Width values to be used.

Just tested removing the line and yep, works exactly as expected, including resizing! ❤️