bubble-table icon indicating copy to clipboard operation
bubble-table copied to clipboard

artifacts on terminal resize

Open dh185221 opened this issue 2 years ago • 8 comments

Hi, thanks for the great library!

I've noticed that when using flex columns if I resize my terminal then some table artifacts appear on the screen. Any idea on how to clear this out when the terminal window resizes?

image

After a screen resize:

image

dh185221 avatar Jul 13 '22 09:07 dh185221

Hello! Sorry about a very slow response, I missed the notification for this.

This is caused because of the ordering of events/draws. The screen is resized, and the view is redrawn -- but the view is being redrawn before the screen resize event is received/processed. I don't know if this is deeper in Bubble Tea itself or if it's something in your code, but I've had troubles with screen resizes as well. The easiest fix is to use the 'full screen' mode with the alternate buffer as in this example: https://github.com/charmbracelet/bubbletea/blob/master/examples/fullscreen/main.go#L19

I'm not sure if there's a deeper fix that can be done on the Bubble Table side.

Evertras avatar Jul 20 '22 12:07 Evertras

Potentially related: https://github.com/charmbracelet/bubbletea/issues/377

Evertras avatar Jul 20 '22 13:07 Evertras

Hi, thanks for the response. Could this also be related to flex columns? When I run the bubble-table flex example I can see the screen artifacts even when using teat.WithAltScreen()

dh185221 avatar Jul 21 '22 09:07 dh185221

Odd... I can definitely reproduce the artifacts when I run it without the alt screen, but I cannot reproduce with the alt screen. 🤔

I can reproduce the artifacts generally if I do this:

func (m Model) View() string {
   return "Helloooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
}

Then resizing the window until the width is smaller than the text creates artifacts the same as the table. So unfortunately I'm not sure if this is something that the table itself can fix.

Evertras avatar Jul 21 '22 11:07 Evertras

Hmmm it still seems like an issue image

I'll try to look into this if I get the time

PrimalPimmy avatar Jan 11 '23 21:01 PrimalPimmy

https://github.com/Evertras/bubble-table/blob/7701b149a29bd6df06cb70c63bb0db1cd5f192b5/examples/flex/main.go#L93-L95

Maybe if we could have a rigid height of the table as well like how width is done there? Something that is comparable to msg.Height of bubbletea I suppose

PrimalPimmy avatar Jan 11 '23 21:01 PrimalPimmy

It's less about the height of the table in this case, and more about how Bubble Tea itself renders text wrapping and leaves behind artifacts when it tries to redraw outside of the alt screen. Having a target height of the table would still leave the artifacts, since nothing about the actual text rendering would be changing.

After checking the link above it looks like this was actually fixed on their end: https://github.com/charmbracelet/bubbletea/issues/297 + https://github.com/charmbracelet/bubbletea/pull/533

So maybe there's some updates that need to happen here to incorporate the change. I'll have to play a bit when I get some time.

Evertras avatar Jan 12 '23 16:01 Evertras

I seem to have the workaround by making a lipgloss style like lipgloss.NewStyle().Height(m.height).MaxHeight(m.height) and then rendering the table and now it doesn't seem to break for me :D

PrimalPimmy avatar Jan 12 '23 20:01 PrimalPimmy