uitable

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package strutil provides various utilities for manipulating strings nolint

nolint

nolint

Index

Constants

This section is empty.

Variables

View Source
var Separator = "\t"

Separator is the default column seperator

Functions

func Join

func Join(list []string, delim string) string

Join joins the list of the string with the delim provided. Returns an empty string for empty list

func PadLeft

func PadLeft(str string, length int, pad byte) string

PadLeft returns a new string of a specified length in which the beginning of the current string is padded with spaces or with a specified Unicode character.

func PadRight

func PadRight(str string, length int, pad byte) string

PadRight returns a new string of a specified length in which the end of the current string is padded with spaces or with a specified Unicode character.

func Resize

func Resize(s string, length uint, rightAlign bool) string

Resize resizes the string with the given length. It ellipses with '...' when the string's length exceeds the desired length or pads spaces to the right of the string when length is smaller than desired

func RuneWidth

func RuneWidth(s rune) int

RuneWidth returns the actual width of the rune

func StringWidth

func StringWidth(s string) int

StringWidth returns the actual width of the string without colors

func Strip

func Strip(s string) string

Strip strips the string of all colors

func WrapString

func WrapString(s string, lim uint) string

WrapString wraps the given string within lim width in characters.

Wrapping is currently naive and only happens at white-space. A future version of the library will implement smarter wrapping. This means that pathological cases can dramatically reach past the limit, such as a very long word.

Types

type Cell

type Cell struct {
	// Width is the width of the cell
	Width uint

	// Wrap when true wraps the contents of the cell when the lenght exceeds the width
	Wrap bool

	// RightAlign when true aligns contents to the right
	RightAlign bool

	// Data is the cell data
	Data interface{}
}

Cell represents a column in a row

func (*Cell) LineWidth

func (c *Cell) LineWidth() uint

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

func (*Cell) String

func (c *Cell) String() string

String returns the string formated representation of the cell

type Row

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

	// Separator for tabular columns
	Separator string
}

Row represents a row in a table

func NewRow

func NewRow(data ...interface{}) *Row

NewRow returns a new Row and adds the data to the row

func (*Row) String

func (r *Row) String() string

String returns the string representation of the row

type Table

type Table struct {
	// Rows is the collection of rows in the table
	Rows []*Row

	// MaxColWidth is the maximum allowed width for cells in the table
	MaxColWidth uint

	// Wrap when set to true wraps the contents of the columns when the length exceeds the MaxColWidth
	Wrap bool

	// Separator is the seperator for columns in the table. Default is "\t"
	Separator string
	// contains filtered or unexported fields
}

Table represents a decorator that renders the data in formatted in a table

func New

func New() *Table

New returns a new Table with default values

func (*Table) AddRow

func (t *Table) AddRow(data ...interface{}) *Table

AddRow adds a new row to the table

func (*Table) Bytes

func (t *Table) Bytes() []byte

Bytes returns the []byte value of table

func (*Table) RightAlign

func (t *Table) RightAlign(col int)

func (*Table) String

func (t *Table) String() string

String returns the string value of table

Jump to

Keyboard shortcuts

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