module

Glimmer::Style::ANSIString

ANSIString provides utilities for working with strings that contain ANSI escape codes.

This is critical for correct word wrapping and layout calculations.

Constants

ANSI_PATTERN = /\e\[[0-9;]*m|\e\]8;[^\e]*\e\\/

ANSI escape code pattern (SGR codes + OSC 8 hyperlinks)

Class methods

char_width(char : Char) : Int32

Returns the display width of a single character.

CJK ideographs, fullwidth forms, and emoji occupy 2 columns.

Combining marks and zero-width characters occupy 0 columns.

All other printable characters occupy 1 column.

Source
has_ansi?(str : String) : Bool

Checks if a string contains ANSI escape codes.

Source
max_line_width(str : String) : Int32

Returns the length of the longest line in a string (visible width).

Source
strip(str : String) : String

Strips all ANSI escape codes from a string.

Source
truncate(str : String, width : Int32, suffix : String = "") : String

Truncates a string to the given visible width without breaking ANSI codes.

If the string is shorter than the width, returns it unchanged.

If longer, truncates and optionally appends a suffix.

Source
visible_width(str : String) : Int32

Returns the visible width of a string (excluding ANSI codes).

Correctly handles CJK double-width characters, emoji, and OSC 8 hyperlinks.

Source

Nested types