Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/ext/string.rb
Overview
burkelibbey’s
Constant Summary collapse
- COLORS =
{ :black => '0', :red => '1', :green => '2', :yellow => '3', :blue => '4', :magenta => '5', :cyan => '6', :white => '7' }
- FORMAT_CODES =
{ :bold => '1', :italic => '3', :underline => '4', :blink => '5', }
Instance Method Summary collapse
Instance Method Details
#ansi_formatted ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/ext/string.rb', line 22 def ansi_formatted ansi_csi = "#{(0x1B).chr}[" formats = {} FORMAT_CODES.each do |name, code| formats[name] = code if @properties[name] end formats[:color] = "3#{COLORS[@properties[:color]]}" if @properties[:color] "#{ansi_csi}#{formats.values.join(';')}m#{self}#{ansi_csi}m" end |
#make_colorized(color) ⇒ Object
32 33 34 35 36 |
# File 'lib/ext/string.rb', line 32 def make_colorized(color) @properties ||= {} @properties[:color] = color ansi_formatted end |