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

column auto merge have minor wrong behavior #279

Closed
naughtyGitCat opened this issue Oct 23, 2023 · 3 comments · Fixed by #280
Closed

column auto merge have minor wrong behavior #279

naughtyGitCat opened this issue Oct 23, 2023 · 3 comments · Fixed by #280
Assignees
Labels
bug Something isn't working

Comments

@naughtyGitCat
Copy link

Describe the bug
wrong merge upper non-empty with downside empty content

To Reproduce

func RenderResources(serviceName string) table.Writer {
	resources, err := service.GetServiceResources(serviceName)
	if err != nil {
		log.Fatal(err)
	}
	t := table.NewWriter()
	t.SetOutputMirror(os.Stdout)
	rowConfigAutoMerge := table.RowConfig{AutoMerge: true}
	tableHeader := table.Row{"环境", "拓补", "地址", "物理IP", "备注"}
	t.AppendHeader(tableHeader)
	for _, resource := range resources {
		t.AppendRow(table.Row{resource.EntranceEnvironment, resource.DBTopologyType, generateUri(resource), resource.EntranceIP, generateComment(resource)},
			rowConfigAutoMerge)
	}
	var columnConfigs []table.ColumnConfig
	for i, _ := range tableHeader {
		columnConfigs = append(columnConfigs, table.ColumnConfig{
			Number:      i + 1,
			AutoMerge:   true,
			VAlign:      text.VAlignMiddle,
			Align:       text.AlignCenter,
			AlignHeader: text.AlignCenter,
		})
	}
	t.SetAutoIndex(true)
	t.SetColumnConfigs(columnConfigs)
	t.SetStyle(table.StyleLight)
	t.Style().Options.SeparateRows = true
	return t
}

Expected behavior
upper non-empty separate from downside empty content when column auto merge enabled

Screenshots
image

Software (please complete the following information):

  • OS: 2.6.32-573.el6.x86_64
  • GoLang Version go version go1.21.3 darwin/arm64

Additional context
Add any other context about the problem here.

@jedib0t jedib0t self-assigned this Oct 27, 2023
@jedib0t
Copy link
Owner

jedib0t commented Oct 27, 2023

I was able to reproduce the bug with this:

package main

import (
	"os"

	"github.com/jedib0t/go-pretty/v6/table"
	"github.com/jedib0t/go-pretty/v6/text"
)

func main() {
	t := table.NewWriter()
	t.SetOutputMirror(os.Stdout)
	rowConfigAutoMerge := table.RowConfig{AutoMerge: true}
	tableHeader := table.Row{"Col #1", "Col #2", "Col #3", "Col #4", "Col #5"}
	t.AppendHeader(tableHeader)
	t.AppendRow(table.Row{"Product", "Standalone", "foo bar", "1.1.1.1", ""}, rowConfigAutoMerge)
	t.AppendRow(table.Row{"Test", "Standalone", "bar baz", "2.2.2.2", ""}, rowConfigAutoMerge)
	t.AppendRow(table.Row{"Product", "RedisCluster", "foo baz", "", "Cluster #1"}, rowConfigAutoMerge)
	t.AppendRow(table.Row{"Product", "RedisCluster", "bar baz", "", "Cluster #2"}, rowConfigAutoMerge)

	var columnConfigs []table.ColumnConfig
	for i, _ := range tableHeader {
		columnConfigs = append(columnConfigs, table.ColumnConfig{
			Number:      i + 1,
			AutoMerge:   true,
			VAlign:      text.VAlignMiddle,
			Align:       text.AlignCenter,
			AlignHeader: text.AlignCenter,
		})
	}
	t.SetAutoIndex(true)
	t.SetColumnConfigs(columnConfigs)
	t.SetStyle(table.StyleLight)
	t.Style().Options.SeparateRows = true
	t.Render()
}

Output:

┌───┬─────────┬──────────────┬─────────┬─────────┬────────────┐
│   │  COL #1 │    COL #2    │  COL #3 │  COL #4 │   COL #5   │
├───┼─────────┼──────────────┼─────────┼─────────┼────────────┤
│ 1 │ Product │  Standalone  │ foo bar │ 1.1.1.1 │            │
├───┼─────────┤              ├─────────┼─────────┤            │
│ 2 │   Test  │              │ bar baz │ 2.2.2.2 │            │
├───┼─────────┼──────────────┼─────────┤         ├────────────┤
│ 3 │ Product │ RedisCluster │ foo baz │         │ Cluster #1 │
├───┤         │              ├─────────┤         ├────────────┤
│ 4 │         │              │ bar baz │         │ Cluster #2 │
└───┴─────────┴──────────────┴─────────┴─────────┴────────────┘

Will work on a solution for this soon.

@jedib0t
Copy link
Owner

jedib0t commented Oct 27, 2023

@naughtyGitCat
Copy link
Author

thanks, it fixed

@jedib0t jedib0t added the bug Something isn't working label Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants