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

feat: convert tabs to spaces with Style.TabWidth(int) #204

Merged
merged 2 commits into from
Jul 24, 2023
Merged

Conversation

meowgorithm
Copy link
Member

@meowgorithm meowgorithm commented Jul 24, 2023

Lip Gloss currently mis-measures a tab (i.e. a \t) at 0 cells wide when they actually render at different widths in different terminals (usually 8 cells, sometimes 4 cells). For theses reasons tabs are almost never what you want when designing layouts for TUIs.

With this revision, a tab will get converted to 4 spaces by default—so this is a behavioral change—but you can customize the behavior and disable it entirely with the new TabWidth(int) method.

s := lipgloss.NewStyle()        // 4 spaces per tab, the default
s = s.TabWidth(2)               // 2 spaces per tab
s = s.TabWidth(0)               // remove tabs
s = s.TabWidth(-1)              // don't convert tabs to spaces
s = s.TabWidth(NoTabConversion) // alias of the above

Disable the feature with Style.TabWidth(-1) feels a little kludgy but is perhaps okay with the addition of the NoTabConversion const. The alternative would be to have a separate method for disabling the behavior (Style.DisableTabConversion(true) or something) but what I don't love about that is that the two settings would then compete with each other.

By default tabs will be converted to 4 spaces. To disable tab
converstion set TabWidth(-1).
@meowgorithm meowgorithm merged commit df8b3fa into master Jul 24, 2023
18 checks passed
@meowgorithm meowgorithm deleted the tabs branch July 24, 2023 15:22
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

Successfully merging this pull request may close these issues.

2 participants