The Wayback Machine - https://web.archive.org/web/20210911024148/https://github.com/arduino/arduino-cli/pull/1080/files
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed odd column width of tables in command outputs #1080

Merged
merged 1 commit into from Dec 15, 2020
Merged
Changes from all commits
Commits
File filter
Filter file types
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.

Always

Just for now

@@ -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 = " "