{"modulePath":"github.com/intentdriven/abcd","version":"v0.17.1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package textwidth\n\nPackage textwidth is the one display-width measure and word wrap: how many terminal columns plain text occupies, and how words are laid into lines of at most a given width. The banner wraps its tagline with it, and the question limits (internal/core/question) estimate a question's rows with it, so the two measure text the same way.\n\nIt is a pure leaf: no terminal I/O, no environment, no state. That is what lets the transport-agnostic core import it without depending on a package that holds raw-mode code (spc-2610030944505997, open question 2, decided (a)).\n\n## Functions\n\n```go\nfunc Break(s string, limit int) []string\n```\nBreak splits s into pieces of at most limit display columns each, never splitting a wide rune: the way a word wider than any line is laid out when it must not run past the window. A limit below one leaves s whole.\n\n```go\nfunc Columns(s string) int\n```\nColumns counts the terminal columns plain text occupies: East Asian wide and fullwidth runes take two, every other rune one. It measures plain text only; an escape sequence is counted rune by rune, so callers measure text before any styling is applied.\n\n```go\nfunc Fit(s string, limit int, ellipsis string) string\n```\nFit returns s whole when it takes at most limit columns, and otherwise s cut by display width and ended with ellipsis, the whole within limit: a wide rune is never split, and a space left before the cut is dropped. When the limit holds the ellipsis and nothing more, the ellipsis alone says a text was cut; when it cannot hold even that, nothing is drawn. It is how the status board fits a title to one line (spc-2610031844142274).\n\n```go\nfunc Greedy(words []string, limit int) []string\n```\nGreedy fills each line with as many words as fit within limit display columns, one space between words; a word wider than limit stands alone.\n\n```go\nfunc Hang(s string, first, rest int) []string\n```\nHang lays one line of text out for a hanging indent: s comes back unchanged when it fits within first columns, its runs of spaces and its leading indent included, and otherwise breaks only at a space, the first line at most first columns and each later line at most rest, the caller indenting the later lines. No blank is carried to either side of a break, and a word wider than its line stands alone. The status board lays every row with it (iss-2610031207397996).\n\n```go\nfunc Wrap(s string, limit int) []string\n```\nWrap word-wraps s into lines of at most limit display columns and never breaks a word; a word wider than limit stands alone on its line. The wrap is balanced: it keeps the fewest lines a greedy wrap at limit needs, then narrows the measure while that count holds, so the last line is never a stranded word.\n\n","path":"github.com/intentdriven/abcd/internal/textwidth","name":"textwidth","synopsis":"Package textwidth is the one display-width measure and word wrap: how many terminal columns plain text occupies, and how words are laid into lines of at most a given width.","isRedistributable":true}
