elastictable

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2019 License: MIT Imports: 10 Imported by: 0

README

go-elastictable Build Status Go Report Card godoc

Go command line tables with elastic column resizing to adapt terminal width.

Approach

Naive algorithms simply take width-of-table/width-of-terminal and apply a uniform factor to grow/shrink the columns. This results in shoddy output, small columns become worse when wrapped.

This library optimizes for visual balance by doing the following:

  • Closely pack wrapped lines:

    # don't:
    | don't waste whitespace in the second |
    | line                                 |
    
    # do:
    | when wrapping a column |
    | try to pack the lines  |
    | as closely as possible |
    
  • Balance row heights:

    # don't:
    | COL-1       | COL-2       | COL-3       |
    +-------------+-------------+-------------+
    | small col   | small col   | really big  |
    |             |             | column that |
    |             |             | spans many  |
    |             |             | rows        |
    
    # do:
    | COL-1 | COL-2 | COL-3                   |
    +-------+-------+-------------------------+
    | small | small | really big column that  |
    | col   | col   | spans many rows         |
    
  • Number of lines depends on wrapping behavior and is hard to predict in advance. So instead of fully computing expensive re-wraps for every pass, it rather just guesses the number of lines using simple rune widths. This works well in most cases, except there will be some trade-offs in certain scenarios.

Compatibility Note

This library is currently under active development. Please use a dependency manager (like godep) to pin specific commit versions.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ElasticTable

type ElasticTable struct {
	// contains filtered or unexported fields
}

ElasticTable - struct that is returned

func NewElasticTable

func NewElasticTable(header []string) *ElasticTable

NewElasticTable - creates a new ElasticTable with given headers

func (*ElasticTable) AddRow

func (e *ElasticTable) AddRow(row []string)

AddRow - Adds a row

func (*ElasticTable) Render

func (e *ElasticTable) Render(out io.Writer)

Render - Prints formatted table to the given writer

Jump to

Keyboard shortcuts

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