mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 13:04:20 +02:00
streamline table api
This commit is contained in:
@@ -42,29 +42,28 @@ type Table struct {
|
||||
debugGoRoutines bool
|
||||
}
|
||||
|
||||
func NewTable(conf *cfg.Config, columns, rows int) *Table {
|
||||
table := new(Table{
|
||||
func NewTable(conf *cfg.Config) *Table {
|
||||
return new(Table{
|
||||
Mode: conf.Output,
|
||||
maxwidth: cfg.GetTermWidth(),
|
||||
debugGoRoutines: conf.DebugGoRoutines,
|
||||
Headers: []string{},
|
||||
RawHeaders: []string{},
|
||||
lenHeaders: []int{},
|
||||
alignInts: conf.AlignInts,
|
||||
})
|
||||
|
||||
table.Headers = make([]string, columns)
|
||||
table.RawHeaders = make([]string, columns)
|
||||
table.Entries = make([][]any, rows)
|
||||
table.lenHeaders = make([]int, columns)
|
||||
table.alignInts = conf.AlignInts
|
||||
|
||||
return table
|
||||
}
|
||||
|
||||
func NewTableEmpty(conf *cfg.Config) *Table {
|
||||
table := new(Table{
|
||||
Mode: conf.Output,
|
||||
maxwidth: cfg.GetTermWidth(),
|
||||
debugGoRoutines: conf.DebugGoRoutines,
|
||||
})
|
||||
table.alignInts = conf.AlignInts
|
||||
func (table *Table) WithSize(columns, rows int) *Table {
|
||||
if columns > 0 {
|
||||
table.Headers = make([]string, columns)
|
||||
table.RawHeaders = make([]string, columns)
|
||||
table.lenHeaders = make([]int, columns)
|
||||
}
|
||||
|
||||
if rows > 0 {
|
||||
table.Entries = make([][]any, rows)
|
||||
}
|
||||
|
||||
return table
|
||||
}
|
||||
@@ -72,12 +71,7 @@ func NewTableEmpty(conf *cfg.Config) *Table {
|
||||
func (table *Table) WithHeaders(headers ...string) *Table {
|
||||
count := len(headers)
|
||||
|
||||
table.Entries = [][]any{}
|
||||
table.lenHeaders = make([]int, count)
|
||||
table.Headers = make([]string, count)
|
||||
table.RawHeaders = make([]string, count)
|
||||
|
||||
table.Addheaders(headers...)
|
||||
table.WithSize(count, 0).Addheaders(headers...)
|
||||
|
||||
return table
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user