Skip to content

Commit 6a69e91

Browse files
fabio42fbessett
authored andcommitted
(fix)table: don't render a column with a width <= 0 (charmbracelet#465)
* (fix)table: don't render a column with a width <= 0 This address charmbracelet#464 * Better check location --------- Co-authored-by: Fabrice Bessettes <[email protected]>
1 parent 849cd3c commit 6a69e91

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

table/table.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,9 @@ func (m *Model) FromValues(value, separator string) {
426426
func (m Model) headersView() string {
427427
var s = make([]string, 0, len(m.cols))
428428
for _, col := range m.cols {
429+
if col.Width <= 0 {
430+
continue
431+
}
429432
style := lipgloss.NewStyle().Width(col.Width).MaxWidth(col.Width).Inline(true)
430433
renderedCell := style.Render(runewidth.Truncate(col.Title, col.Width, "…"))
431434
s = append(s, m.styles.Header.Render(renderedCell))
@@ -436,6 +439,9 @@ func (m Model) headersView() string {
436439
func (m *Model) renderRow(rowID int) string {
437440
var s = make([]string, 0, len(m.cols))
438441
for i, value := range m.rows[rowID] {
442+
if m.cols[i].Width <= 0 {
443+
continue
444+
}
439445
style := lipgloss.NewStyle().Width(m.cols[i].Width).MaxWidth(m.cols[i].Width).Inline(true)
440446
renderedCell := m.styles.Cell.Render(style.Render(runewidth.Truncate(value, m.cols[i].Width, "…")))
441447
s = append(s, renderedCell)

0 commit comments

Comments
 (0)