Skip to content

Commit

Permalink
update README.md for usage and changes over time (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
jedib0t authored Jun 24, 2022
1 parent 76030eb commit 7cfcc6a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 62 deletions.
103 changes: 42 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,23 @@
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=jedib0t_go-pretty&metric=alert_status)](https://sonarcloud.io/dashboard?id=jedib0t_go-pretty)

Utilities to prettify console output of tables, lists, progress-bars, text, etc.
with a heavy emphasis on customization.

## Usage

The current major version of this package is __v6__, and it follows the standard
outlined [here](https://go.dev/doc/modules/version-numbers#major-version).

Run `go get github.com/jedib0t/go-pretty/v6` to add this as a dependency to your
project, and import the packages in your code using one or more of these:
* `github.com/jedib0t/go-pretty/v6/list`
* `github.com/jedib0t/go-pretty/v6/progress`
* `github.com/jedib0t/go-pretty/v6/table`
* `github.com/jedib0t/go-pretty/v6/text`

## Table

Pretty-print tables into ASCII/Unicode strings.
Pretty-print tables in a terminal with colors, nested tables and more.

```
+-----+------------+-----------+--------+-----------------------------+
Expand All @@ -24,85 +37,53 @@ Pretty-print tables into ASCII/Unicode strings.
+-----+------------+-----------+--------+-----------------------------+
```

<img src="table/images/table-StyleColoredBright.png" width="640px"/>
<img src="table/images/table-StyleColoredBright.png" alt="Table with Colors in a Terminal"/>

More details can be found here: [table/](table)

## List
## Progress

Pretty-print lists with multiple levels/indents into ASCII/Unicode strings.
Track the Progress of one or more Tasks like downloading multiple files in
parallel.

```
■ Game Of Thrones
■ Winter
■ Is
■ Coming
■ This
■ Is
■ Known
■ The Dark Tower
■ The Gunslinger
```
<img src="progress/images/demo.gif" alt="Progress Demo in a Terminal"/>

More details can be found here: [list/](list)
More details can be found here: [progress/](progress)

# Progress
## List

Track the Progress of one or more Tasks (like downloading multiple files in
parallel).
Pretty-print lists with multiple levels/indents into ASCII/Unicode strings.

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]
╭─ Game Of Thrones
│ ├─ Winter
│ ├─ Is
│ ╰─ Coming
│ ├─ This
│ ├─ Is
│ ╰─ Known
╰─ The Dark Tower
╰─ The Gunslinger
```

More details can be found here: [progress/](progress)
More details can be found here: [list/](list)

## Text

Utility functions to manipulate text with or without ANSI escape sequences. Most
of the functions available are used in one or more of the other packages here.

- Align text horizontally or vertically
- [text/align.go](text/align.go) and [text/valign.go](text/valign.go)
- Colorize text
- [text/color.go](text/color.go)
- Cursor Movement
- [text/cursor.go](text/cursor.go)
- Format text (convert case)
- [text/format.go](text/format.go)
- String Manipulation (Pad, RepeatAndTrim, RuneCount, Trim, etc.)
- [text/string.go](text/string.go)
- Transform text (UnixTime to human-readable-time, pretty-JSON, etc.)
- [text/transformer.go](text/transformer.go)
- Wrap text
- [text/wrap.go](text/wrap.go)

The unit-tests for each of the above show how these can be used. There GoDoc
should also have examples for all the available functions.

## Benchmarks

Partial output of `make bench` on CI:
```
BenchmarkList_Render-2 372352 3179 ns/op 856 B/op 38 allocs/op
BenchmarkProgress_Render-2 4 300318682 ns/op 3438 B/op 87 allocs/op
BenchmarkTable_Render-2 27208 44154 ns/op 5616 B/op 179 allocs/op
BenchmarkTable_RenderCSV-2 108732 11059 ns/op 2624 B/op 46 allocs/op
BenchmarkTable_RenderHTML-2 88633 13425 ns/op 4080 B/op 45 allocs/op
BenchmarkTable_RenderMarkdown-2 107420 10991 ns/op 2560 B/op 44 allocs/op
```
- Align text [Horizontally](text/align.go) or [Vertically](text/valign.go)
- [Colorize](text/color.go) text
- [Cursor](text/cursor.go) Movement
- [Format](text/format.go) text (convert case)
- [String](text/string.go) Manipulation (Pad, RepeatAndTrim, RuneCount, etc.)
- [Transform](text/transformer.go) text (UnixTime to human-readable-time, pretty-JSON, etc.)
- [Wrap](text/wrap.go) text

GoDoc has examples for all the available functions.

## v6.0.0++
## Upgrading from v5 or less to v6 or above

If you are using a version of this library older than `v6.0.0` and want to move
to a newer version of this library, you'd have to modify the import paths from
Expand Down
2 changes: 1 addition & 1 deletion cmd/demo-progress/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Output of `go run cmd/demo-list/demo.go`:

<img src="../../progress/images/demo.gif" width="640px"/>
<img src="../../progress/images/demo.gif" alt="Progress Demo in a Terminal"/>
Binary file modified progress/images/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified table/images/table-StyleColoredBright.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7cfcc6a

Please sign in to comment.