Releases: jedib0t/go-pretty
v3.0.1
v3.0.0
Changes from v2.0.0:
- Remove external dependencies as much as possible (
v2.1.0
) - Table: more colorful styles in
table/style.go
(v2.2.0
) - Progress/Task Tracker
progress/writer.go
(v2.3.0
) - Table: sort rows by any column (
v2.4.0
) - Table: page rows every X number of rows (
v2.5.0
) - List: refactor and simplify styles in
list/style.go
v2.5.0
You can limit then number of lines rendered in a single "Page". This logic
can handle rows with multiple lines too. Here is a simple example:
t.SetPageSize(1)
t.Render()
to get:
+-----+------------+-----------+--------+-----------------------------+
| # | FIRST NAME | LAST NAME | SALARY | |
+-----+------------+-----------+--------+-----------------------------+
| 1 | Arya | Stark | 3000 | |
+-----+------------+-----------+--------+-----------------------------+
| | | TOTAL | 10000 | |
+-----+------------+-----------+--------+-----------------------------+
+-----+------------+-----------+--------+-----------------------------+
| # | FIRST NAME | LAST NAME | SALARY | |
+-----+------------+-----------+--------+-----------------------------+
| 20 | Jon | Snow | 2000 | You know nothing, Jon Snow! |
+-----+------------+-----------+--------+-----------------------------+
| | | TOTAL | 10000 | |
+-----+------------+-----------+--------+-----------------------------+
+-----+------------+-----------+--------+-----------------------------+
| # | FIRST NAME | LAST NAME | SALARY | |
+-----+------------+-----------+--------+-----------------------------+
| 300 | Tyrion | Lannister | 5000 | |
+-----+------------+-----------+--------+-----------------------------+
| | | TOTAL | 10000 | |
+-----+------------+-----------+--------+-----------------------------+
v2.4.0
Support sorting tables by any of the columns. The sorting directives can be specified using the Column Name (needs a header row with the Column Names) or the Column Number (1-indexed).
Example:
tw := table.NewWriter()
tw.AppendHeader(table.Row{"#", "First Name", "Last Name", "Salary"})
tw.AppendRows([]table.Row{
{1, "Arya", "Stark", 3000},
{11, "Sansa", "Stark", 6000},
{20, "Jon", "Snow", 2000, "You know nothing, Jon Snow!"},
{300, "Tyrion", "Lannister", 5000},
})
tw.SetStyle(table.StyleLight)
tw.SortBy([]table.SortBy{
{Name: "Last Name", Mode: table.Asc},
{Name: "First Name", Mode: table.Dsc},
{Number: 4, Mode: table.DscNumeric}, // corresponds to the "Salary" column
})
fmt.Println(tw.Render())
results in:
┌─────┬────────────┬───────────┬────────┬─────────────────────────────┐
│ # │ FIRST NAME │ LAST NAME │ SALARY │ │
├─────┼────────────┼───────────┼────────┼─────────────────────────────┤
│ 300 │ Tyrion │ Lannister │ 5000 │ │
│ 20 │ Jon │ Snow │ 2000 │ You know nothing, Jon Snow! │
│ 11 │ Sansa │ Stark │ 6000 │ │
│ 1 │ Arya │ Stark │ 3000 │ │
└─────┴────────────┴───────────┴────────┴─────────────────────────────┘
v2.3.0
Track the Progress of one or more Tasks (like downloading multiple files in parallel).
- Track one or more Tasks at the same time
- Dynamically add one or more Task Trackers while
Render()
is in progress - Choose to have the Writer auto-stop the Render when no more Trackers are
in queue, or manually stop usingStop()
- Redirect output to an io.Writer object (like os.StdOut)
- Completely customizable styles
- Many ready-to-use styles: style.go
- Colorize various parts of the Tracker using
StyleColors
- Customize how Trackers get rendered using
StyleOptions
Sample Progress Tracking:
Calculating Total # 1 ... done! [3.25K in 100ms]
Calculating Total # 2 ... done! [6.50K in 100ms]
Downloading File # 3 ... done! [9.75KB in 100ms]
Transferring Amount # 4 ... done! [$26.00K in 200ms]
Transferring Amount # 5 ... done! [£32.50K in 201ms]
Downloading File # 6 ... done! [58.50KB in 300ms]
Calculating Total # 7 ... done! [91.00K in 400ms]
Transferring Amount # 8 ... 60.9% (●●●●●●●●●●●●●●◌◌◌◌◌◌◌◌◌) [$78.00K in 399.071ms]
Downloading File # 9 ... 32.1% (●●●●●●●○◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌) [58.50KB in 298.947ms]
Transferring Amount # 10 ... 13.0% (●●○◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌) [£32.50K in 198.84ms]
v2.2.0
v2.1.0
This release removes the dependency on fatih/color. The text/color.go
file now implements a coloring logic that makes more sense for use in cases like colored tables within colored tables.
This does change table.Style.Color
in a backward-incompatible way. AutoIndexColumn
and FirstColumn
are now logically collapsed into a single IndexColumn
variable inside table.Style.Color
.
v2.0.0
This release changes Table
in a backward-incompatible way (table.Style
changes a lot) and hence the Major version bump.
table.Style
is not a flat struct anymore; and provides a lot more configuration optionsTableWriter
exposes a few more interfaces to set Alignment/VAlignment for the Header/FooterTableWriter
now supports rendering "colored" tables/content within "colored" tables- Colored-text within cells align and wrap without any issues
- Other minor bug-fixes and code cleanup
v1.0.0
This release contains a feature-packed Table
and List
packages.
Table
Pretty-print tables into ASCII/Unicode strings.
- Add Rows one-by-one or as a group
- Add Header(s) and Footer(s)
- Auto Index Rows (1, 2, 3 ...) and Columns (A, B, C, ...)
- Limit the length of the Rows; limit the length of individual Columns
- Alignment - Horizontal & Vertical
- Auto (horizontal) Align (numeric columns are aligned Right)
- Custom (horizontal) Align per column
- Custom (vertical) VAlign per column (and multi-line column support)
- Mirror output to an io.Writer object (like os.StdOut)
- Completely customizable styles
- Many ready-to-use styles: table/style.go
- Colorize Headers/Body/Footers using github.com/fatih/color
- Custom text-case for Headers/Body/Footers
- Enable separators between each row
- Render table without a Border
- Render as:
- (ASCII/Unicode) Table
- CSV
- HTML Table (with custom CSS Style)
- Markdown Table
List
Pretty-print lists with multiple levels/indents into ASCII/Unicode strings.
- Append Items one-by-one or as a group
- Indent/UnIndent as you like
- Limit the length of the Lines/Items
- Support Items with Multiple-lines
- Mirror output to an io.Writer object (like os.StdOut)
- Completely customizable styles
- Many ready-to-use styles: list/style.go
- Render as:
- (ASCII/Unicode) List
- HTML List (with custom CSS Class)
- Markdown List
v0.1.0
The first (pre)-release with a feature packed TableWriter
- Pretty-print tables into ASCII/Unicode strings:
- Add Rows one-by-one or as a group
- Add Header(s) and Footer(s)
- Auto Index Rows (1, 2, 3 ...) and Columns (A, B, C, ...)
- Mirror output to an io.Writer object (like os.StdOut)
- Limit the length of the Rows; limit the length of individual Columns
- Alignment - Horizontal & Vertical
- Auto (horizontal) Align (numeric columns are aligned Right)
- Custom (horizontal) Align per column
- Custom (vertical) VAlign per column (and multi-line column support)
- Completely customizable styles
- Many ready-to-use styles: table/style.go
- Colorize Headers/Body/Footers using github.com/fatih/color
- Custom text-case for Headers/Body/Footers
- Enable separators between each row
- Render table without a Border
- Render as:
- (ASCII/Unicode) Table
- CSV
- HTML Table (with custom CSS Style)
- Markdown Table
+-----+------------+-----------+--------+-----------------------------+
| # | FIRST NAME | LAST NAME | SALARY | |
+-----+------------+-----------+--------+-----------------------------+
| 1 | Arya | Stark | 3000 | |
| 20 | Jon | Snow | 2000 | You know nothing, Jon Snow! |
| 300 | Tyrion | Lannister | 5000 | |
+-----+------------+-----------+--------+-----------------------------+
| | | TOTAL | 10000 | |
+-----+------------+-----------+--------+-----------------------------+
A demonstration of all the capabilities can be found here: cmd/demo-table