gizak / termui

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

table widget with new property: CellSeparator #278

Open Royalsspirit opened 3 years ago

Royalsspirit commented 3 years ago

Hello guys,

First, thank you all for this awesome project.

I started to use table widget to have a kind of structure to manage different label and data but without the separator | while keeping all properties to manage padding, margin, etc ...

Instead of having :

------------------------------------
|  label | data | label | data      |
|                                   |
|                                   |
-------------------------------------

I would like to have something like :

--------------------------------
|  label  data  label  data      |
|                                |
|                                |
---------------------------------

It seems very easy to create a new property CellSeparator

type Table struct {
    Block
    Rows          [][]string
    ColumnWidths  []int
    TextStyle     Style
    RowSeparator  bool
+++ CellSeparator bool
    TextAlignment Alignment
    RowStyles     map[int]Style
    FillRow       bool

    // ColumnResizer is called on each Draw. Can be used for custom column sizing.
    ColumnResizer func()
}

And to add a if statement around the for loop which manage the cell separator:

+++     if self.CellSeparator {
            for i, width := range columnWidths {
                if self.FillRow && i < len(columnWidths)-1 {
                    verticalCell.Style.Bg = rowStyle.Bg
                } else {
                    verticalCell.Style.Bg = self.Block.BorderStyle.Bg
                }

                separatorXCoordinate += width
                buf.SetCell(verticalCell, image.Pt(separatorXCoordinate, yCoordinate))
                separatorXCoordinate++
            }
++      }

I would like to have your opinion. With your knowledge of this project, you probably will have a better approach about it or a potential negative impact. Or just you think is totally useless :p

Let me know.

RYL