Skip to content

[v1.0.5-pre] How to disable headers? #255

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

Closed
zx8 opened this issue May 15, 2025 · 6 comments
Closed

[v1.0.5-pre] How to disable headers? #255

zx8 opened this issue May 15, 2025 · 6 comments
Labels
Feature Request Usage & Discussion Practically understand how to customize & usage
Milestone

Comments

@zx8
Copy link

zx8 commented May 15, 2025

I'm trying to match my v0.0.5 configuration using the latest commit 88e7330 so I can prove feedback before the release. I've managed to discover the majority of settings, but the two I can't seem to find the equivalents of are:

table.SetHeaderLine(false)
table.SetTablePadding("  ")

Also, another suggestion (to save me raising a separate issue) since tw.BorderNone already exists as a convenient helper, could you also add:

tw.LinesNone := tw.Lines{
  ShowTop:        tw.Off,
  ShowBottom:     tw.Off,
  ShowHeaderLine: tw.Off,
  ShowFooterLine: tw.Off,
}

and

tw.SeparatorsNone := tw.Separators{
  ShowHeader:     tw.Off,
  ShowFooter:     tw.Off,
  BetweenRows:    tw.Off,
  BetweenColumns: tw.Off,
}
@olekukonko
Copy link
Owner

Hi @zx8 ,

Will help you add tablewriter.WithPadding to help you simplify global padding forever for fine grain padding you may want to see

func TestTableWithCustomPadding(t *testing.T) {
data := [][]string{
{"Regular", "regular line", "1"},
{"Thick", "particularly thick line", "2"},
{"Double", "double line", "3"},
}
c := tablewriter.Config{
Header: tw.CellConfig{
Formatting: tw.CellFormatting{
Alignment: tw.AlignCenter,
AutoFormat: true,
},
Padding: tw.CellPadding{
Global: tw.Padding{Left: " ", Right: " ", Top: "^", Bottom: "^"},
},
},
Row: tw.CellConfig{
Formatting: tw.CellFormatting{
Alignment: tw.AlignCenter,
},
Padding: tw.CellPadding{
Global: tw.Padding{Left: "L", Right: "R", Top: "T", Bottom: "B"},
},
},
Footer: tw.CellConfig{
Formatting: tw.CellFormatting{
Alignment: tw.AlignCenter,
AutoFormat: true,
},
Padding: tw.CellPadding{
Global: tw.Padding{Left: "*", Right: "*", Top: "", Bottom: ""},
},
},
}
var buf bytes.Buffer
table := tablewriter.NewTable(&buf, tablewriter.WithConfig(c))
table.Header([]string{"Name", "Age", "City"})
table.Bulk(data)
table.Render()
expected := `
┌─────────┬─────────────────────────┬──────┐
│ ^^^^^^^ │ ^^^^^^^^^^^^^^^^^^^^^^^ │ ^^^^ │
│ NAME │ AGE │ CITY │
│ ^^^^^^^ │ ^^^^^^^^^^^^^^^^^^^^^^^ │ ^^^^ │
├─────────┼─────────────────────────┼──────┤
│LTTTTTTTR│LTTTTTTTTTTTTTTTTTTTTTTTR│LTTTTR│
│LRegularR│LLLLLLregular lineRRRRRRR│LL1RRR│
│LBBBBBBBR│LBBBBBBBBBBBBBBBBBBBBBBBR│LBBBBR│

Hope this helps ?

@olekukonko
Copy link
Owner

package main

import (
	"fmt"
	"github.com/olekukonko/tablewriter"
	"github.com/olekukonko/tablewriter/tw"
	"os"
)

type Age int

func (a Age) String() string {
	return fmt.Sprintf("%d yrs", a)
}

func main() {
	data := [][]any{
		{"Name", "Age", "City"},
		{"Alice", Age(25), "New York"},
		{"Bob", Age(30), "Boston"},
	}

	table := tablewriter.NewTable(
		os.Stdout,
		tablewriter.WithPadding(tw.Padding{
			Left:   "*",
			Right:  "#",
			Top:    "",
			Bottom: "",
		}),
	)

	table.Header(data[0])
	table.Bulk(data[1:])
	table.Render()
}
┌───────┬────────┬──────────┐
│*NAME##│**AGE###│***CITY###│
├───────┼────────┼──────────┤
│*Alice#│*25 yrs#│*New York#│
│*Bob###│*30 yrs#│*Boston###│
└───────┴────────┴──────────┘

@olekukonko olekukonko added the Usage & Discussion Practically understand how to customize & usage label May 15, 2025
@zx8
Copy link
Author

zx8 commented May 15, 2025

Sorry, I wanted to disable the header entirely as well, if that's possible? So rather than:

┌───────┬────────┬──────────┐
│*NAME##│**AGE###│***CITY###│
├───────┼────────┼──────────┤
│*Alice#│*25 yrs#│*New York#│
│*Bob###│*30 yrs#│*Boston###│
└───────┴────────┴──────────┘

I wanted:

┌───────┬────────┬──────────┐
│*Alice#│*25 yrs#│*New York#│
│*Bob###│*30 yrs#│*Boston###│
└───────┴────────┴──────────┘

@olekukonko
Copy link
Owner

just comment out the header

package main

import (
	"fmt"
	"github.com/olekukonko/tablewriter"
	"github.com/olekukonko/tablewriter/tw"
	"os"
)

type Age int

func (a Age) String() string {
	return fmt.Sprintf("%d yrs", a)
}

func main() {
	data := [][]any{
		{"Name", "Age", "City"},
		{"Alice", Age(25), "New York"},
		{"Bob", Age(30), "Boston"},
	}

	table := tablewriter.NewTable(
		os.Stdout,
		tablewriter.WithPadding(tw.Padding{
			Left:   "*",
			Right:  "#",
			Top:    "",
			Bottom: "",
		}),
	)

	/// table.Header(data[0])
	table.Bulk(data[1:])
	table.Render()
}
┌───────┬────────┬──────────┐
│*Alice#│*25 yrs#│*New York#│
│*Bob###│*30 yrs#│*Boston###│
└───────┴────────┴──────────┘

However, if I understand your use case correctly, I may be able to add a configuration ... help me out.

@zx8
Copy link
Author

zx8 commented May 16, 2025

Sure, I am loading a CSV like:

r := csv.NewReader(os.Stdin)
table, err := tablewriter.NewCSVReader(os.Stdout, r, true)
if err != nil {
    return err
}
table.Render()

The input data has a header, but I want to skip it when rendering the table.

@olekukonko olekukonko modified the milestones: v1.0.5, v1.0.6 May 16, 2025
@olekukonko
Copy link
Owner

Understandable will add support for this so you can do

package main

import (
	"encoding/csv"
	"github.com/olekukonko/ll"
	"github.com/olekukonko/tablewriter"
	"github.com/olekukonko/tablewriter/tw"
	"os"
	"strings"
)

const csvTestData = `Name,Department,Salary
Alice,Engineering,120000
Bob,Marketing,85000
Charlie,Engineering,135000
Diana,HR,70000
`

func main() {
	r := csv.NewReader(strings.NewReader(csvTestData))
	table, err := tablewriter.NewCSVReader(os.Stdout, r, true,
		tablewriter.WithDebug(true),
		tablewriter.WithHeaderControl(tw.Control{Hide: tw.On}),
	)

	if err != nil {
		ll.Fatal(err)
	}

	table.Render()
}
┌─────────┬─────────────┬────────┐
│ Alice   │ Engineering │ 120000 │
│ Bob     │ Marketing   │ 85000  │
│ Charlie │ Engineering │ 135000 │
│ Diana   │ HR          │ 70000  │
└─────────┴─────────────┴────────┘

olekukonko added a commit that referenced this issue May 16, 2025
olekukonko added a commit that referenced this issue May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request Usage & Discussion Practically understand how to customize & usage
Projects
None yet
Development

No branches or pull requests

2 participants