-
Notifications
You must be signed in to change notification settings - Fork 48
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 header support to tableprinter #139
Conversation
@heaths While in the table header PR for How I am envisioning this working is that the
What are your thoughts? |
That's fine. They main points were to:
The latter makes me wonder if we either:
The problem is that there is no style support in this module currently, which is why I passed it in. |
Hmm my initial thought was that we might just add in a code comment and or code example showing how to achieve the default look achieved by |
That's fine, too. I was mainly going for consistency - at least making it easily possible to be consistent - for extensions. |
Resolves PR feedback
I made the changes and, IMO, the tables look nice in the CLI (using "white+du"): There is a caveat, though. By padding the last header column, TTY table assertions need to be padded in the header row, which I suspect many CLI devs won't expect. It's solvable, but by exposing some things publicly that might seem odd in isolation. For example, a separate The underlines really make it look like a header, and even looks nice with a full background color: But perhaps it's not worth the maintenance hassle. Thoughts? if we don't try to support underlines or other background styles, there's no reason not to trim the last column header, which is what happens currently. /cc @williammartin |
Resolves PR feedback
To note, if you decide the support for full-column styles isn't worth the maintenance hassle or workaround, no change should be needed to this module and the other PR is pretty much done and ready for review. |
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.
@heaths I have a different proposal for supporting full column styles which I think is a bit less clever than the approach you are thinking. What about introducing a WithPadding
method function that is very similar to WithTruncate
? We could then add a padding function to the text
package which would pad to string as necessary. This would allow for the most amount of customization and follow a pattern that we have already laid out. Obviously this could allow our users to create disproportionate looking tables, but I would say that is their business.
pkg/tableprinter/table.go
Outdated
@@ -15,6 +15,7 @@ import ( | |||
type fieldOption func(*tableField) | |||
|
|||
type TablePrinter interface { | |||
AddHeaders([]string, ...fieldOption) |
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.
Ok kind of an odd question, but should this be AddHeader
? I don't have an opinion, just linguistically wondering what is correct. Are we adding a table header, or are we adding table headers?
I could play around with something like that, which is more or less one idea I was considering. That said, it's not even worth it unless you and the others prefer the underlined table header. Certainly easier - still not bad looking, but then relies entirely on color - to only use a different, IMO dimmer, color for the header. |
I suppose one interesting use case for a |
I went ahead and made the changes. It's not a lot of work, and I still personally believe the cli/cli#8090 already takes advantage of this, so the PR will fail, of course. But I wanted to show how I'm using it, basing it on |
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.
@heaths This is great. I pushed a small commit to extract text.PadRight
function that is reusable for other users. I am glad we are exposing the WithPadding
functionality as gh
is not the only consumer of this package.
Related to cli/cli#8090