Skip to content

Commit cc5264c

Browse files
fabio42fbessett
andauthored
(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 d9fe1a7 commit cc5264c

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
@@ -387,6 +387,9 @@ func (m *Model) FromValues(value, separator string) {
387387
func (m Model) headersView() string {
388388
var s = make([]string, 0, len(m.cols))
389389
for _, col := range m.cols {
390+
if col.Width <= 0 {
391+
continue
392+
}
390393
style := lipgloss.NewStyle().Width(col.Width).MaxWidth(col.Width).Inline(true)
391394
renderedCell := style.Render(runewidth.Truncate(col.Title, col.Width, "…"))
392395
s = append(s, m.styles.Header.Render(renderedCell))
@@ -397,6 +400,9 @@ func (m Model) headersView() string {
397400
func (m *Model) renderRow(rowID int) string {
398401
var s = make([]string, 0, len(m.cols))
399402
for i, value := range m.rows[rowID] {
403+
if m.cols[i].Width <= 0 {
404+
continue
405+
}
400406
style := lipgloss.NewStyle().Width(m.cols[i].Width).MaxWidth(m.cols[i].Width).Inline(true)
401407
renderedCell := m.styles.Cell.Render(style.Render(runewidth.Truncate(value, m.cols[i].Width, "…")))
402408
s = append(s, renderedCell)

0 commit comments

Comments
 (0)