table

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package table is the internal shim for providing table support for laying out content prettily.

All interaction with the dependency which provides terminal-drawn tables should go through this module. This provides a shim, giving us isolation. We know the exact subset of features which we rely upon, and can switch providers. If desired, we can use multiple files with build-tags, to let the dependency be satisfied at build-time.

Package table provides table support for character. This implementation uses tabular for layout.

With the more modern Golang features, this should probably be in /internal/ namespace.

Index

Constants

This section is empty.

Variables

View Source
var AvailableStyles []string

AvailableStyles when non-nil, indicates that we can set style options, and lists those styles. Should be sorted.

View Source
var RenderStyle string

RenderStyle represents how the table should be styled.

Functions

func Supported

func Supported() bool

Supported indicates that we have a terminal table provider loaded.

Types

type Alignment

type Alignment int

Alignment indicates our table column alignments. We only use per-column alignment and do not pass through any per-cell alignments.

const (
	UNSET Alignment = iota
	LEFT
	CENTER
	RIGHT
)

These constants define how a given column of the table should have each cell aligned.

type Table

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

A Table encapsulates our terminal table object from the dependency.

func New

func New() *Table

New gives us a new empty table, configured for our basic requirements.

func (*Table) AddHeaders

func (t *Table) AddHeaders(headers ...interface{})

AddHeaders takes a sequence of header-names for each column, and configures them as the header row.

func (*Table) AddRow

func (t *Table) AddRow(cells ...interface{})

AddRow takes a sequence of cells for one table body row.

func (*Table) AddSeparator

func (t *Table) AddSeparator()

AddSeparator adds one row to the table, as a separator.

func (*Table) AlignColumn

func (t *Table) AlignColumn(column int, ourAlign Alignment)

AlignColumn sets the alignment of one column in a given table. It counts columns starting from 1.

func (*Table) Empty

func (t *Table) Empty() bool

Empty is a predicate indicating if any real content has been added.

func (*Table) Render

func (t *Table) Render() string

Render gives us the full table as a string for display. FIXME: why can't we return an error here?

func (*Table) SetSkipableColumn

func (t *Table) SetSkipableColumn(column int)

SetSkipableColumn sets a column as skipable in some contexts (typically if every entry is empty).

Jump to

Keyboard shortcuts

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