From abb14aeec12f6ae92fd85f8eb3a0f9332800a556 Mon Sep 17 00:00:00 2001 From: P R <25353498+BigUstad@users.noreply.github.com> Date: Mon, 12 Oct 2020 11:32:43 -0700 Subject: [PATCH] Header row seperator for console Table (#10651) --- pkg/console/console.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/console/console.go b/pkg/console/console.go index 3d5d3d1d3..c2acab1fa 100644 --- a/pkg/console/console.go +++ b/pkg/console/console.go @@ -353,13 +353,16 @@ type Table struct { // Left margin width for table TableIndentWidth int + + // Flag to print separator under heading. Row 0 is considered heading + HeaderRowSeparator bool } // NewTable - create a new Table instance. Takes per-row colors and // per-column right-align flags and table indentation width (i.e. left // margin width) func NewTable(rowColors []*color.Color, alignRight []bool, indentWidth int) *Table { - return &Table{rowColors, alignRight, indentWidth} + return &Table{rowColors, alignRight, indentWidth, false} } // DisplayTable - prints the table @@ -410,6 +413,11 @@ func (t *Table) DisplayTable(rows [][]string) error { // Print the table with colors for r, row := range paddedText { + if t.HeaderRowSeparator && r == 1 { + // Draw table header-row border + border = fmt.Sprintf("%s├%s┤", indentText, strings.Join(segments, "┼")) + fmt.Println(border) + } fmt.Print(indentText + "│ ") for c, text := range row { t.RowColors[r].Print(text)