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

table: defaults for row/header/footer align/valign; fixes #340 #341

Merged
merged 1 commit into from
Nov 17, 2024

Conversation

jedib0t
Copy link
Owner

@jedib0t jedib0t commented Nov 17, 2024

Proposed Changes

  • the default align/valign option for every row (header+footer) is text.AlignDefault and text.VAlignDefault
  • expose these as customizable options in table.Style().Format

To change the defaults, you'd do something like this:

		tw := table.NewWriter()
		tw.AppendHeader(table.Row{"#", "First\nName", "Last\nName", "Final\nState", "Misc.\nMulti-line\nNotes"})
		tw.AppendRows([]table.Row{
			{1, "Arya", "Stark", ":) 8)"},
			{20, "Jon", "Snow", ":( :( :(", "You know nothing, Jon Snow!"},
			{300, "Tyrion", "Lannister", ":)"},
		})
		tw.AppendFooter(table.Row{"#", "First\nName", "Last\nName", "Final\nState", "Misc.\nMulti-line\nNotes"})
		tw.SetStyle(table.StyleLight)
		tw.Style().Format.HeaderAlign = text.AlignCenter
		tw.Style().Format.HeaderVAlign = text.VAlignBottom
		tw.Style().Format.FooterAlign = text.AlignRight
		tw.Style().Format.FooterVAlign = text.VAlignTop
		fmt.Println(tw.Render())

to get:

┌─────┬────────┬───────────┬──────────┬─────────────────────────────┐
│     │        │           │          │            MISC.            │
│     │  FIRST │    LAST   │   FINAL  │          MULTI-LINE         │
│   # │  NAME  │    NAME   │   STATE  │            NOTES            │
├─────┼────────┼───────────┼──────────┼─────────────────────────────┤
│   1 │ Arya   │ Stark     │ :) 8)    │                             │
│  20 │ Jon    │ Snow      │ :( :( :( │ You know nothing, Jon Snow! │
│ 300 │ Tyrion │ Lannister │ :)       │                             │
├─────┼────────┼───────────┼──────────┼─────────────────────────────┤
│   # │  FIRST │      LAST │    FINAL │                       MISC. │
│     │   NAME │      NAME │    STATE │                  MULTI-LINE │
│     │        │           │          │                       NOTES │
└─────┴────────┴───────────┴──────────┴─────────────────────────────┘

Remember that column-configs takes precedence and will override the above.

Copy link

sonarcloud bot commented Nov 17, 2024

@jedib0t jedib0t merged commit ada7500 into main Nov 17, 2024
4 checks passed
@jedib0t jedib0t deleted the fix-340 branch November 17, 2024 16:12
@coveralls
Copy link

Pull Request Test Coverage Report for Build 11880337864

Details

  • 14 of 14 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 11622525154: 0.0%
Covered Lines: 3718
Relevant Lines: 3718

💛 - Coveralls

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

Successfully merging this pull request may close these issues.

2 participants