textwidth

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package textwidth centralizes rune-safe terminal cell-width math for beam: every width measurement, truncation, pad, and wrap goes through here instead of ad hoc len() arithmetic.

Widths are terminal cells (East-Asian wide runes count 2). Because frame spans carry no escape codes, Width(line.Text()) is a line's rendered width.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pad

func Pad(s string, w int) string

Pad right-pads s with spaces to exactly w cells; wider input is returned unchanged.

func Truncate

func Truncate(s string, w int, tail string) string

Truncate cuts s to at most w cells, appending tail (whose width counts toward w) when anything was removed. Never splits a rune.

func Width

func Width(s string) int

Width returns the cell width of s.

func Wrap

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

Wrap wraps s to at most w cells per line, breaking after spaces where possible and hard-breaking only words wider than w. Existing newlines are respected, and every rune of s appears in the output exactly once, in order — Wrap only ever inserts breaks, leaving a space at the end of the earlier line, a property the composer's caret math counts on.

A non-positive w still splits on newlines and does no other wrapping: a returned element is a terminal row headed straight for a frame.Span, and a span holding a newline breaks frame.Line's one-row contract, so a degenerate width must never return the input whole.

go-runewidth's own Wrap is not used: its word-boundary detection breaks after any non-ASCII rune, hard-splitting words mid-run.

Types

This section is empty.

Jump to

Keyboard shortcuts

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