zgo.at/termtext Index | Files

package termtext

import "zgo.at/termtext"

Package termtext deals with monospace text as interpreted by terminals.

Index

Package Files

termtext.go

Variables

var TabWidth = 8

Number of spaces to count a tab as.

func AlignCenter

func AlignCenter(s string, w int) string

AlignCenter centre-aligns a string, filling up any remaining width with spaces.

Tabs will be expanded to spaces.

func AlignLeft

func AlignLeft(s string, w int) string

AlignLeft left-aligns a string, filling up any remaining width with spaces.

Tabs will be expanded to spaces.

func AlignRight

func AlignRight(s string, w int) string

AlignRight right-aligns a string, filling up any remaining width with spaces.

Tabs will be expanded to spaces.

func Expand

func Expand(s string) string

Expand tabs to spaces.

func Slice

func Slice(s string, start, stop int) string

Slice a string by character index. This works the same as str[n:m] slicing.

Tabs will be expanded to spaces.

func Width

func Width(s string) int

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

func WordWrap(s string, w int, prefix string) string

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

func Wrap(s string, w int, prefix string) string

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.

Version
v1.0.0 (latest)
Published
Apr 17, 2022
Platform
linux/amd64
Imports
5 packages (graph)
Last checked
1 month ago

Tools for package owners.