Sha256: 4e113e65a0ad53bc3f5baec4a5e6147e3271a9af49f58581419e1309ed7347ab

Contents?: true

Size: 510 Bytes

Versions: 26

Compression:

Stored size: 510 Bytes

Contents

class ANSI

  def self.resolve_text( color, &block )
    text = nil
    if block_given?
      text = block.call + reset
    end
    "\e[#{chart[color.to_sym]}m#{text}"
  end

  def self.reset
    "\e[0m"
  end

  def self.chart
    {
      black: 30,
      red: 31,
      green: 32,
      yellow: 33,
      blue: 34,
      magenta: 35,
      cyan: 36,
      white: 37
    }
  end

  chart.keys.each do |color|

    define_singleton_method color do |&block|
      resolve_text color, &block
    end

  end

end

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
endow-1.2.1 lib/ansi.rb
endow-1.2.0 lib/ansi.rb
rabbit-wq-1.9.0 lib/ansi.rb
endow-1.1.0 lib/ansi.rb
rabbit-wq-1.8.0 lib/ansi.rb
endow-1.0.1 lib/ansi.rb
rabbit-wq-1.7.0 lib/ansi.rb
endow-1.0.0 lib/ansi.rb
rabbit-wq-1.6.3 lib/ansi.rb
rabbit-wq-1.6.2 lib/ansi.rb
rabbit-wq-1.6.1 lib/ansi.rb
endow-0.4.0 lib/ansi.rb
endow-0.3.0 lib/ansi.rb
endow-0.2.0 lib/ansi.rb
rabbit-wq-1.6.0 lib/ansi.rb
rabbit-wq-1.5.0 lib/ansi.rb
rabbit-wq-1.4.0 lib/ansi.rb
rabbit-wq-1.3.0 lib/ansi.rb
rabbit-wq-1.2.1 lib/ansi.rb
rabbit-wq-1.2.0 lib/ansi.rb