termui
termui copied to clipboard
Guide on table with different sized columns
Hello,
I've been trying to figure out how to use the table ColumnWidths to set my tables to have the proper widths in each column for it's content, but to no avail. An example code, or some documentation would be very useful for newcomers to the project on how to properly use this feature would be extremely useful.
Not sure if you still need help, I was also trying to figure out how to size columns properly in a table.
In looking at the source code, ColumnWidths
is an array of integers specifying the width for each column. ColumnResizer
seems to be a function that modifies the ColumnWidths
directly during each call to Draw
. Therefore usage is probably something like this:
table := NewTable()
table.ColumnResizer = func() {
w := table.Inner.Dx()
table.ColumnWidths = []int{w/2, w/2}
}
I think that if you do not need dynamic resizing, you can probably just set ColumnWidths
directly.
Hope this helps.
I know it seems obvious. I thought so too, but and example still would not hurt, in the documentation. This ticket will jut get buried at some point.