@@ -80,6 +80,7 @@ func (t *Table) Render() string {
8080 average := make ([]int , t .columnsCount )
8181 widths := make ([]int , t .columnsCount )
8282 count := make ([]int , t .columnsCount )
83+ minimum := make ([]int , t .columnsCount )
8384 for _ , row := range t .rows {
8485 for x , cell := range row .cells {
8586 l := cell .Len ()
@@ -98,6 +99,15 @@ func (t *Table) Render() string {
9899 average [x ] = average [x ] / count [x ]
99100 }
100101 }
102+ // table headers will dictate the absolute min width
103+ for x := range minimum {
104+ if t .hasHeader {
105+ minimum [x ] = t .rows [0 ].cells [x ].Len ()
106+ } else {
107+ minimum [x ] = 1
108+ }
109+ }
110+
101111 variance := make ([]int , t .columnsCount )
102112 for _ , row := range t .rows {
103113 for x , cell := range row .cells {
@@ -128,6 +138,9 @@ func (t *Table) Render() string {
128138 selectedWidth = average [x ] + variance [x ]* 3
129139 }
130140 }
141+ if selectedWidth < minimum [x ] {
142+ selectedWidth = minimum [x ]
143+ }
131144 res += separator
132145 res += cell .Pad (selectedWidth )
133146 separator = " "
0 commit comments