Documentation
¶
Overview ¶
Package text provides pure text/string utility functions. All functions are ANSI-aware where relevant (counting visible width, truncation, padding). This is a leaf package with zero internal imports.
Index ¶
- func CountVisibleWidth(s string) int
- func FirstLine(s string) string
- func Indent(s string, spaces int) string
- func JoinNonEmpty(sep string, parts ...string) string
- func LineCount(s string) int
- func PadCenter(s string, width int) string
- func PadLeft(s string, width int) string
- func PadRight(s string, width int) string
- func Repeat(s string, n int) string
- func Slugify(s string) string
- func StripANSI(s string) string
- func Truncate(s string, width int) string
- func TruncateMiddle(s string, width int) string
- func WordWrap(s string, width int) string
- func WrapLines(s string, width int) []string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CountVisibleWidth ¶
CountVisibleWidth returns the visible width of a string, excluding ANSI codes.
func JoinNonEmpty ¶
JoinNonEmpty joins non-empty strings with the given separator.
func PadCenter ¶
PadCenter centers a string within the specified width. ANSI-aware: counts visible characters only.
func PadLeft ¶
PadLeft pads a string on the left to the specified width. ANSI-aware: counts visible characters only.
func PadRight ¶
PadRight pads a string on the right to the specified width. ANSI-aware: counts visible characters only.
func Slugify ¶ added in v0.2.0
Slugify normalizes input text into a lowercase dash-separated slug. The result contains only [a-z0-9-], collapses repeated dashes, trims leading/trailing dashes, and is capped at 64 chars. Returns "project" when normalization produces an empty value.
func Truncate ¶
Truncate shortens a string to width visible characters, adding "..." if truncated. ANSI-aware: counts visible characters only. When truncation occurs, ANSI codes are stripped from the result (reinserting codes at truncation boundaries is not supported).
func TruncateMiddle ¶
TruncateMiddle shortens a string by removing characters from the middle. Useful for paths: "/Users/foo/very/long/path" -> "/Us.../path" ANSI-aware: when truncation occurs, ANSI codes are stripped from the result.
Types ¶
This section is empty.