@@ -20,7 +20,7 @@ import (
2020// │ │ │ TOTAL │ 10000 │ │
2121// └─────┴────────────┴───────────┴────────┴─────────────────────────────┘
2222func (t * Table ) Render () string {
23- t .initForRender ()
23+ t .initForRender (renderModeDefault )
2424
2525 var out strings.Builder
2626 if t .numColumns > 0 {
@@ -50,6 +50,7 @@ func (t *Table) Render() string {
5050 return t .render (& out )
5151}
5252
53+ //gocyclo:ignore
5354func (t * Table ) renderColumn (out * strings.Builder , row rowStr , colIdx int , maxColumnLength int , hint renderHint ) int {
5455 numColumnsRendered := 1
5556
@@ -93,11 +94,10 @@ func (t *Table) renderColumn(out *strings.Builder, row rowStr, colIdx int, maxCo
9394 numColumnsRendered ++
9495 }
9596 }
96- colStr = align .Apply (colStr , maxColumnLength )
9797
9898 // pad both sides of the column
9999 if ! hint .isSeparatorRow || (hint .isSeparatorRow && mergeVertically ) {
100- colStr = t .style .Box .PaddingLeft + colStr + t .style .Box .PaddingRight
100+ colStr = t .style .Box .PaddingLeft + align . Apply ( colStr , maxColumnLength ) + t .style .Box .PaddingRight
101101 }
102102
103103 t .renderColumnColorized (out , colIdx , colStr , hint )
@@ -112,9 +112,9 @@ func (t *Table) renderColumnAutoIndex(out *strings.Builder, hint renderHint) {
112112 if hint .isSeparatorRow {
113113 numChars := t .autoIndexVIndexMaxLength + utf8 .RuneCountInString (t .style .Box .PaddingLeft ) +
114114 utf8 .RuneCountInString (t .style .Box .PaddingRight )
115- chars := t .style .Box .MiddleHorizontal
115+ chars := t .style .Box .middleHorizontal ( hint . separatorType )
116116 if hint .isAutoIndexColumn && hint .isHeaderOrFooterSeparator () {
117- chars = text .RepeatAndTrim (" " , len (t . style . Box . MiddleHorizontal ))
117+ chars = text .RepeatAndTrim (" " , len (chars ))
118118 }
119119 outAutoIndex .WriteString (text .RepeatAndTrim (chars , numChars ))
120120 } else {
@@ -304,8 +304,10 @@ func (t *Table) renderRowSeparator(out *strings.Builder, hint renderHint) {
304304 } else if hint .isFooterRow && ! t .style .Options .SeparateFooter {
305305 return
306306 }
307+
307308 hint .isSeparatorRow = true
308- t .renderLine (out , t .rowSeparator , hint )
309+ separator := t .rowSeparatorStrings [hint .separatorType ]
310+ t .renderLine (out , t .rowSeparators [separator ], hint )
309311}
310312
311313func (t * Table ) renderRows (out * strings.Builder , rows []rowStr , hint renderHint ) {
@@ -316,8 +318,17 @@ func (t *Table) renderRows(out *strings.Builder, rows []rowStr, hint renderHint)
316318 t .renderRow (out , row , hint )
317319
318320 if t .shouldSeparateRows (rowIdx , len (rows )) {
319- hint .isFirstRow = false
320- t .renderRowSeparator (out , hint )
321+ hintSep := hint
322+ hintSep .isFirstRow = false
323+ hintSep .isSeparatorRow = true
324+ if hintSep .isHeaderRow {
325+ hintSep .separatorType = separatorTypeHeaderMiddle
326+ } else if hintSep .isFooterRow {
327+ hintSep .separatorType = separatorTypeFooterMiddle
328+ } else {
329+ hintSep .separatorType = separatorTypeRowMiddle
330+ }
331+ t .renderRowSeparator (out , hintSep )
321332 }
322333 }
323334}
@@ -328,28 +339,41 @@ func (t *Table) renderRowsBorderBottom(out *strings.Builder) {
328339 isBorderBottom : true ,
329340 isFooterRow : true ,
330341 rowNumber : len (t .rowsFooter ),
342+ separatorType : separatorTypeFooterBottom ,
331343 })
332344 } else {
333345 t .renderRowSeparator (out , renderHint {
334346 isBorderBottom : true ,
335347 isFooterRow : false ,
336348 rowNumber : len (t .rows ),
349+ separatorType : separatorTypeRowBottom ,
337350 })
338351 }
339352}
340353
341354func (t * Table ) renderRowsBorderTop (out * strings.Builder ) {
355+ st := separatorTypeHeaderTop
356+ if t .title != "" {
357+ st = separatorTypeTitleBottom
358+ } else if len (t .rowsHeader ) == 0 && ! t .autoIndex {
359+ st = separatorTypeRowTop
360+ }
361+
342362 if len (t .rowsHeader ) > 0 || t .autoIndex {
343363 t .renderRowSeparator (out , renderHint {
344- isBorderTop : true ,
345- isHeaderRow : true ,
346- rowNumber : 0 ,
364+ isBorderTop : true ,
365+ isHeaderRow : true ,
366+ isSeparatorRow : true ,
367+ rowNumber : 0 ,
368+ separatorType : st ,
347369 })
348370 } else {
349371 t .renderRowSeparator (out , renderHint {
350- isBorderTop : true ,
351- isHeaderRow : false ,
352- rowNumber : 0 ,
372+ isBorderTop : true ,
373+ isHeaderRow : false ,
374+ isSeparatorRow : true ,
375+ rowNumber : 0 ,
376+ separatorType : st ,
353377 })
354378 }
355379}
@@ -360,14 +384,20 @@ func (t *Table) renderRowsFooter(out *strings.Builder) {
360384 isFooterRow : true ,
361385 isFirstRow : true ,
362386 isSeparatorRow : true ,
387+ separatorType : separatorTypeFooterTop ,
363388 })
364389 t .renderRows (out , t .rowsFooter , renderHint {isFooterRow : true })
365390 }
366391}
367392
368393func (t * Table ) renderRowsHeader (out * strings.Builder ) {
369394 if len (t .rowsHeader ) > 0 || t .autoIndex {
370- hintSeparator := renderHint {isHeaderRow : true , isLastRow : true , isSeparatorRow : true }
395+ hintSeparator := renderHint {
396+ isHeaderRow : true ,
397+ isLastRow : true ,
398+ isSeparatorRow : true ,
399+ separatorType : separatorTypeHeaderMiddle ,
400+ }
371401
372402 if len (t .rowsHeader ) > 0 {
373403 t .renderRows (out , t .rowsHeader , renderHint {isHeaderRow : true })
@@ -376,6 +406,8 @@ func (t *Table) renderRowsHeader(out *strings.Builder) {
376406 t .renderRow (out , t .getAutoIndexColumnIDs (), renderHint {isAutoIndexRow : true , isHeaderRow : true })
377407 hintSeparator .rowNumber = 1
378408 }
409+
410+ hintSeparator .separatorType = separatorTypeHeaderBottom
379411 t .renderRowSeparator (out , hintSeparator )
380412 }
381413}
@@ -393,8 +425,9 @@ func (t *Table) renderTitle(out *strings.Builder) {
393425 }
394426 if t .style .Options .DrawBorder {
395427 lenBorder := rowLength - text .StringWidthWithoutEscSequences (t .style .Box .TopLeft + t .style .Box .TopRight )
428+ middleHorizontal := t .style .Box .middleHorizontal (separatorTypeTitleTop )
396429 out .WriteString (colorsBorder .Sprint (t .style .Box .TopLeft ))
397- out .WriteString (colorsBorder .Sprint (text .RepeatAndTrim (t . style . Box . MiddleHorizontal , lenBorder )))
430+ out .WriteString (colorsBorder .Sprint (text .RepeatAndTrim (middleHorizontal , lenBorder )))
398431 out .WriteString (colorsBorder .Sprint (t .style .Box .TopRight ))
399432 }
400433
0 commit comments