Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e20cbc1

Browse files
authored
Fixed odd width of tables in command outputs (#1080)
Fix #1040
1 parent 441f8eb commit e20cbc1

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

‎table/table.go‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /