diff --git a/table/render.go b/table/render.go index 1a8bc04..a1b6cfe 100644 --- a/table/render.go +++ b/table/render.go @@ -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) } diff --git a/table/render_test.go b/table/render_test.go index 515ae2f..0531286 100644 --- a/table/render_test.go +++ b/table/render_test.go @@ -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 │ @@ -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 │ diff --git a/table/style_options.go b/table/style_options.go index d24e767..7e7a27c 100644 --- a/table/style_options.go +++ b/table/style_options.go @@ -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 │