textwidth

package
v0.13.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

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. 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.

It 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)).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Break added in v0.13.1

func Break(s string, limit int) []string

Break 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.

func Columns

func Columns(s string) int

Columns 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.

func Fit added in v0.13.1

func Fit(s string, limit int, ellipsis string) string

Fit 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).

func Greedy

func Greedy(words []string, limit int) []string

Greedy fills each line with as many words as fit within limit display columns, one space between words; a word wider than limit stands alone.

func Hang

func Hang(s string, first, rest int) []string

Hang 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).

func Wrap

func Wrap(s string, limit int) []string

Wrap 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.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL