Sha256: 98ffe12fe7fcc466255e52912dcf72fa80d82874e0f020a6598a911a6bf5f8f9

Contents?: true

Size: 820 Bytes

Versions: 9

Compression:

Stored size: 820 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Formatter
    # This mix-in module provides string coloring methods for terminals.
    # It automatically disables coloring if coloring is disabled in the process
    # globally or the formatter's output is not a terminal.
    module Colorizable
      def rainbow
        @rainbow ||= begin
          rainbow = Rainbow.new
          rainbow.enabled = false unless output.tty?
          rainbow
        end
      end

      def colorize(string, *args)
        rainbow.wrap(string).color(*args)
      end

      [
        :black,
        :red,
        :green,
        :yellow,
        :blue,
        :magenta,
        :cyan,
        :white
      ].each do |color|
        define_method(color) do |string|
          colorize(string, color)
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rubocop-0.22.0 lib/rubocop/formatter/colorizable.rb
rubocop-0.21.0 lib/rubocop/formatter/colorizable.rb
rubocop-0.20.1 lib/rubocop/formatter/colorizable.rb
rubocop-0.20.0 lib/rubocop/formatter/colorizable.rb
rubocop-0.19.1 lib/rubocop/formatter/colorizable.rb
rubocop-0.19.0 lib/rubocop/formatter/colorizable.rb
rubocop-0.18.1 lib/rubocop/formatter/colorizable.rb
rubocop-0.18.0 lib/rubocop/formatter/colorizable.rb
rubocop-0.17.0 lib/rubocop/formatter/colorizable.rb