Sha256: b5a35841f203d82177b50792ad71c402cd6ed2961815fc94823ce3cb545c4a39

Contents?: true

Size: 1.31 KB

Versions: 23

Compression:

Stored size: 1.31 KB

Contents

module Bones::Colors
  extend self

  COLOR_CODES = {
    :clear         =>   0,
    :reset         =>   0,     # synonym for :clear
    :bold          =>   1,
    :dark          =>   2,
    :italic        =>   3,     # not widely implemented
    :underline     =>   4,
    :underscore    =>   4,     # synonym for :underline
    :blink         =>   5,
    :rapid_blink   =>   6,     # not widely implemented
    :negative      =>   7,     # no reverse because of String#reverse
    :concealed     =>   8,
    :strikethrough =>   9,     # not widely implemented
    :black         =>  30,
    :red           =>  31,
    :green         =>  32,
    :yellow        =>  33,
    :blue          =>  34,
    :magenta       =>  35,
    :cyan          =>  36,
    :white         =>  37,
    :on_black      =>  40,
    :on_red        =>  41,
    :on_green      =>  42,
    :on_yellow     =>  43,
    :on_blue       =>  44,
    :on_magenta    =>  45,
    :on_cyan       =>  46,
    :on_white      =>  47
  }

  COLOR_CODES.each { |name,code|
    module_eval <<-CODE
      def #{name.to_s}( str )
        "\e[#{code}m\#{str}\e[0m"
      end
    CODE
  }

  def colorize( str, *args )
    args.each { |name|
      code = COLOR_CODES[name]
      next if code.nil?
      str = "\e[#{code}m#{str}\e[0m"
    }
    str
  end
end  # module Bones::Colors

# EOF

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
bones-3.5.5 lib/bones/colors.rb
bones-3.5.4 lib/bones/colors.rb
bones-3.5.3 lib/bones/colors.rb
bones-3.5.2 lib/bones/colors.rb
bones-3.5.1 lib/bones/colors.rb
bones-3.5.0 lib/bones/colors.rb
bones-3.4.7 lib/bones/colors.rb
bones-3.4.6 lib/bones/colors.rb
bones-3.4.5 lib/bones/colors.rb
bones-3.4.4 lib/bones/colors.rb
bones-3.4.3 lib/bones/colors.rb
bones-3.4.2 lib/bones/colors.rb
bones-3.4.1 lib/bones/colors.rb
bones-3.4.0 lib/bones/colors.rb
bones-3.3.0 lib/bones/colors.rb
bones-3.2.1 lib/bones/colors.rb
bones-3.2.0 lib/bones/colors.rb
bones-3.1.3 lib/bones/colors.rb
bones-3.1.2 lib/bones/colors.rb
bones-3.1.1 lib/bones/colors.rb