-
Notifications
You must be signed in to change notification settings - Fork 122
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
[Feature Request] - Table full width based on terminal size / Header / Row content auto positioning #328
Comments
Auto-sizing tables has been something I wanted to implement, thanks for the reminder. |
Hey @ondrovic try the code in branch table-auto-width and see if that works for you? Sample usage: https://github.com/jedib0t/go-pretty/blob/table-auto-width/table/render_test.go#L1356-L1533 |
I will give it a try later today and let you know |
As a quick test I tried it like this func renderResultsToTable(results interface{}, totalCount int, totalFileSize int64, ff types.FileFinder) {
t := table.Table{}
// Determine header and footer based on the type of results
var header table.Row
var footer table.Row
switch results.(type) {
case []types.DirectoryResult:
header = table.Row{"Directory", "Count"}
footer = table.Row{"Total", pterm.Sprintf("%v", totalCount)}
case []types.EntryResult:
header = table.Row{"Directory", "FileName", "FileSize"}
footer = table.Row{"Total", pterm.Sprintf("%v", totalCount), pterm.Sprintf("%v", commonFormatters.FormatSize(totalFileSize))}
default:
return // Exit if results type is not supported
}
t.AppendHeader(header)
// Append rows based on the display mode
switch results := results.(type) {
case []types.DirectoryResult:
for _, result := range results {
t.AppendRow(table.Row{
formatResultHyperLink(result.Directory, result.Directory),
pterm.Sprintf("%v", result.Count),
})
}
case []types.EntryResult:
if ff.DisplayDetailedResults {
for _, result := range results {
newLink := pterm.Sprintf("%s/%s", result.Directory, result.FileName)
t.AppendRow(table.Row{
formatResultHyperLink(result.Directory, result.Directory),
formatResultHyperLink(newLink, result.FileName),
result.FileSize,
})
}
}
}
t.AppendFooter(footer)
t.SetStyle(table.StyleColoredDark)
t.SetStyle(table.Style{Size: table.SizeOptions{
WidthMax: 50,
WidthMin: 0,
}})
t.SetOutputMirror(os.Stdout)
t.Render()
} It didn't quite work as I expected without size styles It seems like it broke the headers / footers, it could have been that I wasn't using it like your example using the table writer, I will try that when I get back from errands this morning But also I was hoping more for an automatic / dynamic min / max width where it would auto calculate the min / and the maximum based on the content so you don't have to hard code in the values. While I understand it may increase rendering times based on the the size of the data set. |
Your second SetStyle just overrode the first call's effect. Try it like this:
To auto-size for your terminal, you'd do something like this:
Title sizing logic is broken now and I will fix it before merging this code. |
Two things:
|
// just posting for anyone else who stumbles across this ;-)
t.Style().Size = table.SizeOptions{
WidthMin: w,
}
|
Is your feature request related to a problem? Please describe.
Tables with and column spacing seem to be dependent on row content
Header / Row content alignment, I found in using the
text.Hyperlink(text, link)
it table formattingDescribe the solution you'd like
A config option allow the table to calculate no only the full table width, but also split the header / column locations based on the terminal size
Header / Row content alignment, I found in using the
text.Hyperlink(text, link)
seems to break the content alignmentDescribe alternatives you've considered
Tried adjusting the
.SetColumnConfigs( WidthMin, WidthMax)
Additional context
Examples:
using regular non hyperlink - works as expected, wish I could force it to be the full size of the terminal with everything aligned perfectly
using hyperlink - throws alignment off just a bit
####I was able to find fix the alignment issue by doing the following but it's very hacky and I haven't tested it enough, would be better if this was automagically calculated
another example using colors with hyperlink illustration how alignment is broken - illustration how my temp fix is garbage
The text was updated successfully, but these errors were encountered: