module

Opal::VisualWidth

Utilities for computing string display width in terminal columns, accounting for ANSI escapes, East Asian wide characters, and Unicode emojis.

Constants

ANSI_REGEX = /\e\[[0-9;?]*[a-zA-Z]|\e\].*?(?:\a|\e\\)/

Class methods

char_width(char : Char) : Int32

Returns the visual column width of a character when printed on a terminal.

Source
measure(str : String) : Int32

Alias for width

Source
strip_ansi(str : String) : String

Removes all ANSI escape codes from the string.

Source
truncate(str : String, max_width : Int32, ellipsis : String = "...") : String

Truncates a string to fit within max_width terminal columns, appending ellipsis if needed.

Source
width(str : String) : Int32

Returns the total visual column width of a string.

Source