charmbracelet / lipgloss

Style definitions for nice terminal layouts 👄
MIT License
8.24k stars 231 forks source link

fix(render): strip carriage returns from strings #386

Closed bashbunni closed 1 month ago

bashbunni commented 1 month ago

If a string contains carriage returns \r, it will cause some funky issues when rendering. More specifically any time we do any string concatenation, string A will be overwritten by string B instead of appended.

this is an example log output when a string has a \r and goes through alignHorizontal to pad spaces

2024/10/07 13:36:43 end of horizontal align
git: 'defer' is not a git command. See 'git --help'.
----------------------------------------------------
-----------------------ds are
------------------------------------------
------------------------------------------
----------------------------------------------------

After this change:

2024/10/07 13:53:24 end of horizontal align
git: 'defer' is not a git command. See 'git --help'.
----------------------------------------------------
The most similar commands are-----------------------
    rerere------------------------------------------
    revert------------------------------------------
----------------------------------------------------

related: https://github.com/charmbracelet/freeze/pull/119

bashbunni commented 1 month ago

Added a test that reproduces this behaviour. I notice that it only happens when Margin is set which is interesting. If you want to see for yourself, run the test on master and you'll see it fail