package ui import ( "fmt" "os" "github.com/fatih/color" "github.com/gosuri/uitable" ) func Error(s string) { color.Red(s) } func ErrorWithExit(s string) { color.Red(s) os.Exit(1) } type KV struct { K string V string } type KVTable struct { KVs []KV } func (k *KVTable) Print() { table := uitable.New() table.MaxColWidth = 100 table.Wrap = true // wrap columns table.AddRow("") for _, i := range k.KVs { if i.V == "" { table.AddRow(i.K, "-") } else { table.AddRow(i.K, i.V) } } fmt.Println(table) } type Table struct { Title []interface{} Items [][]interface{} } func (t *Table) Print() { table := uitable.New() table.MaxColWidth = 70 table.Wrap = true // wrap columns table.AddRow(t.Title...) for _, item := range t.Items { table.AddRow(item...) } fmt.Println(table) }