github.com/webonyx/up@v0.7.4-0.20180808230834-91b94e551323/internal/table/table.go (about)

     1  package table
     2  
     3  import (
     4  	tab "github.com/tj/simpletable"
     5  )
     6  
     7  // TODO: add to tj/simpletable
     8  
     9  var style = &tab.Style{
    10    Border: &tab.BorderStyle{
    11      TopLeft:            "",
    12      Top:                "",
    13      TopRight:           "",
    14      Right:              "",
    15      BottomRight:        "",
    16      Bottom:             "",
    17      BottomLeft:         "",
    18      Left:               "    ",
    19      TopIntersection:    "",
    20      BottomIntersection: "",
    21    },
    22    Divider: &tab.DividerStyle{
    23      Left:         "",
    24      Center:       "=",
    25      Right:        "",
    26      Intersection: " ",
    27    },
    28    Cell: "",
    29  }
    30  
    31  // Cell is a single cell.
    32  type Cell = tab.Cell
    33  
    34  // Row is a group of cells.
    35  type Row []*Cell
    36  
    37  // Table is an ascii table.
    38  type Table struct {
    39  	*tab.Table
    40  }
    41  
    42  // New table.
    43  func New() *Table {
    44  	t := &Table{tab.New()}
    45    t.SetStyle(style)
    46    return t
    47  }
    48  
    49  // AddRow adds a row.
    50  func (t *Table) AddRow(r Row)  {
    51    t.Body.Cells = append(t.Body.Cells, r)
    52  }