textutil

package
v0.2.19 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package textutil provides terminal-cell-aware operations on Unicode text.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clip

func Clip(s string, cols int) string

Clip returns the longest prefix of whole grapheme clusters whose terminal width does not exceed cols. It does not pad or sanitize its input.

func DropLast

func DropLast(s string) string

DropLast removes the final complete grapheme cluster from s. This is useful for implementing Backspace without splitting UTF-8, combining sequences, or emoji. It does not sanitize its input.

func Fit

func Fit(s string, cols int) string

Fit clips s to cols terminal cells and pads the result with spaces so that its width is exactly cols. It does not sanitize its input.

func Sanitize

func Sanitize(s string) string

Sanitize makes s safe to draw as terminal text. Control and formatting characters which could affect the terminal or the visual ordering of text are replaced with spaces. ZWNJ and ZWJ are retained because they participate in legitimate grapheme clusters. Invalid UTF-8 is converted to utf8.RuneError by ranging over the string.

func Truncate

func Truncate(s string, cols int) string

Truncate sanitizes s and, when it is wider than cols, clips it to make room for a one-cell ellipsis. It returns an empty string when cols is non-positive.

func Width

func Width(s string) int

Width returns the number of terminal cells occupied by s. Callers should sanitize untrusted input with Sanitize before measuring or drawing it. East Asian ambiguous-width characters use uniseg's standard width of one.

Types

This section is empty.

Jump to

Keyboard shortcuts

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