Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 57 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,12 @@ func main() {
t := table.New(os.Stdout)

t.SetHeaders("ID", "Fruit", "Stock")
t.SetFooters("ID", "Fruit", "Stock")

t.SetRowLines(false)
t.AddRow("1", "Apple", "14")
t.AddRow("2", "Banana", "88,041")
t.AddRow("3", "Cherry", "342")
t.AddRow("4", "Dragonfruit", "1")

t.SetFooters("", "Count", "4")
t.Render()
}

Expand All @@ -260,14 +259,11 @@ func main() {
│ ID │ Fruit │ Stock │
├────┼─────────────┼────────┤
│ 1 │ Apple │ 14 │
├────┼─────────────┼────────┤
│ 2 │ Banana │ 88,041 │
├────┼─────────────┼────────┤
│ 3 │ Cherry │ 342 │
├────┼─────────────┼────────┤
│ 4 │ Dragonfruit │ 1 │
├────┼─────────────┼────────┤
ID FruitStock
Count 4
└────┴─────────────┴────────┘

```
Expand Down Expand Up @@ -487,17 +483,17 @@ func main() {

#### Output
```
┌───────────────────┬────────┬────────────────
│ System │ Status │ Last Check
├───────────────────┼────────┼────────────────
│ Life Support │ OK │ May 13 17:34:32
├───────────────────┤ ├────────────────
│ Nuclear Generator │ │ May 13 17:33:32
├───────────────────┼────────┼────────────────
│ Weapons Systems │ FAIL │ May 13 17:34:32
├───────────────────┼────────┤
│ Shields │ OK │
└───────────────────┴────────┴────────────────
┌───────────────────┬────────┬────────────────┐
│ System │ Status │ Last Check │
├───────────────────┼────────┼────────────────┤
│ Life Support │ OK │ May 2 09:28:05
├───────────────────┤ ├────────────────┤
│ Nuclear Generator │ │ May 2 09:27:05
├───────────────────┼────────┼────────────────┤
│ Weapons Systems │ FAIL │ May 2 09:28:05
├───────────────────┼────────┤ │
│ Shields │ OK │ │
└───────────────────┴────────┴────────────────┘

```

Expand Down Expand Up @@ -620,6 +616,49 @@ func main() {
│ default │ Service/test │ 0 │ 0 │ 0 │ 1 │ 0 │ 3 │ 0 │ 4 │ 9 │ 0 │
└───────────┴────────────────┴──────────┴──────┴────────┴─────┴─────────┴──────────┴──────┴────────┴─────┴─────────┘

```

### Example: Only Wrap When Needed
```go
package main

import (
"os"

"github.com/aquasecurity/table"
)

func main() {

t := table.New(os.Stdout)

t.SetHeaders("ID", "Fruit", "Stock")

t.AddRow("1", "01234567890123456789012345678901234567890123456789012345678901234567890123456789", "14")
t.AddRow("2", "Banana", "88,041")
t.AddRow("3", "Cherry", "342")
t.AddRow("4", "Dragonfruit", "1")

t.Render()
}

```

#### Output
```
┌────┬──────────────────────────────────────────────────────────────┬────────┐
│ ID │ Fruit │ Stock │
├────┼──────────────────────────────────────────────────────────────┼────────┤
│ 1 │ 01234567890123456789012345678901234567890123456789012345678- │ 14 │
│ │ 901234567890123456789 │ │
├────┼──────────────────────────────────────────────────────────────┼────────┤
│ 2 │ Banana │ 88,041 │
├────┼──────────────────────────────────────────────────────────────┼────────┤
│ 3 │ Cherry │ 342 │
├────┼──────────────────────────────────────────────────────────────┼────────┤
│ 4 │ Dragonfruit │ 1 │
└────┴──────────────────────────────────────────────────────────────┴────────┘

```
<!--/eg-->

Expand Down
5 changes: 2 additions & 3 deletions _examples/06-footers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ func main() {
t := table.New(os.Stdout)

t.SetHeaders("ID", "Fruit", "Stock")
t.SetFooters("ID", "Fruit", "Stock")

t.SetRowLines(false)
t.AddRow("1", "Apple", "14")
t.AddRow("2", "Banana", "88,041")
t.AddRow("3", "Cherry", "342")
t.AddRow("4", "Dragonfruit", "1")

t.SetFooters("", "Count", "4")
t.Render()
}
3 changes: 2 additions & 1 deletion table.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,8 @@ func (t *Table) getColspan(header bool, footer bool, row int, col int) int {
func (t *Table) renderLineAbove(row iRow, prev iRow) {

// don't draw top border if disabled
if (row.first && !t.borders.Top) || (!prev.header && !t.rowLines && !row.first) {
if (row.first && !t.borders.Top) ||
(!prev.header && !row.footer && !t.rowLines && !row.first) {
return
}

Expand Down
20 changes: 20 additions & 0 deletions table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,26 @@ func Test_Footers(t *testing.T) {
`, "\n"+builder.String())
}

func Test_Footers_No_RowLines(t *testing.T) {
builder := &strings.Builder{}
table := New(builder)
table.SetFooters("A", "B", "C")
table.SetRowLines(false)
table.AddRow("1", "2", "3")
table.AddRow("4", "5", "6")
table.AddRow("7", "8", "9")
table.Render()
assertMultilineEqual(t, `
┌───┬───┬───┐
│ 1 │ 2 │ 3 │
│ 4 │ 5 │ 6 │
│ 7 │ 8 │ 9 │
├───┼───┼───┤
│ A │ B │ C │
└───┴───┴───┘
`, "\n"+builder.String())
}

func Test_VaryingWidths(t *testing.T) {
builder := &strings.Builder{}
table := New(builder)
Expand Down
Loading