2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-26 14:56:29 +00:00

ui/table: avoid duplicate table cell width calculation

This commit is contained in:
Michael Eischer 2024-06-07 21:45:40 +02:00
parent edd3e214c2
commit 7cd324fe26

View File

@ -141,16 +141,18 @@ func (t *Table) Write(w io.Writer) error {
columnWidths := make([]int, columns)
for i, desc := range t.columns {
for _, line := range strings.Split(desc, "\n") {
if columnWidths[i] < ui.TerminalDisplayWidth(line) {
columnWidths[i] = ui.TerminalDisplayWidth(line)
width := ui.TerminalDisplayWidth(line)
if columnWidths[i] < width {
columnWidths[i] = width
}
}
}
for _, line := range lines {
for i, content := range line {
for _, l := range strings.Split(content, "\n") {
if columnWidths[i] < ui.TerminalDisplayWidth(l) {
columnWidths[i] = ui.TerminalDisplayWidth(l)
width := ui.TerminalDisplayWidth(l)
if columnWidths[i] < width {
columnWidths[i] = width
}
}
}