Tabs
Customize tab rendering in Lip Gloss for consistent terminal output.
Handle Tabs Consistently
Lip Gloss standardizes tab character (\t) rendering, converting tabs to 4 spaces by default due to inconsistent terminal behavior. You can customize this on a per-style basis to suit your terminal app’s needs.
Pair tab customization with formatting and rules for polished terminal layouts.
Tab Rendering Options
Lip Gloss provides flexible tab width settings:
Tabs render as 4 spaces by default:
style := lipgloss.NewStyle() // tabs will render as 4 spaces, the defaultSet a custom tab width (e.g., 2 spaces):
style := lipgloss.NewStyle().TabWidth(2) // render tabs as 2 spacesRemove tabs or leave them intact:
style := lipgloss.NewStyle().TabWidth(0) // remove tabs entirely
style := lipgloss.NewStyle().TabWidth(lipgloss.NoTabConversion) // leave tabs intactHow It Works
Customize tab rendering for consistent output:
Understand Default Behavior
Lip Gloss converts tabs (\t) to 4 spaces to handle inconsistent terminal rendering (e.g., 4 or 8 spaces).
Customize Tab Width
Use TabWidth to set a specific width or disable conversion:
style := lipgloss.NewStyle().TabWidth(2)
fmt.Println(style.Render("Text\twith tabs"))Apply to Styled Text
Combine tab settings with other styles for consistent layouts in CLIs or Bubble Tea TUIs.
Tab rendering may vary across terminals. Test your app in your target terminal (e.g., iTerm2, Alacritty) to ensure consistent output.
How is this guide?