From 1029f3164d6379df19b2d36eb0bc03c5ec6a6b81 Mon Sep 17 00:00:00 2001 From: Fabrice Bessettes Date: Wed, 28 Feb 2024 12:15:07 -0500 Subject: [PATCH] (fix)table: don't render a column with a width <= 0 (#465) * (fix)table: don't render a column with a width <= 0 This address #464 * Better check location --------- Co-authored-by: Fabrice Bessettes --- table/table.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/table/table.go b/table/table.go index c389a0d..fcb9011 100644 --- a/table/table.go +++ b/table/table.go @@ -387,6 +387,9 @@ func (m *Model) FromValues(value, separator string) { func (m Model) headersView() string { var s = make([]string, 0, len(m.cols)) for _, col := range m.cols { + if col.Width <= 0 { + continue + } style := lipgloss.NewStyle().Width(col.Width).MaxWidth(col.Width).Inline(true) renderedCell := style.Render(runewidth.Truncate(col.Title, col.Width, "…")) s = append(s, m.styles.Header.Render(renderedCell)) @@ -397,6 +400,9 @@ func (m Model) headersView() string { func (m *Model) renderRow(rowID int) string { var s = make([]string, 0, len(m.cols)) for i, value := range m.rows[rowID] { + if m.cols[i].Width <= 0 { + continue + } style := lipgloss.NewStyle().Width(m.cols[i].Width).MaxWidth(m.cols[i].Width).Inline(true) renderedCell := m.styles.Cell.Render(style.Render(runewidth.Truncate(value, m.cols[i].Width, "…"))) s = append(s, renderedCell)