Sha256: 6724bfd21876c6a892c7e047dce815b15c819aceb27343a0374b62079f323f6f

Contents?: true

Size: 712 Bytes

Versions: 31

Compression:

Stored size: 712 Bytes

Contents

module RakeCompilerDock
  module Colors
    # Start an escape sequence
    ESC = "\e["

    # End the escape sequence
    NND = "#{ESC}0m"

    ColorMap = {
      black: 0,
      red: 1,
      green: 2,
      yellow: 3,
      blue: 4,
      magenta: 5,
      cyan: 6,
      white: 7,
    }

    ColorMap.each do |color, code|
      define_method(color) do |string|
        colored(code, string)
      end
    end

    def colored(color, string)
      if @colors_on
        c = ColorMap[color] || color
        "#{ESC}#{30+c}m#{string}#{NND}"
      else
        string.dup
      end
    end

    def enable_colors
      @colors_on = true
    end

    def disable_colors
      @colors_on = false
    end
  end
end

Version data entries

31 entries across 31 versions & 2 rubygems

Version Path
rake-compiler-dock-1.5.2 lib/rake_compiler_dock/colors.rb
rake-compiler-dock-1.5.1 lib/rake_compiler_dock/colors.rb
rake-compiler-dock-1.5.0 lib/rake_compiler_dock/colors.rb
rake-compiler-dock-1.5.0.rc1 lib/rake_compiler_dock/colors.rb
rake-compiler-dock-1.4.0 lib/rake_compiler_dock/colors.rb
rake-compiler-dock-1.4.0.rc2 lib/rake_compiler_dock/colors.rb
rake-compiler-dock-1.4.0.rc1 lib/rake_compiler_dock/colors.rb
rake-compiler-dock-1.3.1 lib/rake_compiler_dock/colors.rb
rake-compiler-dock-1.3.0 lib/rake_compiler_dock/colors.rb
rake-compiler-dock-1.2.2 lib/rake_compiler_dock/colors.rb
rake-compiler-dock-1.2.1 lib/rake_compiler_dock/colors.rb
rake-compiler-dock-1.2.0 lib/rake_compiler_dock/colors.rb
win32-api-1.10.1 vendor/bundle/ruby/2.5.0/gems/rake-compiler-dock-0.7.2/lib/rake_compiler_dock/colors.rb
win32-api-1.10.0 vendor/bundle/ruby/2.5.0/gems/rake-compiler-dock-0.7.2/lib/rake_compiler_dock/colors.rb
rake-compiler-dock-1.1.0 lib/rake_compiler_dock/colors.rb
win32-api-1.9.2 vendor/bundle/ruby/2.5.0/gems/rake-compiler-dock-0.7.2/lib/rake_compiler_dock/colors.rb
win32-api-1.9.1 vendor/bundle/ruby/2.5.0/gems/rake-compiler-dock-0.7.2/lib/rake_compiler_dock/colors.rb
rake-compiler-dock-1.0.1 lib/rake_compiler_dock/colors.rb
rake-compiler-dock-1.0.0 lib/rake_compiler_dock/colors.rb
rake-compiler-dock-0.7.2 lib/rake_compiler_dock/colors.rb