go-pretty
go-pretty copied to clipboard
Vertical AutoMerge keeps unnecessary whitespace when a merged row value is wrapped by WidthMax
Describe the bug
When using AutoMerge
and WidthMax
together on a ColumnConfig
, unnecessary whitespace is left in rows where the column value is wrapped and has been merged.
To Reproduce
import (
"fmt"
"testing"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/jedib0t/go-pretty/v6/text"
)
func TestWrapWithVerticalMerge(t *testing.T) {
tbl := table.NewWriter()
tbl.SetColumnConfigs([]table.ColumnConfig{
{
Name: "C1",
AutoMerge: true,
WidthMax: 10,
WidthMaxEnforcer: text.WrapSoft,
},
{
Name: "C2",
},
})
tbl.AppendHeader(table.Row{
"C1",
"C2",
})
tbl.AppendRows([]table.Row{
{
"very long row value that wraps",
"x",
},
{
"very long row value that wraps",
"y",
},
})
tblstring := tbl.Render()
fmt.Println(tblstring)
}
Output:
=== RUN TestWrapWithVerticalMerge
+------------+----+
| C1 | C2 |
+------------+----+
| very long | x |
| row value | |
| that wraps | |
| | y |
| | |
| | |
+------------+----+
Expected behavior I would expect the output to look more like the following, though I'm open to changes on the specifics. The main point is that, similar to https://github.com/jedib0t/go-pretty/issues/226, unnecessary space is left because it seems like the merging thinks the original row value (pre merge) is still present.
+------------+----+
| C1 | C2 |
+------------+----+
| very long | x |
| row value | y |
| that wraps | |
+------------+----+
Software (please complete the following information):
My go.mod
has:
go 1.16
require (
github.com/jedib0t/go-pretty/v6 v6.4.6
)
- OS: Linux
- GoLang Version:
go version go1.20.1 linux/amd64