Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_rich/panel.rb

Overview

Extend String to remove ANSI codes for alignment

Instance Method Summary collapse

Instance Method Details

#display_widthObject



181
182
183
184
185
186
187
# File 'lib/ruby_rich/panel.rb', line 181

def display_width
  width = 0
  self.uncolorize.each_char do |char|
    width += Unicode::DisplayWidth.of(char)
  end
  width
end

#uncolorizeObject



177
178
179
# File 'lib/ruby_rich/panel.rb', line 177

def uncolorize
    gsub(/\e\[[0-9;]*m/, '')
end