Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
xinaxu committed Aug 29, 2023
1 parent 62e32dc commit 6580dda
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ func main () {
* `headerColor` The color to use for the header. The color is specified as a comma separated list of color codes. Check available values [here](https://github.com/fatih/color/blob/main/color.go)
* `color` The color to use for the column. The color is specified as a comma separated list of color codes. Check available values [here](https://github.com/fatih/color/blob/main/color.go)
* `format` The format to use for the column. For `time.Time`, the format is specified as a [Go time layout](https://pkg.go.dev/time#pkg-constants). For all other types, the format is specified as a [Go format string](https://pkg.go.dev/fmt#hdr-Printing).
* `verbose` If set to true, the column will be displayed only when the verbose is set to true in `Render` function.
* `verbose` If set to true, the column will be displayed only when the verbose is set to true in the `Table`.
* `expand` If set to true, the column will be expanded to a sub table. The column needs to be a slice/instance/pointer to a struct.
* `-` If specified, the column will be hidden.

## Supported Options
* `Table.WithTab` Set the tab string that is appended to the sub-tables.
* `Table.WithVerbose` Columns with `verbose` tag is only displayed when the verbose is set to true.
* `Table.WithPaddingSize` Set the padding size for each column which is the minimum padding between the columns.
* `Table.WithHeaderRowColor` Overrides the default header row color.
* `Table.WithFirstColumnColor` Overrides the default first column color.
6 changes: 6 additions & 0 deletions table.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ func WithHeaderRowColor(c *color.Color) Option {
}
}

func WithFirstColumnColor(c *color.Color) Option {
return func(t *Table) {
t.firstColumnColor = c
}
}

func WithPaddingSize(p int) Option {
return func(t *Table) {
t.padding = p
Expand Down
2 changes: 1 addition & 1 deletion table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestRender(t *testing.T) {
table := New().toTable(p, "", nil)
require.NotNil(t, table)

str := New().Render([]Parent{p, p})
str := New(WithVerbose(), WithTab(" "), WithPaddingSize(2), WithFirstColumnColor(nil), WithHeaderRowColor(nil)).Render([]Parent{p, p})
fmt.Println(str)
}

Expand Down

0 comments on commit 6580dda

Please sign in to comment.