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
- COLORS =
{ :black => 30, :red => 31, :green => 32, :brown => 33, :blue => 34, :magenta => 35, :cyan => 36, :gray => 37 }
Instance Method Summary (collapse)
Instance Method Details
- (Object) ansi_length
23 24 25 |
# File 'lib/color_routes/string_ansi.rb', line 23 def ansi_length gsub(/\033\[\d+m/, "").length end |
- (Object) ansi_ljust(n)
27 28 29 |
# File 'lib/color_routes/string_ansi.rb', line 27 def ansi_ljust(n) ljust(n + length - ansi_length) end |
- (Object) ansi_rjust(n)
31 32 33 |
# File 'lib/color_routes/string_ansi.rb', line 31 def ansi_rjust(n) rjust(n + length - ansi_length) end |
- (Object) color(color)
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 |