I am a little late with this since the initial version was published a month and a half ago, but I’ve just cut v1.0.4 of stringwrap
, a small library that solves the annoying parts of wrapping text in terminals & TUIs:
- Grapheme-aware: never splits
, flags, or combining-mark sequences.
- True display width: uses
go-runewidth
, handles full-width CJK, thin spaces, etc. - ANSI friendly: escape codes are preserved but don’t count toward width.
- Tabs, trim, word-splitting: choose to keep or trim leading/trailing whitespace, expand tabs, hyphenate long words safely.
- Rich metadata: every wrapped line comes with byte/rune offsets back into the original string in addition to other metadata.
Repo & docs
- GitHub: GitHub - galactixx/stringwrap: Stringwrap is a Go package for wrapping strings by visual width with optional word splitting and full ANSI + grapheme cluster support. Designed for precision line-wrapping, ideal for terminal output, formatted logs, or editors that require accurate metadata per line segment.
go get
github.com/galactixx/stringwrap@v1.0.4
- Full changelog in the releases tab.
Would love feedback, bug reports, or ideas for niceties like stream-based wrapping. Thanks for checking it out!