github charmbracelet/lipgloss v1.1.0

one day ago

Tables, Improved

In this release, the inimitable @andreynering and @bashbunni majorly overhauled on the table sizing and content wrapping algorithms. Tables will now be much smarter on deciding the ideal width of each column, and contents now wraps by default inside cells.

// Table content wraps by default.
t := table.New().
    Headers(someHeaders...).
    Rows(someRows...).
    Width(80)

fmt.Println(t)
// Actually, let's not wrap the content.
t := table.New().
    Headers(someHeaders...).
    Rows(someRows...).
    Width(80).
    Wrap(false)

fmt.Println(t)

New Border Styles

Also, we added two new border styles that you can use to generate tables in Markdown and ASCII styles.

Markdown Tables

To render tables correctly for Markdown you'll want to use lipgloss.MarkdownBorder and disable the top and bottom borders.

t := table.New().
    Headers(someHeaders...).
    Rows(someRows).
    Border(lipgloss.MarkdownBorder()).
    BorderTop(false).
    BorderBottom(false)

fmt.Println(t)

ASCII Tables

To render an ASCII-style table use lipgloss.ASCIIBorder.

t := table.New().
    Headers(someHeaders...).
    Rows(someRows).
    Border(lipgloss.ASCIIBorder())

fmt.Println(t)

Thanks everyone

Special thanks to @aymanbagabas, @bashbunni, @andreynering, and @caarlos0 for or all the work on this release!


Changelog

New Features

Bug fixes

Other work


The Charm logo

Thoughts? Questions? We love hearing from you. Feel free to reach out on Twitter, The Fediverse, or on Discord.

Don't miss a new lipgloss release

NewReleases is sending notifications on new releases.