forked from dynport/metrix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable.go
More file actions
38 lines (33 loc) · 637 Bytes
/
table.go
File metadata and controls
38 lines (33 loc) · 637 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"fmt"
"strings"
)
type Table struct {
Columns [][]string
Lengths map[int]int
}
func NewTable() *Table {
return &Table{
Columns: [][]string{},
Lengths: map[int]int{},
}
}
func (self *Table) Lines() (lines []string) {
for _, col := range self.Columns {
cl := []string{}
for i, v := range col {
cl = append(cl, fmt.Sprintf("%-*s", self.Lengths[i], v))
}
lines = append(lines, strings.Join(cl, "\t"))
}
return
}
func (self *Table) Add(cols []string) {
for i, v := range cols {
if self.Lengths[i] < len(v) {
self.Lengths[i] = len(v)
}
}
self.Columns = append(self.Columns, cols)
}