tablew

package module
v2.0.6 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: Apache-2.0 Imports: 11 Imported by: 4

Documentation

Index

Constants

View Source
const (
	CENTER  = "+"
	ROW     = "-"
	COLUMN  = "|"
	SPACE   = " "
	NEWLINE = "\n"
)
View Source
const (
	ALIGN_DEFAULT = iota
	ALIGN_CENTER
	ALIGN_RIGHT
	ALIGN_LEFT
)
View Source
const (
	BgBlackColor int = iota + 40
	BgRedColor
	BgGreenColor
	BgYellowColor
	BgBlueColor
	BgMagentaColor
	BgCyanColor
	BgWhiteColor
)
View Source
const (
	FgBlackColor int = iota + 30
	FgRedColor
	FgGreenColor
	FgYellowColor
	FgBlueColor
	FgMagentaColor
	FgCyanColor
	FgWhiteColor
)
View Source
const (
	BgHiBlackColor int = iota + 100
	BgHiRedColor
	BgHiGreenColor
	BgHiYellowColor
	BgHiBlueColor
	BgHiMagentaColor
	BgHiCyanColor
	BgHiWhiteColor
)
View Source
const (
	FgHiBlackColor int = iota + 90
	FgHiRedColor
	FgHiGreenColor
	FgHiYellowColor
	FgHiBlueColor
	FgHiMagentaColor
	FgHiCyanColor
	FgHiWhiteColor
)
View Source
const (
	Normal          = 0
	Bold            = 1
	UnderlineSingle = 4
	Italic
)
View Source
const ESC = "\033"
View Source
const (
	MAX_ROW_WIDTH = 30
)
View Source
const SEP = ";"

Variables

This section is empty.

Functions

func Color

func Color(colors ...int) []int

func ConditionString

func ConditionString(cond bool, valid, inValid string) string

ConditionString Simple Condition for string Returns value based on condition

func DisplayWidth

func DisplayWidth(str string) int

func Pad

func Pad(s, pad string, width int) string

Pad String Attempts to place string in the center

func PadLeft

func PadLeft(s, pad string, width int) string

PadLeft Pad String Left position This would place string at the right side of the screen

func PadRight

func PadRight(s, pad string, width int) string

PadRight Pad String Right position This would place string at the left side of the screen

func Render

func Render(opts ...Option) string

func Structs

func Structs(vs any, opts ...Option) string

func Title

func Title(name string) string

Title Format Table Header Replace _ , . and spaces

func WrapString

func WrapString(s string, lim int) ([]string, int)

WrapString wraps s into a paragraph of lines of length lim, with minimal raggedness.

func WrapWords

func WrapWords(words []string, spc, lim, pen int) [][]string

WrapWords is the low-level line-breaking algorithm, useful if you need more control over the details of the text wrapping process. For most uses, WrapString will be sufficient and more convenient.

WrapWords splits a list of words into lines with minimal "raggedness", treating each rune as one unit, accounting for spc units between adjacent words on each line, and attempting to limit lines to lim units. Raggedness is the total error over all lines, where error is the square of the difference of the length of the line and lim. Too-long lines (which only happen when a single word is longer than lim units) have pen penalty units added to the error.

Types

type Border

type Border struct {
	Left   bool
	Right  bool
	Top    bool
	Bottom bool
}

type Colors

type Colors []int

type Option added in v2.0.5

type Option func(w *Table)

type Table

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

func NewWriter

func NewWriter(writer io.Writer) *Table

NewWriter Start New Table Take io.Writer Directly

func (*Table) Append

func (t *Table) Append(row []string)

Append row to table

func (*Table) AppendBulk

func (t *Table) AppendBulk(rows [][]string)

AppendBulk Allow Support for Bulk Append Eliminates repeated for loops

func (*Table) ClearFooter

func (t *Table) ClearFooter()

ClearFooter Clear footer

func (*Table) ClearRows

func (t *Table) ClearRows()

ClearRows Clear rows

func (*Table) EnableBorder

func (t *Table) EnableBorder(border bool)

EnableBorder Set Table Border This would enable / disable line around the table

func (*Table) NumLines

func (t *Table) NumLines() int

NumLines to get the number of lines

func (*Table) Render

func (t *Table) Render()

Render table output

func (*Table) Rich

func (t *Table) Rich(row []string, colors []Colors)

Rich Append row to table with color attributes

func (*Table) SetAlignment

func (t *Table) SetAlignment(align int)

SetAlignment Set Table Alignment

func (*Table) SetAutoFormatHeaders

func (t *Table) SetAutoFormatHeaders(auto bool)

SetAutoFormatHeaders Turn header autoformatting on/off. Default is on (true).

func (*Table) SetAutoMergeCells

func (t *Table) SetAutoMergeCells(auto bool)

SetAutoMergeCells Set Auto Merge Cells This would enable / disable the merge of cells with identical values

func (*Table) SetAutoMergeCellsByColumnIndex

func (t *Table) SetAutoMergeCellsByColumnIndex(cols []int)

SetAutoMergeCellsByColumnIndex Set Auto Merge Cells By Column Index This would enable / disable the merge of cells with identical values for specific columns If cols is empty, it is the same as `SetAutoMergeCells(true)`.

func (*Table) SetAutoWrapText

func (t *Table) SetAutoWrapText(auto bool)

SetAutoWrapText Turn automatic multiline text adjustment on/off. Default is on (true).

func (*Table) SetBorder

func (t *Table) SetBorder(border bool)

SetBorder Set Table Border This would enable / disable line around the table Deprecated: use EnableBorder

func (*Table) SetBorders

func (t *Table) SetBorders(border Border)

SetBorders SetBorder Set Custom Table Border

func (*Table) SetCaption

func (t *Table) SetCaption(caption bool, captionText ...string)

SetCaption Set table Caption

func (*Table) SetCenterSeparator

func (t *Table) SetCenterSeparator(sep string)

SetCenterSeparator Set the center Separator

func (*Table) SetColMinWidth

func (t *Table) SetColMinWidth(column int, width int)

SetColMinWidth Set the minimal width for a column

func (*Table) SetColWidth

func (t *Table) SetColWidth(width int)

SetColWidth Set the Default column width

func (*Table) SetColumnAlignment

func (t *Table) SetColumnAlignment(keys []int)

SetColumnAlignment Set Column Alignment

func (*Table) SetColumnColor

func (t *Table) SetColumnColor(colors ...Colors)

Adding column colors (ANSI codes)

func (*Table) SetColumnSeparator

func (t *Table) SetColumnSeparator(sep string)

SetColumnSeparator Set the Column Separator

func (*Table) SetFooter

func (t *Table) SetFooter(keys []string)

SetFooter Set table Footer

func (*Table) SetFooterAlignment

func (t *Table) SetFooterAlignment(fAlign int)

SetFooterAlignment Set Footer Alignment

func (*Table) SetFooterColor

func (t *Table) SetFooterColor(colors ...Colors)

Adding column colors (ANSI codes)

func (*Table) SetHeader

func (t *Table) SetHeader(keys []string)

SetHeader Set table header

func (*Table) SetHeaderAlignment

func (t *Table) SetHeaderAlignment(hAlign int)

SetHeaderAlignment Set Header Alignment

func (*Table) SetHeaderColor

func (t *Table) SetHeaderColor(colors ...Colors)

Adding header colors (ANSI codes)

func (*Table) SetHeaderLine

func (t *Table) SetHeaderLine(line bool)

SetHeaderLine Set Header Line This would enable / disable a line after the header

func (*Table) SetNewLine

func (t *Table) SetNewLine(nl string)

SetNewLine Set New Line

func (*Table) SetNoWhiteSpace

func (t *Table) SetNoWhiteSpace(allow bool)

SetNoWhiteSpace Set No White Space

func (*Table) SetReflowDuringAutoWrap

func (t *Table) SetReflowDuringAutoWrap(auto bool)

SetReflowDuringAutoWrap Turn automatic reflowing of multiline text when rewrapping. Default is on (true).

func (*Table) SetRowLine

func (t *Table) SetRowLine(line bool)

SetRowLine Set Row Line This would enable / disable a line on each row of the table

func (*Table) SetRowSeparator

func (t *Table) SetRowSeparator(sep string)

SetRowSeparator Set the Row Separator

func (*Table) SetStructs

func (t *Table) SetStructs(v interface{}) error

SetStructs sets header and rows from slice of struct. If something that is not a slice is passed, error will be returned. The tag specified by "table" for the struct becomes the header. If not specified or empty, the field name will be used. The field of the first element of the slice is used as the header. If the element implements fmt.Stringer, the result will be used. And the slice contains nil, it will be skipped without rendering.

func (*Table) SetTablePadding

func (t *Table) SetTablePadding(padding string)

SetTablePadding Set Table Padding

func (*Table) SetUnicodeHV

func (t *Table) SetUnicodeHV(horizontal, vertical UnicodeLineStyle) error

Use unicode box drawing symbols to achieve the specified line styles. Note that combinations of thick and double lines are not supported. Will return an error in case of unsupported combinations.

type TableCell added in v2.0.1

type TableCell interface {
	TableCellString() string
}

type UnicodeLineStyle

type UnicodeLineStyle int
const (
	Regular UnicodeLineStyle = iota
	Thick
	Double
)

Jump to

Keyboard shortcuts

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