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 separator is misaligned when header is empty #186

Open
cgrinds opened this issue Jul 7, 2021 · 1 comment
Open

Column separator is misaligned when header is empty #186

cgrinds opened this issue Jul 7, 2021 · 1 comment

Comments

@cgrinds
Copy link

cgrinds commented Jul 7, 2021

package main

import (
	"github.com/olekukonko/tablewriter"
	"os"
	"strings"
)

func main() {
	lines := []string{
		"Lorem ipsum dolor",
		"quis commodo odio",
	}
	linesWithNewline := strings.Join(lines, "\n")
	data := [][]string{
		{" ", "b", "c"},
		{" ", "e", linesWithNewline},
	}
	table := tablewriter.NewWriter(os.Stdout)
	table.SetHeader([]string{"", "", "col2"})
	table.SetAlignment(tablewriter.ALIGN_LEFT)
	table.SetBorder(false)
	table.SetColMinWidth(2, 15)
	table.SetAutoWrapText(false)
	table.SetRowLine(true)
	table.AppendBulk(data)
	table.Render()
}

Results in

    |   |       COL2         
----+---+--------------------
    | b | c                  
----+---+--------------------
    | e | Lorem ipsum dolor  
     |    | quis commodo odio  
----+---+--------------------

Instead of the expected

    |   |       COL2         
----+---+--------------------
    | b | c                  
----+---+--------------------
    | e | Lorem ipsum dolor  
    |   | quis commodo odio  
----+---+--------------------
@cgrinds
Copy link
Author

cgrinds commented Jul 7, 2021

Patch #187

Workaround: Ensure your headers are at least two spaces instead of empty. In the example above, replace

	table.SetHeader([]string{"", "", "col2"})

with

	table.SetHeader([]string{"  ", "  ", "col2"})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant