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
- 7862f52: feat(table): improve sizing and behavior: wrap by default, overflow optionally (@andreynering)
- 1f1209e: feat(table): use cellbuf to preserve styles for wrapped content (@bashbunni)
- c454a0a: feat(tables): add markdown and ascii border style for tables (#480) (@andreynering)
- bafb8fd: feat(tree): hide children (#460) (@bashbunni)
- 9942166: feat: style ranges (#458) (@caarlos0)
Bug fixes
- 9500f10: fix(table): ensure we're passing the right row index to
styleFunc
(@andreynering) - 7b191c5: fix(test): make table wrapping tests use golden files (@bashbunni)
- 9b8304f: fix: border size getters when implicit borders are present (#411) (@meowgorithm)
- 022e967: fix: range test (@caarlos0)
Other work
- ecc1bd0: fix: comment on min func in utils (@derezzolution)
- 5cd2074: style(table): improve naming of the resizer functions (@andreynering)
- 9cfb7dd: test(table): check truncation logic for overflow and nowrap (@bashbunni)
- 2aa2eb0: test(table): test wrapping cell styles (@bashbunni)
- ca67d0f: chore(lint): apply De Morgans law to the if statement (@aymanbagabas)
- 0fbb070: chore(lint): fix lint ignore comments (@andreynering)
Thoughts? Questions? We love hearing from you. Feel free to reach out on Twitter, The Fediverse, or on Discord.