Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Commit

Permalink
Use an embedded field for underlying table
Browse files Browse the repository at this point in the history
  • Loading branch information
carolynvs-msft committed Jul 26, 2018
1 parent c22d950 commit e86f22e
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions cmd/svcat/output/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,19 @@ const DefaultPageWidth = 80
// value of our special column first, call SetColMinWidth and then add the
// headers/rows.
type ListTable struct {
table *tablewriter.Table
*tablewriter.Table

columnWidths []int // Max width of data in column we've seen
variableColumn int // 0 == not set
pageWidth int // Defaults to 80
headers []string
rows [][]string
}

// SetBorder is a proxy/pass-thru to the tablewriter.Table's func
func (lt *ListTable) SetBorder(b bool) { lt.table.SetBorder(b) }

// SetVariableColumn tells us which column, if any, should be of variable
// width so that the table takes up the width of the screen rather than
// wrapping cells in this column prematurely.
func (lt *ListTable) SetVariableColumn(c int) { lt.variableColumn = c }

// SetColMinWidth is a proxy/pass-thru to the tablewriter.Table's func
func (lt *ListTable) SetColMinWidth(c, w int) { lt.table.SetColMinWidth(c, w) }

// SetPageWidth allows us to change the screen/page width.
// Probably not used right now, so its just for future need.
func (lt *ListTable) SetPageWidth(w int) { lt.pageWidth = w }
Expand All @@ -74,8 +67,7 @@ func (lt *ListTable) SetHeader(keys []string) {
}
}

// Save the headers for when we call Render
lt.headers = keys
lt.Table.SetHeader(keys)
}

// Append will look at each column in the row to see if its longer than any
Expand Down Expand Up @@ -125,12 +117,11 @@ func (lt *ListTable) Render() {
}
}

// Pass along all of the data (header and rows) to the real tablewriter
lt.table.SetHeader(lt.headers)
// Pass along all of the row data to the underlying tablewriter
for _, row := range lt.rows {
lt.table.Append(row)
lt.Table.Append(row)
}
lt.table.Render()
lt.Table.Render()
}

// NewListTable builds a table formatted to list a set of results.
Expand All @@ -140,7 +131,7 @@ func NewListTable(w io.Writer) *ListTable {
t.SetColumnSeparator(" ")

return &ListTable{
table: t,
Table: t,
pageWidth: DefaultPageWidth,
}
}
Expand Down

0 comments on commit e86f22e

Please sign in to comment.