textwidth

package
v1.36.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 4 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 textwidth measures text by the columns it takes in a terminal, and cuts it to them, so that what is written beside it lines up whatever characters it has.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OneLine

func OneLine(s string) string

OneLine returns s with each run of white space and control characters made one space, and those at its ends left out, so that it keeps to the line it is written on, and without format characters, such as one that turns the text after it right to left, which would change how the rest of the line reads.

func Truncate

func Truncate(s string, maxWidth int) string

Truncate returns s cut to at most maxWidth columns, ending in an ellipsis when it was cut. A character is kept or left out with the marks and the emoji modifiers that follow it, and a wide one that would go past maxWidth is left out whole, so what is returned may be a column narrower. Nothing is left of s when maxWidth is less than one.

func Width

func Width(s string) int

Width returns how many columns s takes in a terminal: two for a wide character, such as one of Japanese, or one drawn as an emoji, none for a mark that combines with the one before it or a format character, and one for any other.

Types

This section is empty.

Jump to

Keyboard shortcuts

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