table

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: BSD-3-Clause Imports: 7 Imported by: 1

Documentation

Overview

Package table implements utilities for rendering tables and managing table data.

The template funcs registered by this package are:

  • Table [ string | *Format ]
  • EndTable
  • Headers <[]string>
  • Footers <[]string>
  • Row
  • Cell <string>

The Table function takes an optional argument which is the name of a format or a value to use for formatting the table. To conclude the table, use EndTable. Headers/Footers appears optionally to denote the names of the headers. Row must be used to group together cells. The content of each cell is passed to the Cell function.

"Default" and "Unformatted" are the built-in Formats

A viable table looks like:

{{- Table "Unformatted" -}}
{{- Headers "First" "Last" }}
{{- Row -}}
{{- Cell "George" -}}
{{- Cell "Burdell" -}}
{{- EndTable -}}`

Additional formats can be registered using the RegisterTableFormat action.

When you want to display tabular data in the CLI, you can use the RegisterTable function to give the table a name and specify

Index

Constants

View Source
const (
	// UseTablesInHelpTemplate causes tables to be used in the help template
	UseTablesInHelpTemplate = Feature(1 << iota)

	// TemplateFuncs enables the template funcs feature, which provides template funcs
	// for colors and styles
	TemplateFuncs

	// AllFeatures enables all of the features.  This is the default
	AllFeatures = -1
)
View Source
const (
	// Unformatted is the table format associated with a table with no boxes or alignments
	Unformatted = "Unformatted"

	// Porcelain is a table that only uses tabs to separate columns
	Porcelain = "Porcelain"
)
View Source
const (
	AlignDefault Alignment = tablewriter.ALIGN_DEFAULT
	AlignCenter            = tablewriter.ALIGN_CENTER
	AlignRight             = tablewriter.ALIGN_RIGHT
	AlignLeft              = tablewriter.ALIGN_LEFT
)

Align constants

Variables

This section is empty.

Functions

func RegisterHelpTemplates

func RegisterHelpTemplates() cli.Action

RegisterHelpTemplates causes various templates used in the default help template to be overridden with ones that use tables

func RegisterTemplateFuncs

func RegisterTemplateFuncs() cli.Action

RegisterTemplateFuncs provides the template functions described in the package overview:

  • Table
  • EndTable
  • Headers
  • Footers
  • Row, and
  • Cell

Types

type Alignment

type Alignment int

Alignment defines how table cell contents are aligned

type Feature

type Feature int

Feature provides a name for each feature in the extension

func (Feature) Pipeline

func (f Feature) Pipeline() cli.Action

type Format

type Format struct {
	Alignment             Alignment
	AutoFormatHeaders     bool
	AutoWrapText          bool
	Border                bool
	CenterSeparator       string
	ColumnSeparator       string
	ColWidth              int
	HeaderAlignment       Alignment
	HeaderLine            bool
	NoWhiteSpace          bool
	RowLine               bool
	RowSeparator          string
	TablePadding          string
	TopLeftSeparator      string
	TopCenterSeparator    string
	TopRightSeparator     string
	CenterLeftSeparator   string
	CenterRightSeparator  string
	BottomLeftSeparator   string
	BottomCenterSeparator string
	BottomRightSeparator  string
}

Format defines the optional format for tables

type Options

type Options struct {
	// Features enumerates which features to use
	Features Feature
}

Options is the configuration for the table extension and provides the initializer for the app initialization pipeline

func (Options) Execute

func (o Options) Execute(c context.Context) error

Jump to

Keyboard shortcuts

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