Rendering Lists
Render organized lists in Lip Gloss for structured terminal output.
Render Organized Lists
Lip Gloss’s list rendering sub-package lets you create structured, styled lists for your terminal apps, supporting nesting and custom enumerators for flexible layouts.
Customize lists with colors and formatting for a professional look.
List Rendering Options
Lip Gloss provides tools to create and style lists:
Define a simple list:
import "github.com/charmbracelet/lipgloss/list"
l := list.New("A", "B", "C")
fmt.Println(l)
// output will be:
// • A
// • B
// • CCreate nested lists for hierarchical data:
l := list.New(
"A", list.New("Artichoke"),
"B", list.New("Baking Flour", "Bananas", "Barley", "Bean Sprouts"),
"C", list.New("Cashew Apple", "Cashews", "Coconut Milk", "Curry Paste", "Currywurst"),
"D", list.New("Dill", "Dragonfruit", "Dried Shrimp"),
"E", list.New("Eggs"),
"F", list.New("Fish Cake", "Furikake"),
"J", list.New("Jicama"),
"K", list.New("Kohlrabi"),
"L", list.New("Leeks", "Lentils", "Licorice Root"),
)
fmt.Println(l)Customize lists with styles and enumerators:
enumeratorStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("99")).MarginRight(1)
itemStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("212")).MarginRight(1)
l := list.New(
"Glossier",
"Claire’s Boutique",
"Nyx",
"Mac",
"Milk",
).
Enumerator(list.Roman).
EnumeratorStyle(enumeratorStyle).
ItemStyle(itemStyle)Build lists incrementally:
l := list.New()
for i := 0; i < repeat; i++ {
l.Item("Lip Gloss")
}Define custom enumerators:
l := list.New("Duck", "Duck", "Duck", "Duck", "Goose", "Duck", "Duck")
func DuckDuckGooseEnumerator(l list.Items, i int) string {
if l.At(i).Value() == "Goose" {
return "Honk →"
}
return ""
}
l = l.Enumerator(DuckDuckGooseEnumerator)
fmt.Println(l)How It Works
Create and render lists in your terminal apps:
Import the List Package
Use github.com/charmbracelet/lipgloss/list to access list rendering tools.
Define List Items
Create a list with list.New() and add items or nested lists:
l := list.New("A", "B", "C")Style and Render
Apply styles or custom enumerators, then render with fmt.Println(l).
Test list rendering in your target terminal to ensure enumerators and styles display correctly.
How is this guide?