-
Notifications
You must be signed in to change notification settings - Fork 832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The visible area in viewport may seem incorrect when content exceed the viewport.Width #1017
Comments
I am using this lib to create a terminal application. But there seems to be some problem when rendering a long text in a small viewport area. Everytime when server informs me with a new message, I expect to append the message to the new line.
When receiving short messages, this will work as the example shows.
I'm wondering if bubbletea provides a decent method to handle with the newline, or is this a bug related to the viewport? |
Any updates on this issue? |
Hi @MTTMTTMTT , I would love to work on this, let me reproduce it in my local. |
Thanks for your reply! I will wait for your feedback. |
Hi @MTTMTTMTT , I think it is expected to wrap around, because the message is more than 30 characters. But I'm agree that it's weird, that the message ends with the Btw, your solution are these to options right?:
If so, then I like solution no 2 more, because in solution no 1, we cannot read the end of the sentence (get trimmed because it's the 31st character and more) Wdyt? |
Btw, take a look at this: charmbracelet/bubbles#509 |
Yes, the msg555, msg666, and msg777 is buried under. This is the problem I encounted. @pikomonde For my solution 1, I mean to cut the string into []string slices. package main
import (
"fmt"
)
func main() {
fmt.Println(SoftWrap(5, "aaaaabbbbbcccccddddd"))
}
func SoftWrap(width int, msg string) []string {
if len(msg) <= width {
return []string{msg}
}
result := make([]string, 0)
result = append(result, msg[:width])
result = append(result, SoftWrap(width, msg[width:])...)
return result
} This could help but make me headache with another problem, the Chinese characters. But this doesn't matter, let's just ignore the Chinese characters problem now. |
I took a look at the charmbracelet/bubbles#509. I also find my issue same to charmbracelet/bubbles#479 |
Oh, got it, so you want to make the software to new line. To summarize: The input:
Current Implementation:
Expected Implementation:
CMIIW |
@MTTMTTMTT please check, I've created the PR, I think it should solve the Chinese characters problem. I haven't try it for that case |
Describe the bug
When I am using a viewport (fixed width and height) and set content with a very long text, the visible area may be incorrect because of multilines.
The viewport.GotoBottom() seems ineffective.
Setup
To Reproduce
viewport.New(30, 5)
Source Code
Using the example
https://github.com/charmbracelet/bubbletea/blob/master/examples/chat/main.go
Expected behavior
When inputting short text.
When inputting long text.
The text was updated successfully, but these errors were encountered: