Documentation
¶
Overview ¶
Package textwrap provides dependency-free helpers for reflowing plain text to a fixed column width.
Index ¶
- Constants
- func Dedent(text string) string
- func Indent(text, prefix string) string
- func IndentLines(lines []string, prefix string) []string
- func Truncate(ctx context.Context, text string, width int) (string, error)
- func TruncateLines(ctx context.Context, lines []string, width int) ([]string, error)
- func Wrap(ctx context.Context, text string, width int) ([]string, error)
- func WrapString(ctx context.Context, text string, width int) (string, error)
Constants ¶
const Ellipsis = "…"
Ellipsis is appended to text that Truncate shortens.
Variables ¶
This section is empty.
Functions ¶
func Dedent ¶
Dedent removes the longest common leading whitespace shared by all non-blank lines of text. Blank lines never constrain the calculation, and lines without the common prefix are returned unchanged.
func Indent ¶
Indent prefixes every non-empty line of text with prefix. Blank lines are left untouched so paragraph structure stays visible.
func IndentLines ¶
IndentLines returns a copy of lines with prefix prepended to every non-empty entry. The input slice is never modified.
func Truncate ¶
Truncate shortens text to at most width runes. Text that already fits is returned unchanged. Shortened text ends with Ellipsis, which counts toward width; when width is not larger than the ellipsis itself the ellipsis is cut down to width.
Truncate returns an error when width is smaller than one.
func TruncateLines ¶
TruncateLines returns a copy of lines with every entry truncated to at most width runes. The input slice is never modified.
func Wrap ¶
Wrap reflows text so that every returned line is at most width runes long. Every line break in text starts a new output line and blank input lines stay blank. Runs of spaces, tabs, and other whitespace collapse to a single space. Words longer than width are hard-split so the width guarantee always holds.
Wrap returns an error when width is smaller than one.
Types ¶
This section is empty.