Sha256: e8190e036df2644cd157274cc5307fd7e3f3698d0537a26668f8a89c097777ea

Contents?: true

Size: 754 Bytes

Versions: 1

Compression:

Stored size: 754 Bytes

Contents

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

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.12.0 lib/coco/formatter/colored_string.rb