gotable

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: MIT Imports: 5 Imported by: 0

README

go-table

A table writer utility

Usage

Documentation

Index

Constants

View Source
const (
	MinColumnWidth           int    = 2
	AdjustableColumnMinWidth int    = 6
	UnfinishedCellTailer     string = " ~"
)

Variables

View Source
var (
	ErrColumnAlreadyExist       = errors.New("column already exist")
	ErrColumnNotExist           = errors.New("column does not exist")
	ErrEnforcingTableWidth      = errors.New("enforcing table width failed")
	ErrFieldIsMissing           = errors.New("field is missing")
	ErrInsufficientColumnHeight = errors.New("insufficient column height")
	ErrInsufficientColumnWidth  = errors.New("insufficient column width")
	ErrInvalidCellHeight        = errors.New("invalid cell height")
	ErrInvalidCellWidth         = errors.New("invalid cell width")
	ErrNoAdjustableColumn       = errors.New("no adjustable column")
	ErrRenderTableFailed        = errors.New("render table failed")
	ErrTableNotEmpty            = errors.New("table is not empty")
)

Functions

This section is empty.

Types

type Align

type Align int
const (
	AlignDefault Align = iota // same as AlignLeft
	AlignLeft                 // "left        "
	AlignCenter               // "   center   "
	AlignJustify              // "justify   it"
	AlignRight                // "       right"
)

type Cell

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

func (*Cell) Padding

func (a *Cell) Padding(l, r string)

func (*Cell) String

func (a *Cell) String() string

func (*Cell) Style

func (a *Cell) Style(tss ...TextStyle)

func (*Cell) Value

func (a *Cell) Value(data any)

type Column

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

func NewStandardColumn

func NewStandardColumn(name string) *Column

func NewTreePathColumn

func NewTreePathColumn(sty TreePathStyle) *Column

func (*Column) BodyStyle

func (a *Column) BodyStyle(sty *ColumnStyle) *Column

func (*Column) HeaderStyle

func (a *Column) HeaderStyle(sty *ColumnStyle) *Column

func (*Column) Hidden

func (a *Column) Hidden(b bool) *Column

func (*Column) Name

func (a *Column) Name() string

func (*Column) Padding

func (a *Column) Padding(p rune, l, r string) *Column

func (*Column) Width

func (a *Column) Width(limit int, autoControl bool) *Column

type ColumnOverFlowAction

type ColumnOverFlowAction int
const (
	Wordwrap ColumnOverFlowAction = iota
	Truncate
	Exception
)

type ColumnStyle

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

func DefauleBodyStyle

func DefauleBodyStyle() *ColumnStyle

func DefauleHeaderStyle

func DefauleHeaderStyle() *ColumnStyle

func DefauleTreeStyle

func DefauleTreeStyle() *ColumnStyle

func (*ColumnStyle) Align

func (a *ColumnStyle) Align(al Align) *ColumnStyle

func (*ColumnStyle) EscapeLineFeed

func (a *ColumnStyle) EscapeLineFeed(b bool) *ColumnStyle

func (*ColumnStyle) OverFlowAction

func (a *ColumnStyle) OverFlowAction(ofa ColumnOverFlowAction) *ColumnStyle

func (*ColumnStyle) Text

func (a *ColumnStyle) Text(st ...TextStyle) *ColumnStyle

type ColumnWidthControl

type ColumnWidthControl int
const (
	AutoExpand ColumnWidthControl = iota
	NoAutoExpand
)

type DataCell

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

type Output

type Output int
const (
	Console Output = iota
	ReStructuredText
	Yaml
	Json
)

type Row

type Row []*Cell

type StandardColumn

type StandardColumn struct {
}

type Table

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

func NewTable

func NewTable(l *TableLayout) *Table

func (*Table) AppendColumn

func (a *Table) AppendColumn(cs ...*Column) (*Table, error)

func (*Table) AppendRow

func (a *Table) AppendRow(c ...any) error

AppendRow add construct a table row from []any and append to the table

func (*Table) AppendRowM

func (a *Table) AppendRowM(m map[string]any) error

AppendRowM add construct a table row from a Row and append to the table

func (*Table) AppendTrees

func (a *Table) AppendTrees(sty TreePathStyle, ns ...TreeNodeReader) error

func (*Table) Cell

func (a *Table) Cell(col, row int) *Cell

func (*Table) GetColumn

func (a *Table) GetColumn(name string) (*Column, error)

func (*Table) Render

func (a *Table) Render(o Output) (string, error)

func (*Table) ResetData

func (a *Table) ResetData()

type TableLayout

type TableLayout struct {
	HeaderTopLeft          rune
	HeaderTopRight         rune
	HeaderTopSeparator     rune
	HeaderTopHorizontal    rune
	HeaderLeft             rune
	HeaderRight            rune
	HeaderSeparator        rune
	HeaderBottomLeft       rune
	HeaderBottomRight      rune
	HeaderBottomSeparator  rune
	HeaderBottomHorizontal rune
	BodyTopLeft            rune
	BodyTopRight           rune
	BodyTopSeparator       rune
	BodyTopHorizontal      rune
	BodyBottomLeft         rune
	BodyBottomRight        rune
	BodyBottomSeparator    rune
	BodyBottomHorizontal   rune
	RowLeft                rune
	RowRight               rune
	RowSeparator           rune
	RowHorizontal          rune
	ColumnSeparator        rune
	ColumnPaddingLeft      string
	ColumnPaddingRight     string
	CellPadding            string

	ShowHeader             bool
	ShowHeaderTopBorder    bool
	ShowHeaderBottemBorder bool
	ShowBodyTopBorder      bool
	ShowBodyBottomBorder   bool
	ShowSideBorder         bool
	ShowColumnSeparator    bool
	ShowRowSeparator       bool

	Width int
}

func DefaultTableLayout

func DefaultTableLayout() *TableLayout

func LightTableLayout

func LightTableLayout() *TableLayout

func (*TableLayout) HideHeader

func (a *TableLayout) HideHeader() *TableLayout

func (*TableLayout) HideOutterBorder

func (a *TableLayout) HideOutterBorder() *TableLayout

func (*TableLayout) SplitHeaderAndBody

func (a *TableLayout) SplitHeaderAndBody() *TableLayout

type TableStats

type TableStats struct {
	ColumnWidths []int
	RowHeights   []int
	HeaderHeight int
}

type TextStyle

type TextStyle int
const (
	None TextStyle = iota
	Bold
	Red
	Green
	Yellow
	Blue
	BgRed
	BgGreen
	BgYellow
	BgBlue
)

type TreeNodeReader

type TreeNodeReader interface {
	Children() []TreeNodeReader
	Fields() map[string]any
}

type TreePathCell

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

type TreePathColumn

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

type TreePathStyle

type TreePathStyle struct {
	Name          string
	Root          string
	Middle        string
	Terminal      string
	PadLine       string
	PadBlank      string
	Children      string
	PrefixLeveled string
	PrefixBlank   string
	// contains filtered or unexported fields
}

func DefaultTreePathStyle

func DefaultTreePathStyle() *TreePathStyle

func LightTreePathStyle

func LightTreePathStyle() *TreePathStyle

func (*TreePathStyle) Body

func (a *TreePathStyle) Body(ss ...TextStyle) *TreePathStyle

func (*TreePathStyle) Header

func (a *TreePathStyle) Header(ss ...TextStyle) *TreePathStyle

func (TreePathStyle) ReplacePathAsExtention

func (a TreePathStyle) ReplacePathAsExtention(s string) string

type TreeStatistics

type TreeStatistics struct {
	MaxDepth int
}

Directories

Path Synopsis
examples
console command

Jump to

Keyboard shortcuts

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