table

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2023 License: Apache-2.0, MIT Imports: 6 Imported by: 1

README

table

codecov Go Report Card Go Reference Go

A simple library to create nested tables in the terminal.

Installation

go get github.com/data-preservation-programs/table@latest

Example Usage

type Person struct {
	ID           int
	Name         string
	AverageScore int     `table:"header:Average Score"`
	Grade        string  `table:"color:96;headerColor:96,4"`
	Scores       []Score `table:"headerColor:34,4;expand"`
}

type Score struct {
	Subject  string
	Score    float32
	GradedAt time.Time `table:"header:Graded At;format:2006-01-02"`
}

func main () {
    fmt.Println(table.New().Render([]Person{...}))
}

demo.png

Supported Tags

  • header The header string to use for the column.
  • headerColor The color to use for the header. The color is specified as a comma separated list of color codes. Check available values here
  • color The color to use for the column. The color is specified as a comma separated list of color codes. Check available values here
  • format The format to use for the column. For time.Time, the format is specified as a Go time layout. For all other types, the format is specified as a Go format string.
  • verbose If set to true, the column will be displayed only when the verbose is set to true in the Table.
  • expand If set to true, the column will be expanded to a sub table. The column needs to be a slice/instance/pointer to a struct.
  • - If specified, the column will be hidden.

Supported Options

  • Table.WithTab Set the tab string that is appended to the sub-tables.
  • Table.WithVerbose Columns with verbose tag is only displayed when the verbose is set to true.
  • Table.WithPaddingSize Set the padding size for each column which is the minimum padding between the columns.
  • Table.WithHeaderRowColor Overrides the default header row color.
  • Table.WithFirstColumnColor Overrides the default first column color.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Table)

func WithFirstColumnColor added in v0.0.2

func WithFirstColumnColor(c *color.Color) Option

func WithHeaderRowColor

func WithHeaderRowColor(c *color.Color) Option

func WithPaddingSize

func WithPaddingSize(p int) Option

func WithTab

func WithTab(p string) Option

func WithVerbose

func WithVerbose() Option

type Table

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

func New

func New(opts ...Option) *Table

func (*Table) Render

func (t *Table) Render(v any) string

Jump to

Keyboard shortcuts

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