Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion table/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ func (t *Table) renderRowsHeader(out *strings.Builder) {

// Only add separator after header if there are data rows or footer rows.
// Otherwise, the bottom border is rendered directly.
if len(t.rows) > 0 || len(t.rowsFooter) > 0 {
if len(t.rows) > 0 || len(t.rowsFooter) > 0 || !t.style.Options.DoNotRenderSeparatorWhenEmpty {
hintSeparator.separatorType = separatorTypeHeaderBottom
t.renderRowSeparator(out, hintSeparator)
}
Expand Down
8 changes: 7 additions & 1 deletion table/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,14 @@ func TestTable_Render_EmptyWithHeaders(t *testing.T) {
tw := NewWriter()
tw.AppendHeader(Row{"ID", "DIALER", "ACCEPTOR", "STATIC COST", "SRC LATENCY", "DST LATENCY", "STATE", "STATUS", "FULL COST", "CONNECTIONS"})
tw.SetStyle(StyleRounded)
tw.Style().Options.DoNotRenderSeparatorWhenEmpty = false
compareOutput(t, tw.Render(), `
╭────┬────────┬──────────┬─────────────┬─────────────┬─────────────┬───────┬────────┬───────────┬─────────────╮
│ ID │ DIALER │ ACCEPTOR │ STATIC COST │ SRC LATENCY │ DST LATENCY │ STATE │ STATUS │ FULL COST │ CONNECTIONS │
├────┼────────┼──────────┼─────────────┼─────────────┼─────────────┼───────┼────────┼───────────┼─────────────┤
╰────┴────────┴──────────┴─────────────┴─────────────┴─────────────┴───────┴────────┴───────────┴─────────────╯`)

tw.Style().Options.DoNotRenderSeparatorWhenEmpty = true
compareOutput(t, tw.Render(), `
╭────┬────────┬──────────┬─────────────┬─────────────┬─────────────┬───────┬────────┬───────────┬─────────────╮
│ ID │ DIALER │ ACCEPTOR │ STATIC COST │ SRC LATENCY │ DST LATENCY │ STATE │ STATUS │ FULL COST │ CONNECTIONS │
Expand All @@ -1130,7 +1137,6 @@ func TestTable_Render_EmptyWithHeaders(t *testing.T) {
tw2.AppendHeader(testHeader)
tw2.AppendFooter(testFooter)
tw2.SetStyle(StyleRounded)

compareOutput(t, tw2.Render(), `
╭───┬────────────┬───────────┬────────╮
│ # │ FIRST NAME │ LAST NAME │ SALARY │
Expand Down
5 changes: 5 additions & 0 deletions table/style_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ type Options struct {
// or column separators.
DoNotColorBordersAndSeparators bool

// DoNotRenderSeparatorWhenEmpty disables rendering the separator row after
// headers when there are no data rows (for example when only headers and/or
// footers are present).
DoNotRenderSeparatorWhenEmpty bool

// DrawBorder enables or disables drawing the border around the Table.
// Example of a table where it is disabled:
// # │ FIRST NAME │ LAST NAME │ SALARY │
Expand Down