Unverified Commit e20cbc16 authored by Cristian Maglie's avatar Cristian Maglie Committed by GitHub

Fixed odd width of tables in command outputs (#1080)

Fix #1040
parent 441f8ebf
......@@ -80,6 +80,7 @@ func (t *Table) Render() string {
average := make([]int, t.columnsCount)
widths := make([]int, t.columnsCount)
count := make([]int, t.columnsCount)
minimum := make([]int, t.columnsCount)
for _, row := range t.rows {
for x, cell := range row.cells {
l := cell.Len()
......@@ -98,6 +99,15 @@ func (t *Table) Render() string {
average[x] = average[x] / count[x]
}
}
// table headers will dictate the absolute min width
for x := range minimum {
if t.hasHeader {
minimum[x] = t.rows[0].cells[x].Len()
} else {
minimum[x] = 1
}
}
variance := make([]int, t.columnsCount)
for _, row := range t.rows {
for x, cell := range row.cells {
......@@ -128,6 +138,9 @@ func (t *Table) Render() string {
selectedWidth = average[x] + variance[x]*3
}
}
if selectedWidth < minimum[x] {
selectedWidth = minimum[x]
}
res += separator
res += cell.Pad(selectedWidth)
separator = " "
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment