package termtext
import "zgo.at/termtext"
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
Variables ¶
var TabWidth = 8
Number of spaces to count a tab as.
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 Expand ¶
Expand tabs 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.
func WordWrap ¶
WordWrap wraps lines to be at most w characters wide, but doesn't break in the middle of words.
Lines will be prefixed with prefix. The prefix isn't counted in line length calculations.
Tabs will be expanded to spaces.
func Wrap ¶
Wrap lines to be at most w characters wide.
Lines will be prefixed with prefix. The prefix isn't counted in line length calculations.
This does not use word wrap, use WordWrap() for this instead.
Tabs will be expanded to spaces.
Source Files ¶
termtext.go
- Version
- v1.5.0 (latest)
- Published
- May 22, 2024
- Platform
- linux/amd64
- Imports
- 5 packages
- Last checked
- 3 hours ago –
Tools for package owners.