Skip to content

Commit

Permalink
Avoid widening table columns that already fit
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Nov 20, 2019
1 parent 9fc80a1 commit 2022f8e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions utils/table_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,19 @@ func (t *TTYTablePrinter) FitColumns() {
numCols := len(t.colWidths)
delimWidth := 2
availWidth := t.maxWidth - t.colWidths[0] - ((numCols - 1) * delimWidth)
// TODO: avoid widening columns that already fit
// add extra space from columns that are already narrower than threshold
for col := 1; col < len(t.colWidths); col++ {
availColWidth := availWidth / (numCols - 1)
if extra := availColWidth - t.colWidths[col]; extra > 0 {
availWidth += extra
}
}
// TODO: support weighted instead of even redistribution
for col := 1; col < len(t.colWidths); col++ {
t.colWidths[col] = availWidth / (numCols - 1)
availColWidth := availWidth / (numCols - 1)
if t.colWidths[col] > availColWidth {
t.colWidths[col] = availColWidth
}
}
}

Expand Down

0 comments on commit 2022f8e

Please sign in to comment.