module
Opal::VisualWidth
Overview
Utilities for computing string display width in terminal columns, accounting for ANSI escapes, East Asian wide characters, and Unicode emojis.
Defined in:
opal/style/visual_width.crConstant Summary
-
ANSI_REGEX =
/\e\[[0-9;?]*[a-zA-Z]|\e\].*?(?:\a|\e\\)/
Class Method Summary
-
.char_width(char : Char) : Int32
Returns the visual column width of a character when printed on a terminal.
-
.strip_ansi(str : String) : String
Removes all ANSI escape codes from the string.
-
.truncate(str : String, max_width : Int32, ellipsis : String = "...") : String
Truncates a string to fit within max_width terminal columns, appending ellipsis if needed.
-
.width(str : String) : Int32
Returns the total visual column width of a string.
Class Method Detail
def self.char_width(char : Char) : Int32
#
Returns the visual column width of a character when printed on a terminal.
def self.truncate(str : String, max_width : Int32, ellipsis : String = "...") : String
#
Truncates a string to fit within max_width terminal columns, appending ellipsis if needed.