Documentation ¶
Overview ¶
Package strutil provides various utilities for manipulating strings nolint
nolint
nolint
Index ¶
- Variables
- func Join(list []string, delim string) string
- func PadLeft(str string, length int, pad byte) string
- func PadRight(str string, length int, pad byte) string
- func Resize(s string, length uint, rightAlign bool) string
- func RuneWidth(s rune) int
- func StringWidth(s string) int
- func Strip(s string) string
- func WrapString(s string, lim uint) string
- type Cell
- type Row
- type Table
Constants ¶
This section is empty.
Variables ¶
var Separator = "\t"
Separator is the default column seperator
Functions ¶
func Join ¶
Join joins the list of the string with the delim provided. Returns an empty string for empty list
func PadLeft ¶
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 ¶
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 ¶
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 StringWidth ¶
StringWidth returns the actual width of the string without colors
func WrapString ¶
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
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
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