Method: Rex::Text.display_width

Defined in:
lib/rex/text.rb

.display_width(str) ⇒ Integer

Function that aims to calculate the display width of the given string. In the future this will be aware of East Asian characters having different display widths. For now it simply returns the string’s length ignoring color codes.

Parameters:

  • str (String)

Returns:

  • (Integer)


112
113
114
115
116
# File 'lib/rex/text.rb', line 112

def self.display_width(str)
  return 0 if str.nil?

  str.gsub(COLOR_CODES_REGEX, '').length
end