Sha256: 8e4b6730ccc85175abf307b0ce23a43e9870b156f70af62c7ed18abd50496ceb

Contents?: true

Size: 727 Bytes

Versions: 1

Compression:

Stored size: 727 Bytes

Contents

module Coco

  # Public: Build String with ANSI colorization.
  # Do nothing on Windows.
  class ColoredString < String

    # Public: Initialize a new ColoredString object.
    #
    # str - A String.
    def initialize(str="")
      super(str)
    end

    # Public: Make a red string.
    #
    # Returns String ANSIfied in red.
    def red
      colorize "\033[31m"
    end

    # Public: Make a yellow string.
    #
    # Returns String ANSIfied in yellow.
    def yellow
      colorize "\033[33m"
    end

    def green
      colorize "\033[32m"
    end

    private

    def colorize(color_code)
      if RUBY_PLATFORM =~ /win32/
        self
      else
        "#{color_code}#{self}\033[0m"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
coco-0.13.0 lib/coco/formatter/colored_string.rb