Module: ColorRoutes::StringANSI
- Included in:
- String
- Defined in:
- lib/color_routes/string_ansi.rb
Overview
Some extensions to String to deal with ANSI colors.
Constant Summary collapse
- COLORS =
{ :black => 30, :red => 31, :green => 32, :brown => 33, :blue => 34, :magenta => 35, :cyan => 36, :gray => 37 }
Instance Method Summary collapse
Instance Method Details
#ansi_length ⇒ Object
23 24 25 |
# File 'lib/color_routes/string_ansi.rb', line 23 def ansi_length gsub(/\033\[\d+m/, "").length end |
#ansi_ljust(n) ⇒ Object
27 28 29 |
# File 'lib/color_routes/string_ansi.rb', line 27 def ansi_ljust(n) ljust(n + length - ansi_length) end |
#ansi_rjust(n) ⇒ Object
31 32 33 |
# File 'lib/color_routes/string_ansi.rb', line 31 def ansi_rjust(n) rjust(n + length - ansi_length) end |
#color(color) ⇒ Object
17 18 19 20 21 |
# File 'lib/color_routes/string_ansi.rb', line 17 def color(color) code = "\033[#{COLORS[color]}m" end_code = "\033[0m" "#{code}#{self}#{end_code}" end |