diff --git a/table/render.go b/table/render.go index d58f189..ca4bc99 100644 --- a/table/render.go +++ b/table/render.go @@ -365,10 +365,7 @@ func (t *Table) renderRowsHeader(out *strings.Builder) { func (t *Table) renderTitle(out *strings.Builder) { if t.title != "" { colors := t.style.Title.Colors - colorsBorder := colors - if t.style.Options.DoNotColorBordersAndSeparators { - colorsBorder = nil - } + colorsBorder := t.getBorderColors(renderHint{isTitleRow: true}) rowLength := t.maxRowLength if t.allowedRowLength != 0 && t.allowedRowLength < rowLength { rowLength = t.allowedRowLength diff --git a/table/render_hint.go b/table/render_hint.go index d32504b..e46cdc8 100644 --- a/table/render_hint.go +++ b/table/render_hint.go @@ -12,6 +12,7 @@ type renderHint struct { isLastLineOfRow bool // last-line of the current row? isLastRow bool // last-row of header/footer/regular-rows? isSeparatorRow bool // separator row? + isTitleRow bool // title row? rowLineNumber int // the line number for a multi-line row rowNumber int // the row number/index } diff --git a/table/render_test.go b/table/render_test.go index 81f104c..abeaa79 100644 --- a/table/render_test.go +++ b/table/render_test.go @@ -986,6 +986,21 @@ func TestTable_Render_BorderAndSeparators_Colored(t *testing.T) { "\x1b[31m│\x1b[0m \x1b[33m│\x1b[0m \x1b[33m│\x1b[0m TOTAL \x1b[33m│\x1b[0m 10000 \x1b[33m│\x1b[0m \x1b[31m│\x1b[0m\n"+ "\x1b[31m└\x1b[0m\x1b[31m─────\x1b[0m\x1b[31m┴\x1b[0m\x1b[31m────────────\x1b[0m\x1b[31m┴\x1b[0m\x1b[31m───────────\x1b[0m\x1b[31m┴\x1b[0m\x1b[31m────────\x1b[0m\x1b[31m┴\x1b[0m\x1b[31m─────────────────────────────\x1b[0m\x1b[31m┘\x1b[0m", ) + + table.SetTitle("Game of Thrones") + compareOutputColored(t, table.Render(), ""+ + "\x1b[31m┌\x1b[0m\x1b[31m─────────────────────────────────────────────────────────────────────\x1b[0m\x1b[31m┐\x1b[0m\n"+ + "\x1b[31m│\x1b[0m Game of Thrones \x1b[31m│\x1b[0m\n"+ + "\x1b[31m├\x1b[0m\x1b[31m─────\x1b[0m\x1b[31m┬\x1b[0m\x1b[31m────────────\x1b[0m\x1b[31m┬\x1b[0m\x1b[31m───────────\x1b[0m\x1b[31m┬\x1b[0m\x1b[31m────────\x1b[0m\x1b[31m┬\x1b[0m\x1b[31m─────────────────────────────\x1b[0m\x1b[31m┤\x1b[0m\n"+ + "\x1b[31m│\x1b[0m # \x1b[33m│\x1b[0m FIRST NAME \x1b[33m│\x1b[0m LAST NAME \x1b[33m│\x1b[0m SALARY \x1b[33m│\x1b[0m \x1b[31m│\x1b[0m\n"+ + "\x1b[31m├\x1b[0m\x1b[33m─────\x1b[0m\x1b[33m┼\x1b[0m\x1b[33m────────────\x1b[0m\x1b[33m┼\x1b[0m\x1b[33m───────────\x1b[0m\x1b[33m┼\x1b[0m\x1b[33m────────\x1b[0m\x1b[33m┼\x1b[0m\x1b[33m─────────────────────────────\x1b[0m\x1b[31m┤\x1b[0m\n"+ + "\x1b[31m│\x1b[0m 1 \x1b[33m│\x1b[0m Arya \x1b[33m│\x1b[0m Stark \x1b[33m│\x1b[0m 3000 \x1b[33m│\x1b[0m \x1b[31m│\x1b[0m\n"+ + "\x1b[31m│\x1b[0m 20 \x1b[33m│\x1b[0m Jon \x1b[33m│\x1b[0m Snow \x1b[33m│\x1b[0m 2000 \x1b[33m│\x1b[0m You know nothing, Jon Snow! \x1b[31m│\x1b[0m\n"+ + "\x1b[31m│\x1b[0m 300 \x1b[33m│\x1b[0m Tyrion \x1b[33m│\x1b[0m Lannister \x1b[33m│\x1b[0m 5000 \x1b[33m│\x1b[0m \x1b[31m│\x1b[0m\n"+ + "\x1b[31m├\x1b[0m\x1b[33m─────\x1b[0m\x1b[33m┼\x1b[0m\x1b[33m────────────\x1b[0m\x1b[33m┼\x1b[0m\x1b[33m───────────\x1b[0m\x1b[33m┼\x1b[0m\x1b[33m────────\x1b[0m\x1b[33m┼\x1b[0m\x1b[33m─────────────────────────────\x1b[0m\x1b[31m┤\x1b[0m\n"+ + "\x1b[31m│\x1b[0m \x1b[33m│\x1b[0m \x1b[33m│\x1b[0m TOTAL \x1b[33m│\x1b[0m 10000 \x1b[33m│\x1b[0m \x1b[31m│\x1b[0m\n"+ + "\x1b[31m└\x1b[0m\x1b[31m─────\x1b[0m\x1b[31m┴\x1b[0m\x1b[31m────────────\x1b[0m\x1b[31m┴\x1b[0m\x1b[31m───────────\x1b[0m\x1b[31m┴\x1b[0m\x1b[31m────────\x1b[0m\x1b[31m┴\x1b[0m\x1b[31m─────────────────────────────\x1b[0m\x1b[31m┘\x1b[0m", + ) } func TestTable_Render_Colored(t *testing.T) { diff --git a/table/table.go b/table/table.go index 7b19dcc..684974c 100644 --- a/table/table.go +++ b/table/table.go @@ -330,6 +330,8 @@ func (t *Table) getBorderColors(hint renderHint) text.Colors { return nil } else if t.style.Color.Border != nil { return t.style.Color.Border + } else if hint.isTitleRow { + return t.style.Title.Colors } else if hint.isHeaderRow { return t.style.Color.Header } else if hint.isFooterRow {