gizak / termui

Golang terminal dashboard
MIT License
13.06k stars 783 forks source link

Guide on table with different sized columns #293

Open madpipeline opened 3 years ago

madpipeline commented 3 years ago

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.

dingyuchen commented 3 years ago

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.

madpipeline commented 3 years ago

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.