charmbracelet / bubbles

TUI components for Bubble Tea 🫧
MIT License
5.47k stars 263 forks source link

Viewport: truncation and wrapping options #56

Open meowgorithm opened 3 years ago

meowgorithm commented 3 years ago

It would be nice if the viewport provided some options to automatically wrap and truncate text to keep layouts from breaking, rather than leaving this as an exercise for the user.

The most likely solution here is to take advantage of reflow.

mrusme commented 2 years ago

Is this the reason why SetcContent with a very large text will make the viewport expand in height? I was under the assumption that I might have done something wrong, so I'm still looking into why the viewport won't obey the height I set. I thought that a large content will make the viewport scroll vertically.

meowgorithm commented 2 years ago

@mrusme iirc, yes. you'll want to wrap your text with something like:

str := lipgloss.NewStyle().Width(width).Render(content)
model.SetContent(str)
captv89 commented 2 weeks ago

@meowgorithm When the length of a line exceeds the width of the terminal, the line is soft-wrapped as per your example above. However, this is affects the scrolling. Scrolling is still assuming that each content line = line in the terminal, and stops after the YOffset has been incremented to the int value, which is the difference between viewport lines and total content lines. This affects the scroll percentage as well.