width

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package width approximates terminal cell widths. Its table covers common East Asian, Hangul, and emoji ranges and must be updated as Unicode grows.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cut

func Cut(text string, cells int) (string, int)

Cut returns the longest prefix that fits and its cell width.

func Of

func Of(text string) int

Of is how many cells text takes up.

func Rune

func Rune(value rune) int

Rune is how many cells one character takes up.

func Wrap

func Wrap(text string, cells int) []string

Wrap breaks styled text into rows no wider than cells, preferring spaces. ANSI escapes take no cells, and their styling continues across breaks.

Types

type Row

type Row struct {
	Text  string
	Begin int
	End   int
	Next  int
}

Row maps rendered text to source runes. Text may carry ANSI state across the break; [End, Next) is discarded break whitespace.

func Rows

func Rows(text string, cells int) []Row

Rows wraps as Wrap does, and says which runes of the input each row came from. There is always at least one row.

Jump to

Keyboard shortcuts

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