Documentation
¶
Overview ¶
Package termtext deals with monospace text as interpreted by terminals.
Index ¶
- Variables
- func AlignCenter(s string, w int) string
- func AlignLeft(s string, w int) string
- func AlignRight(s string, w int) string
- func Expand(s string) string
- func Slice(s string, start, stop int) string
- func Width(s string) int
- func WordWrap(s string, w int, prefix string) string
- func Wrap(s string, w int, prefix string) string
Constants ¶
This section is empty.
Variables ¶
var TabWidth = 8
Number of spaces to count a tab as.
var Widths map[rune]int
Widths sets the width for the given runes.
This can be useful in some cases where the written text is different. For example when encoding JSON some characters get written as a \-escape. To account for this, you can override the width for those:
termtext.Escapes = map[rune]int{
'\b': 2,
'\f': 2,
'\n': 2,
'\r': 2,
'\t': 2,
}
Functions ¶
func AlignCenter ¶
AlignCenter centre-aligns a string, filling up any remaining width with spaces.
Tabs will be expanded to spaces.
func AlignLeft ¶
AlignLeft left-aligns a string, filling up any remaining width with spaces.
Tabs will be expanded to spaces.
func AlignRight ¶
AlignRight right-aligns a string, filling up any remaining width with spaces.
Tabs will be expanded to spaces.
func Slice ¶
Slice a string by character index. This works the same as str[n:m] slicing.
Tabs will be expanded to spaces.
func Width ¶
Width gets the display width of a string.
The "display width" is the number of columns a string will occupy in a monospace terminal.
Types ¶
This section is empty.