Documentation
¶
Overview ¶
Package text is a set of utility functions for text processing and outputting to the terminal.
Index ¶
- func DisplayWidth(s string) int
- func FuzzyAgo(a, b time.Time) string
- func Indent(s, indent string) string
- func PadRight(maxWidth int, s string) string
- func Pluralize(num int, thing string) string
- func RelativeTimeAgo(a, b time.Time) string
- func RemoveDiacritics(value string) string
- func Truncate(maxWidth int, s string) string
- type FormatSliceBuilder
- func (b *FormatSliceBuilder) String() string
- func (b *FormatSliceBuilder) WithAppend(s string) *FormatSliceBuilder
- func (b *FormatSliceBuilder) WithDefault(d []string) *FormatSliceBuilder
- func (b *FormatSliceBuilder) WithIndent(n int) *FormatSliceBuilder
- func (b *FormatSliceBuilder) WithLineLength(n int) *FormatSliceBuilder
- func (b *FormatSliceBuilder) WithPrepend(s string) *FormatSliceBuilder
- func (b *FormatSliceBuilder) WithSort(yes bool) *FormatSliceBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DisplayWidth ¶
DisplayWidth calculates what the rendered width of string s will be.
func Indent ¶
Indent returns a copy of the string s with indent prefixed to it, will apply indent to each line of the string.
func PadRight ¶ added in v0.1.0
PadRight returns a copy of the string s that has been padded on the right with whitespace to fit the maximum display width.
func Pluralize ¶
Pluralize returns a concatenated string with num and the plural form of thing if necessary.
func RelativeTimeAgo ¶
RelativeTimeAgo returns a human readable string of the time duration between a and b that is estimated to the nearest unit of time.
func RemoveDiacritics ¶
RemoveDiacritics returns the input value without "diacritics", or accent marks.
Types ¶
type FormatSliceBuilder ¶ added in v0.5.0
type FormatSliceBuilder struct {
// contains filtered or unexported fields
}
FormatSliceBuilder provides a fluent API to format string slices.
func NewSliceFormatter ¶ added in v0.5.0
func NewSliceFormatter(items []string) *FormatSliceBuilder
NewSliceFormatter constructs a builder for the provided items.
func (*FormatSliceBuilder) String ¶ added in v0.5.0
func (b *FormatSliceBuilder) String() string
String formats the slice according to the builder configuration.
func (*FormatSliceBuilder) WithAppend ¶ added in v0.5.0
func (b *FormatSliceBuilder) WithAppend(s string) *FormatSliceBuilder
WithAppend sets a string to place after each element.
func (*FormatSliceBuilder) WithDefault ¶ added in v0.5.0
func (b *FormatSliceBuilder) WithDefault(d []string) *FormatSliceBuilder
WithDefault sets the default slice to use when items is nil or empty.
func (*FormatSliceBuilder) WithIndent ¶ added in v0.5.0
func (b *FormatSliceBuilder) WithIndent(n int) *FormatSliceBuilder
WithIndent sets the number of spaces to indent the first column.
func (*FormatSliceBuilder) WithLineLength ¶ added in v0.5.0
func (b *FormatSliceBuilder) WithLineLength(n int) *FormatSliceBuilder
WithLineLength sets the maximum line length. Non-positive values disable wrapping.
func (*FormatSliceBuilder) WithPrepend ¶ added in v0.5.0
func (b *FormatSliceBuilder) WithPrepend(s string) *FormatSliceBuilder
WithPrepend sets a string to place before each element.
func (*FormatSliceBuilder) WithSort ¶ added in v0.5.0
func (b *FormatSliceBuilder) WithSort(yes bool) *FormatSliceBuilder
WithSort enables or disables sorting of the elements.