@@ -80,6 +80,7 @@ func (t *Table) Render() string {
80
80
average := make ([]int , t .columnsCount )
81
81
widths := make ([]int , t .columnsCount )
82
82
count := make ([]int , t .columnsCount )
83
+ minimum := make ([]int , t .columnsCount )
83
84
for _ , row := range t .rows {
84
85
for x , cell := range row .cells {
85
86
l := cell .Len ()
@@ -98,6 +99,15 @@ func (t *Table) Render() string {
98
99
average [x ] = average [x ] / count [x ]
99
100
}
100
101
}
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
+
101
111
variance := make ([]int , t .columnsCount )
102
112
for _ , row := range t .rows {
103
113
for x , cell := range row .cells {
@@ -128,6 +138,9 @@ func (t *Table) Render() string {
128
138
selectedWidth = average [x ] + variance [x ]* 3
129
139
}
130
140
}
141
+ if selectedWidth < minimum [x ] {
142
+ selectedWidth = minimum [x ]
143
+ }
131
144
res += separator
132
145
res += cell .Pad (selectedWidth )
133
146
separator = " "
0 commit comments