From 51a32221ef68772f30e4bde97a94d626ac01caf5 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 1 Sep 2023 17:21:59 +0200 Subject: [PATCH 1/2] Simplified table.Render method --- table/table.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/table/table.go b/table/table.go index 278077f623f..ee94dec2dcd 100644 --- a/table/table.go +++ b/table/table.go @@ -127,7 +127,6 @@ func (t *Table) Render() string { res := "" for _, row := range t.rows { - separator := "" for x, cell := range row.cells { selectedWidth := widths[x] if x < len(t.columnsWidthMode) { @@ -141,9 +140,10 @@ func (t *Table) Render() string { if selectedWidth < minimum[x] { selectedWidth = minimum[x] } - res += separator + if x > 0 { + line += " " + } res += cell.Pad(selectedWidth) - separator = " " } res += "\n" } From 561416857aad21932a38d7f0729a07c50d9f067c Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 1 Sep 2023 17:22:24 +0200 Subject: [PATCH 2/2] Removed right padding from tables --- table/table.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/table/table.go b/table/table.go index ee94dec2dcd..7de2d46343a 100644 --- a/table/table.go +++ b/table/table.go @@ -18,6 +18,7 @@ package table import ( "fmt" "math" + "strings" ) // ColumnWidthMode is used to configure columns type @@ -127,6 +128,7 @@ func (t *Table) Render() string { res := "" for _, row := range t.rows { + line := "" for x, cell := range row.cells { selectedWidth := widths[x] if x < len(t.columnsWidthMode) { @@ -143,9 +145,10 @@ func (t *Table) Render() string { if x > 0 { line += " " } - res += cell.Pad(selectedWidth) + line += cell.Pad(selectedWidth) } - res += "\n" + + res += strings.TrimRight(line, " ") + "\n" } return res }