go-pretty

module
v2.2.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2018 License: MIT

README

go-pretty

Build Status Coverage Status Go Report Card GoDoc

Utilities to prettify console output of tables, lists, text, etc.

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 text/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

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
  • Render as:
    • (ASCII/Unicode) List
    • HTML List (with custom CSS Class)
    • Markdown List
 ■ Game Of Thrones
   ■ Winter
   ■ Is
   ■ Coming
     ■ This
     ■ Is
     ■ Known
 ■ The Dark Tower
   ■ The Gunslinger

A demonstration of all the capabilities can be found here: cmd/demo-list

Text

The following features are all used by the other packages in this project. Specifically, table and list use these extensively:

The unit-tests for each of the above show how these are to be used.

Benchmarks

Partial output of make bench:

BenchmarkList_Render-8                   1000000              1836 ns/op             808 B/op         22 allocs/op
BenchmarkTable_Render-8                   100000             20736 ns/op            5426 B/op        191 allocs/op
BenchmarkTable_RenderCSV-8                300000              4394 ns/op            2336 B/op         45 allocs/op
BenchmarkTable_RenderHTML-8               200000              6563 ns/op            3793 B/op         44 allocs/op
BenchmarkTable_RenderMarkdown-8           300000              4666 ns/op            2272 B/op         43 allocs/op

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL