go-pretty

module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 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 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

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              1607 ns/op             584 B/op         21 allocs/op
BenchmarkTable_Render-8                   100000             18828 ns/op            5009 B/op        190 allocs/op
BenchmarkTable_RenderCSV-8                300000              4066 ns/op            1920 B/op         44 allocs/op
BenchmarkTable_RenderHTML-8               300000              5621 ns/op            3377 B/op         43 allocs/op
BenchmarkTable_RenderMarkdown-8           300000              4221 ns/op            1856 B/op         42 allocs/op

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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