Documentation ¶
Index ¶
- func AndString(vals ...string) string
- func ArrayFormatter(values []string) string
- func DateStringer(date time.Time) string
- func FixTabStop(init, tabSize int, spacing, str string) (string, int)
- func LongestLine[T any](table [][]T) int
- func OrString(vals ...string) string
- func StringsJoiner[T fmt.Stringer](values []T, sep string) string
- func TabAlign(table [][]string, column int, tabSize int) ([][]string, error)
- func TableEntriesAlign(table [][]string, tabSize int) ([][]string, error)
- func TimeStringer(time time.Time) string
- type TableAligner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AndString ¶
AndString concatenates a list of strings using commas and the word "and" before the last string.
Parameters:
- vals: The list of strings to concatenate.
Returns:
- string: The concatenated string.
func ArrayFormatter ¶ added in v0.3.8
ArrayFormatter formats a list of strings as an array.
Parameters:
- values: The list of strings to format.
Returns:
- string: The formatted array.
func DateStringer ¶
DateStringer prints the date in the format "1st January, 2006".
Parameters:
- date: The date to print.
Returns:
- string: The date in the format "1st January, 2006".
func FixTabStop ¶ added in v0.3.27
FixTabStop fixes the tab stops in a string.
The initial level and the integer return are used for chaining multiple calls to this function.
Parameters:
- init: The initial level of the tab stop.
- tabSize: The size of the tab.
- spacing: The spacing to use for the tab stop.
- str: The string to fix the tab stops for.
Returns:
- string: The string with the tab stops fixed.
- int: The total number of characters in the string.
Behaviors:
- If the tabSize is less than 1, it is set to 1.
- If the initial tab stop is less than 0, it is set to 0.
- If the string is empty, an empty string is returned.
func LongestLine ¶ added in v0.3.18
LongestLine finds the longest line in a table.
Parameters:
- table: The table to find the longest line in.
Returns:
- int: The length of the longest line. -1 if the table is empty.
func OrString ¶
OrString concatenates a list of strings using commas and the word "or" before the last string.
Parameters:
- vals: The list of strings to concatenate.
Returns:
- string: The concatenated string.
func StringsJoiner ¶ added in v0.2.36
StringsJoiner joins a list of fmt.Stringer values using a separator.
Parameters:
- values: The list of fmt.Stringer values to join.
- sep: The separator to use when joining the strings.
Returns:
- string: The string representation of the values.
func TabAlign ¶ added in v0.3.18
TabAlign aligns the tabs of a table's column.
Parameters:
- table: The table to align.
- column: The column to align.
- tabSize: The size of the tab.
Returns:
- [][]string: The aligned table.
- error: An error of type *errors.ErrInvalidParameter if the tabSize is less than 1 or the column is less than 0.
Behaviors:
- If the column is not found in the table, the table is returned as is.
func TableEntriesAlign ¶ added in v0.3.18
TableEntriesAlign aligns the entries of a table.
Parameters:
- table: The table to align.
- tabSize: The size of the tab.
Returns:
- [][]string: The aligned table.
- error: An error if there was an issue aligning the table.
Errors:
- *errors.ErrAt: If there was an issue aligning a specific column.
- *errors.ErrInvalidParameter: If the tabSize is less than 1.
func TimeStringer ¶
TimeStringer prints the time in the format "3:04 PM".
Parameters:
- time: The time to print.
Returns:
- string: The time in the format "3:04 PM".
Types ¶
type TableAligner ¶ added in v0.3.32
type TableAligner struct {
// contains filtered or unexported fields
}
TableAligner is a struct to help align tables.
func NewTableAligner ¶ added in v0.3.32
func NewTableAligner() *TableAligner
NewTableAligner creates a new table aligner.
func (*TableAligner) AddRow ¶ added in v0.3.32
func (ta *TableAligner) AddRow(elems ...string)
AddRow adds a row to the table.
Parameters:
- elems: The elements of the row.
func (*TableAligner) AlignColumn ¶ added in v0.3.33
func (ta *TableAligner) AlignColumn(idx int)
AlignColumn specifies a row to align.
Parameters:
- idx: The index of the row to align.
Behaviors:
- If the index is less than 0, the function does nothing.
func (*TableAligner) Build ¶ added in v0.3.32
func (ta *TableAligner) Build(tabSize int, tableIndent bool) ([]string, error)
Accept accepts the table aligner.
Parameters:
- tabSize: The size of the tab.
- tableIndent: Whether to indent the table.
Returns:
- error: An error of type *errors.ErrInvalidParameter if the tabSize is less than 1.
func (*TableAligner) Reset ¶ added in v0.3.32
func (ta *TableAligner) Reset()
Reset resets the table aligner for reuse.
func (*TableAligner) SetHead ¶ added in v0.3.32
func (ta *TableAligner) SetHead(head string)
SetHead sets the head of the table.
Parameters:
- head: The head of the table.