-
Notifications
You must be signed in to change notification settings - Fork 30
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
Add WithHeaderSeparatorRow
#40
Add WithHeaderSeparatorRow
#40
Conversation
This function will print a separator line between the header and the data rows. It will use the same formatter as the header. The width of each separator cell will be equal to the width of the header cell in the same column. It supports runes, meaning dependning on the rune width, it might not be perfect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the patch! A couple of comments when the seperator widths cannot cleanly divide the header names. Also, this only puts the separator directly below the header, instead of continuing the line across the whole row. Is that the intent?
table.go
Outdated
headerRuneCount := t.Width(headerName) | ||
separatorLen := headerRuneCount / separatorRuneWidth |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If headerRuneCount
and separatorRuneWidth
aren't cleanly divisible then the length here will be truncated, resulting in too short of a separator line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a bug, it's a feature 😄
The intent is, that in a case where you have a separator rune that's of cell width 2
and a header of length 5
, you get a separator of length 2
(cell width 4
).
In this case I wanted the separator to be one char shorter, instead of too long. I thought better too short than too long 🤔 Either way, this is more of an edge case, I doubt many people are gonna use chars other than _-.
.
Yes, that was the intend. I was going for this style. I wanted to replicate this: We could however make this configurable. Since this feature didn't exist before though, I wanted to refrain from adding more stuff nobody asked for. |
3c60862
to
3f41783
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again!
Thanks for merging and the quick response. Have a nice day ;) |
This function will print a separator line between the header and the data rows. It will use the same formatter as the header. The width of each separator cell will be equal to the width of the header cell in the same column. It supports runes, meaning dependning on the rune width, it might not be perfect.
Oh and, I use gofumpt, it reformatted some comments, hope that's okay.