charmbracelet / bubbletea

A powerful little TUI framework 🏗
MIT License
28.03k stars 808 forks source link

text rendering incorrectly using serial data #931

Open Horryportier opened 9 months ago

Horryportier commented 9 months ago

Describe the bug text dose not render correctly when inserting longer line

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

To Reproduce i have text value that i append to data from serial port and its displayed

Source Code https://github.com/Horryportier/go-serial-tui/blob/main/main.go

Expected behavior content should not disappear whenever longer line is append. from my test's when not using data from serial it works without any issues

Screenshots https://github.com/charmbracelet/bubbletea/assets/42907709/f60e8030-80da-46a3-bd8e-7f7bead8d006

muesli commented 8 months ago

You need to wrap your content at the given maximum width.

Horryportier commented 8 months ago

https://github.com/charmbracelet/bubbletea/issues/43 looked at this issue and added wrapping using github.com/muesli/reflow/wordwrap package yet it still has that weird despairing bug although text appears when i add long enough string so wordwrap triggers and then all seems to stay on screen from that point on

m1cm1c commented 8 months ago

43 looked at this issue and added wrapping using github.com/muesli/reflow/wordwrap package yet it still has that weird despairing bug although text appears when i add long enough string so wordwrap triggers and then all seems to stay on screen from that point on

I'm experiencing this exact bug. I thought about calling

import (
    "github.com/inancgumus/screen"
)

func clearScreen() {
    screen.Clear()
    screen.MoveTopLeft()
}

in the beginning of View() but https://pkg.go.dev/github.com/charmbracelet/bubbletea#ClearScreen states: "Note that it should never be necessary to call ClearScreen() for regular redraws." So I think there must be a better way to fix this. Did you figure something out by now?

meowgorithm commented 8 months ago

Hi! @Horryportier or @m1cm1c: can you produce a minimal example, with reflow, that reproduces the issue? That will help us solve this quickly and effectively. If the bug you're seeing is in reflow itself, let's close this issue and open an issue there.

Horryportier commented 8 months ago

I don't thing reflowis the issue, bug was present before I've added that library. Wordwrap solved issue partially because it still would occurred for strings shorter that wrap threshold but it would fix itself after wordwrap was triggered

As for reproducing the bug it would hard because it only occurs for me when dealing with text data from serial port. So there might be issue with data send from esp32 having some weird glyphs. Although arduino ide 2 works just fine.

m1cm1c commented 8 months ago

@meowgorithm Here is a fairly small program that reliably reproduces the described behavior: https://gist.github.com/m1cm1c/0248ef748db56d0cc1f7e4398a3f2fad

I ran it via: go run .

Initial state (looks fine): image

After making the window wider (looks fine): image

After making the window narrower again, "(esc to quit)" repeats: image

OS: Manjaro Go version: 1.21.7 Architecture: AMD64 Terminal: xfce4-terminal (version 1.1.3) Shell: GNU bash (version 5.2.26(1))

Horryportier commented 8 months ago

that looks like different bug than mine mine makes first few characters disappear corresponding to amount of additional text image image image