table

package
v3.2.3 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// StyleDefault - MySql-like table style:
	StyleDefault = Style{
		HeadColor: "",
		RowColor:  "",
		Border: BorderStyle{

			TopLeft:      '+',
			Top:          '-',
			TopIntersect: '+',
			TopRight:     '+',

			Right: '|',
			Cell:  '|',

			BottomRight:     '+',
			Bottom:          '-',
			BottomLeft:      '+',
			BottomIntersect: '+',
		},
		Divider: DividerStyle{},
	}

	StyleSimple   = Style{}
	StyleMarkdown = Style{}
)

Functions

This section is empty.

Types

type BorderStyle added in v3.1.1

type BorderStyle struct {
	TopLeft, Top, TopIntersect, TopRight rune

	Right, Center, Cell, Left rune

	BottomRight, Bottom, BottomIntersect, BottomLeft rune
}

BorderStyle for table

type Cell added in v3.1.1

type Cell struct {
	// Width is the width of the cell
	Width int
	// Wrap when true wraps the contents of the cell when the length exceeds the width
	Wrap bool
	// Align when true aligns contents to the right
	Align strutil.PosFlag

	// Val is the cell data
	Val any
	// contains filtered or unexported fields
}

Cell represents a column in a row

func (*Cell) MaxWidth added in v3.1.1

func (c *Cell) MaxWidth() int

MaxWidth returns the max width of all the lines in a cell

func (*Cell) String added in v3.1.1

func (c *Cell) String() string

String returns the string formatted representation of the cell

type DividerStyle added in v3.1.1

type DividerStyle struct {
	Left      rune
	Right     rune
	Intersect rune
}

DividerStyle defines table divider style

type OpFunc added in v3.1.1

type OpFunc func(opts *Options)

OpFunc define

type Options added in v3.1.1

type Options struct {
	TitleStyle  string
	HeaderStyle string

	BottomBorder []rune

	Alignment   strutil.PosFlag
	ColMaxWidth int
	LineNumber  bool
	WrapContent bool

	// HasBorder show border line
	HasBorder bool
	// RowBorder show row border
	RowBorder bool
	// HeadBorder show head border
	HeadBorder bool
	// WrapBorder wrap border for table
	WrapBorder bool
}

Options struct

type Row added in v3.1.1

type Row struct {
	// Cells is the group of cell for the row
	Cells []*Cell

	// Separator for table columns
	Separator rune
}

Row represents a row in a table

type Style added in v3.1.1

type Style struct {
	Border  BorderStyle
	Divider DividerStyle

	HeadColor string
	RowColor  string
}

Style for table

━━━┯━━━━━━━┯━━━━━━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━
 # │ pid   │ name            │ status   │ cpu
───┼───────┼─────────────────┼──────────┼──────────
 0 │   992 │ chrome          │ Sleeping │ 6.988768
 2 │ 13973 │ qemu-system-x86 │ Sleeping │ 4.996551
━━━┷━━━━━━━┷━━━━━━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━

+-----+------------+-----------+--------+-----------------------------+
|   # | FIRST NAME | LAST NAME | SALARY |                             |
+-----+------------+-----------+--------+-----------------------------+
|   1 | Arya       | Stark     |   3000 |                             |
|  20 | Jon        | Snow      |   2000 | You know nothing, Jon Snow! |
| 300 | Tyrion     | Lannister |   5000 |                             |
+-----+------------+-----------+--------+-----------------------------+
|     |            | TOTAL     |  10000 |                             |
+-----+------------+-----------+--------+-----------------------------+

type Table

type Table struct {
	show.Base // use for internal

	// Title for the table
	Title string
	// Heads the table head data
	Heads []string
	// Rows table data rows
	Rows []*Row
	// contains filtered or unexported fields
}

Table a cli Table show

func New added in v3.1.1

func New(title string, fns ...OpFunc) *Table

New create table

func (*Table) AddHead added in v3.1.1

func (t *Table) AddHead(names ...string) *Table

AddHead column names to table

func (*Table) AddRow added in v3.1.1

func (t *Table) AddRow(cols ...any)

AddRow data to table

func (*Table) Format added in v3.1.1

func (t *Table) Format()

Format as string

func (*Table) Print added in v3.1.1

func (t *Table) Print()

Print formatted message

func (*Table) Println added in v3.1.1

func (t *Table) Println()

Println formatted message with newline

func (*Table) Render added in v3.1.1

func (t *Table) Render()

Render formatted message with newline

func (*Table) SetRows added in v3.1.1

func (t *Table) SetRows(rs any) *Table

SetRows to table

func (*Table) String added in v3.1.1

func (t *Table) String() string

String format as string

func (*Table) WithOptions added in v3.1.1

func (t *Table) WithOptions(fns ...OpFunc) *Table

WithOptions for table

func (*Table) WriteTo added in v3.1.1

func (t *Table) WriteTo(w io.Writer) (int64, error)

WriteTo format table to string and write to w.

Jump to

Keyboard shortcuts

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