Skip to content
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

Question: should wordwrap support a "hard wrap if needed" option? #68

Open
JaredReisinger opened this issue Nov 19, 2023 · 0 comments
Open

Comments

@JaredReisinger
Copy link

JaredReisinger commented Nov 19, 2023

I'm learning bubbletea and lipgloss, and reading a lot of the code because I'm not finding any descriptions about the "box model" (so to speak) that explains how width, padding, border, and margins interact. In doing so, I ran across this code in lipgloss/style.go:

str = wordwrap.String(str, wrapAt)
str = wrap.String(str, wrapAt) // force-wrap long strings

If you have a series of words just longer than the limit, you will get weird, orphaned pieces. For example, wrapping 123456789 123 123456789 123 123456789 123 at length 8 using the above code, the initial wordbreak will leave the length-9 words intact, but add newlines after them, causing the short words to always be on their own lines:

wordwrap    ==> wrap
--------|       --------|   
12345678|9      12345678|  (hard break)  
123     |       9       |
12345678|9      123     |   
123     |       12345678|  (hard break)
12345678|9      9       |
                123     |   
                12345678|  (hard break)
                9       |

If wordbreak had a "hard break if needed", the calling code would just call "wordwrap with hard-breaks", and get:

wordwrap+hard
--------|
12345678|  (hard break)
9 123   |  ("123" fits, soft-wrap afterwards)
12345678|  (hard break)
9 123   |  ("123" fits, soft-wrap afterwards)
12345678|  (hard break)
9

Would that be useful?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant