update dependencies
This commit is contained in:
parent
fce1b99683
commit
397e9c0842
164 changed files with 5207 additions and 2213 deletions
36
vendor/github.com/olekukonko/tablewriter/table.go
generated
vendored
36
vendor/github.com/olekukonko/tablewriter/table.go
generated
vendored
|
|
@ -77,6 +77,7 @@ type Table struct {
|
|||
headerParams []string
|
||||
columnsParams []string
|
||||
footerParams []string
|
||||
columnsAlign []int
|
||||
}
|
||||
|
||||
// Start New Table
|
||||
|
|
@ -109,7 +110,9 @@ func NewWriter(writer io.Writer) *Table {
|
|||
borders: Border{Left: true, Right: true, Bottom: true, Top: true},
|
||||
colSize: -1,
|
||||
headerParams: []string{},
|
||||
columnsParams: []string{}}
|
||||
columnsParams: []string{},
|
||||
footerParams: []string{},
|
||||
columnsAlign: []int{}}
|
||||
return t
|
||||
}
|
||||
|
||||
|
|
@ -210,6 +213,22 @@ func (t *Table) SetAlignment(align int) {
|
|||
t.align = align
|
||||
}
|
||||
|
||||
func (t *Table) SetColumnAlignment(keys []int) {
|
||||
for _, v := range keys {
|
||||
switch v {
|
||||
case ALIGN_CENTER:
|
||||
break
|
||||
case ALIGN_LEFT:
|
||||
break
|
||||
case ALIGN_RIGHT:
|
||||
break
|
||||
default:
|
||||
v = ALIGN_DEFAULT
|
||||
}
|
||||
t.columnsAlign = append(t.columnsAlign, v)
|
||||
}
|
||||
}
|
||||
|
||||
// Set New Line
|
||||
func (t *Table) SetNewLine(nl string) {
|
||||
t.newLine = nl
|
||||
|
|
@ -528,6 +547,15 @@ func (t Table) printRows() {
|
|||
}
|
||||
}
|
||||
|
||||
func (t *Table) fillAlignment(num int) {
|
||||
if len(t.columnsAlign) < num {
|
||||
t.columnsAlign = make([]int, num)
|
||||
for i := range t.columnsAlign {
|
||||
t.columnsAlign[i] = t.align
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Print Row Information
|
||||
// Adjust column alignment based on type
|
||||
|
||||
|
|
@ -553,6 +581,7 @@ func (t *Table) printRow(columns [][]string, colKey int) {
|
|||
if len(t.columnsParams) > 0 {
|
||||
is_esc_seq = true
|
||||
}
|
||||
t.fillAlignment(total)
|
||||
|
||||
for i, line := range columns {
|
||||
length := len(line)
|
||||
|
|
@ -579,7 +608,7 @@ func (t *Table) printRow(columns [][]string, colKey int) {
|
|||
|
||||
// This would print alignment
|
||||
// Default alignment would use multiple configuration
|
||||
switch t.align {
|
||||
switch t.columnsAlign[y] {
|
||||
case ALIGN_CENTER: //
|
||||
fmt.Fprintf(t.out, "%s", Pad(str, SPACE, t.cs[y]))
|
||||
case ALIGN_RIGHT:
|
||||
|
|
@ -656,6 +685,7 @@ func (t *Table) printRowMergeCells(writer io.Writer, columns [][]string, colKey
|
|||
}
|
||||
|
||||
var displayCellBorder []bool
|
||||
t.fillAlignment(total)
|
||||
for x := 0; x < max; x++ {
|
||||
for y := 0; y < total; y++ {
|
||||
|
||||
|
|
@ -681,7 +711,7 @@ func (t *Table) printRowMergeCells(writer io.Writer, columns [][]string, colKey
|
|||
|
||||
// This would print alignment
|
||||
// Default alignment would use multiple configuration
|
||||
switch t.align {
|
||||
switch t.columnsAlign[y] {
|
||||
case ALIGN_CENTER: //
|
||||
fmt.Fprintf(writer, "%s", Pad(str, SPACE, t.cs[y]))
|
||||
case ALIGN_RIGHT:
|
||||
|
|
|
|||
34
vendor/github.com/olekukonko/tablewriter/table_test.go
generated
vendored
34
vendor/github.com/olekukonko/tablewriter/table_test.go
generated
vendored
|
|
@ -833,3 +833,37 @@ func TestWrapString(t *testing.T) {
|
|||
t.Errorf("\ngot:\n%v\nwant:\n%v\n", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCustomAlign(t *testing.T) {
|
||||
var (
|
||||
buf = &bytes.Buffer{}
|
||||
table = NewWriter(buf)
|
||||
header = []string{"AAA", "BBB", "CCC"}
|
||||
data = [][]string{
|
||||
[]string{"a", "b", "c"},
|
||||
[]string{"1", "2", "3"},
|
||||
}
|
||||
footer = []string{"a", "b", "cccc"}
|
||||
want = `+-----+-----+-------+
|
||||
| AAA | BBB | CCC |
|
||||
+-----+-----+-------+
|
||||
| a | b | c |
|
||||
| 1 | 2 | 3 |
|
||||
+-----+-----+-------+
|
||||
| A | B | CCCC |
|
||||
+-----+-----+-------+
|
||||
`
|
||||
)
|
||||
table.SetHeader(header)
|
||||
table.SetFooter(footer)
|
||||
table.AppendBulk(data)
|
||||
table.SetColMinWidth(2, 5)
|
||||
table.SetColumnAlignment([]int{ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT})
|
||||
table.Render()
|
||||
|
||||
got := buf.String()
|
||||
|
||||
if got != want {
|
||||
t.Errorf("\ngot:\n%s\nwant:\n%s\n", got, want)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue