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

Bug: a size of columns with merged cells is not calculated correctly #350

Open
fpawel opened this issue Jan 14, 2025 · 1 comment
Open
Labels
bug Something isn't working

Comments

@fpawel
Copy link

fpawel commented Jan 14, 2025

Hello! Thank you for your work on this useful package!

Describe the bug
When calculating the size of columns, merging table cells is not taken into account

To Reproduce
Go Playground.

package main

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

func main() {
	tw := table.NewWriter()
	tw.AppendHeader(table.Row{"ID", "Date", "From", "To", "Subject", "Size"})
	tw.AppendRow(table.Row{
		4,
		"2024-11-18T09:30:54Z",
		"Shaylee McDermott",
		"",
		"Tote bag photo booth lumbersexual normcore synth meh lumbersexual disrupt craft beer aesthetic.",
		"4.2 MB",
	})
	tw.AppendRow(table.Row{
		4,
		"2024-11-18T09:30:54Z",
		"Anahi Braun ",
		"",
		"Mumblecore salvia mumblecore austin tofu viral asymmetrical small batch distillery you probably haven't heard of them.",
		"4.2 MB",
	})
	tw.AppendRow(table.Row{
		4,
		"2024-11-18T09:30:54Z",
		"Brando Barton",
		"",
		"Before they sold out jean shorts chartreuse neutra fixie flexitarian goth art party small batch sriracha.",
		"4.2 MB",
	})
	const ID = "AAMkADdiOWM1OTBkLTBhZjEtNGFiNS1hOGYwLTY2YWFmOGQyNTMxNgBGAAAAAADBju3TxrP2SZIsqjNb8hmoBwA9J0gY/4/nQ73Lmp9F9NoaAABlJ281AAA9J0gY/4/nQ73Lmp9F9NoaAABlJ6bLAAA="
	tw.AppendRow(
		table.Row{ID, ID, ID, ID, ID, ID},
		table.RowConfig{
			AutoMerge:      true,
			AutoMergeAlign: text.AlignLeft,
		})
	fmt.Println(tw.Render())
}

Expected behavior

	+----+----------------------+-------------------+----+------------------------------------------------------------------------------------------------------------------------+--------+
	| ID | DATE                 | FROM              | TO | SUBJECT                                                                                                                | SIZE   |
	+----+----------------------+-------------------+----+------------------------------------------------------------------------------------------------------------------------+--------+
	|  4 | 2024-11-18T09:30:54Z | Shaylee McDermott |    | Tote bag photo booth lumbersexual normcore synth meh lumbersexual disrupt craft beer aesthetic.                        | 4.2 MB |
	|  4 | 2024-11-18T09:30:54Z | Anahi Braun       |    | Mumblecore salvia mumblecore austin tofu viral asymmetrical small batch distillery you probably haven't heard of them. | 4.2 MB |
	|  4 | 2024-11-18T09:30:54Z | Brando Barton     |    | Before they sold out jean shorts chartreuse neutra fixie flexitarian goth art party small batch sriracha.              | 4.2 MB |
	|  AAMkADdiOWM1OTBkLTBhZjEtNGFiNS1hOGYwLTY2YWFmOGQyNTMxNgBGAAAAAADBju3TxrP2SZIsqjNb8hmoBwA9J0gY/4/nQ73Lmp9F9NoaAABlJ281AAA9J0gY/4/nQ73Lmp9F9NoaAABlJ6bLAAA=                            |
	+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
	

Actual behavior

	+----------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
	| ID                                                                                                                                                       | DATE                                                                                                                                                     | FROM                                                                                                                                                     | TO                                                                                                                                                       | SUBJECT                                                                                                                                                  | SIZE                                                                                                                                                     |
	+----------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
	| 4                                                                                                                                                        | 2024-11-18T09:30:54Z                                                                                                                                     | Shaylee McDermott                                                                                                                                        |                                                                                                                                                          | Tote bag photo booth lumbersexual normcore synth meh lumbersexual disrupt craft beer aesthetic.                                                          | 4.2 MB                                                                                                                                                   |
	| 4                                                                                                                                                        | 2024-11-18T09:30:54Z                                                                                                                                     | Anahi Braun                                                                                                                                              |                                                                                                                                                          | Mumblecore salvia mumblecore austin tofu viral asymmetrical small batch distillery you probably haven't heard of them.                                   | 4.2 MB                                                                                                                                                   |
	| 4                                                                                                                                                        | 2024-11-18T09:30:54Z                                                                                                                                     | Brando Barton                                                                                                                                            |                                                                                                                                                          | Before they sold out jean shorts chartreuse neutra fixie flexitarian goth art party small batch sriracha.                                                | 4.2 MB                                                                                                                                                   |
	| AAMkADdiOWM1OTBkLTBhZjEtNGFiNS1hOGYwLTY2YWFmOGQyNTMxNgBGAAAAAADBju3TxrP2SZIsqjNb8hmoBwA9J0gY/4/nQ73Lmp9F9NoaAABlJ281AAA9J0gY/4/nQ73Lmp9F9NoaAABlJ6bLAAA=                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
	+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

	

Software:

  • GoLang Version 1.23
@fpawel fpawel changed the title A size of columns with merged cells is not calculated correctly Bug: a size of columns with merged cells is not calculated correctly Jan 14, 2025
@jedib0t jedib0t added the bug Something isn't working label Jan 14, 2025
@jedib0t
Copy link
Owner

jedib0t commented Jan 14, 2025

I thought this use-case was covered by the library already (see unit-test here). Looks like it wasn't. Will try to address this as soon as I can.

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

No branches or pull requests

2 participants