Sha256: d8492f85a77cc4fff5bc601aaebaa8a4ebe673a4c4c8fb17c62adb5b87c51495

Contents?: true

Size: 484 Bytes

Versions: 10

Compression:

Stored size: 484 Bytes

Contents

# -*- encoding: utf-8 -*-

module Coco

  # Extend String with ANSI colorization.
  # Do nothing on Windows.
  class ColoredString < String
    
    def initialize(str="")
      super(str)
    end
    
    def red
      colorize "\033[31m"
    end
    
    def yellow
      colorize "\033[33m"
    end
    
    private
    
    def colorize color_code
      if RUBY_PLATFORM =~ /win32/
        self
      else
        "#{color_code}#{self}\033[0m"
      end
    end
    
  end
  
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
coco-0.10.0 lib/coco/formatter/colored_string.rb
coco-0.9 lib/coco/formatter/colored_string.rb
coco-0.8 lib/coco/formatter/colored_string.rb
coco-0.7.1 lib/coco/formatter/colored_string.rb
coco-0.7 lib/coco/formatter/colored_string.rb
coco-0.6 lib/coco/formatter/colored_string.rb
coco-0.5.1 lib/coco/formatter/colored_string.rb
coco-0.5 lib/coco/formatter/colored_string.rb
coco-0.4.2 lib/coco/formatter/colored_string.rb
coco-0.4.1 lib/coco/formatter/colored_string.rb