Skip to content

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

Open
@JaredReisinger

Description

@JaredReisinger

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions