Sha256: bed38f27132e971ef251d9f16f5671f8dda9f6bb4588abc81f7ee966cc0f825b

Contents?: true

Size: 1.14 KB

Versions: 15

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

# Adds ANSI colors to string class.
class String
  def black
    "\e[30m#{self}\e[0m"
  end

  def red
    "\e[31m#{self}\e[0m"
  end

  def green
    "\e[32m#{self}\e[0m"
  end

  def brown
    "\e[33m#{self}\e[0m"
  end

  def yellow
    brown
  end

  def blue
    "\e[34m#{self}\e[0m"
  end

  def magenta
    "\e[35m#{self}\e[0m"
  end

  def cyan
    "\e[36m#{self}\e[0m"
  end

  def gray
    "\e[37m#{self}\e[0m"
  end

  def white
    "\e[39m#{bold}\e[0m"
  end

  def bg_black
    "\e[40m#{self}\e[0m"
  end

  def bg_red
    "\e[41m#{self}\e[0m"
  end

  def bg_green
    "\e[42m#{self}\e[0m"
  end

  def bg_brown
    "\e[43m#{self}\e[0m"
  end

  def bg_blue
    "\e[44m#{self}\e[0m"
  end

  def bg_magenta
    "\e[45m#{self}\e[0m"
  end

  def bg_cyan
    "\e[46m#{self}\e[0m"
  end

  def bg_gray
    "\e[47m#{self}\e[0m"
  end

  def bold
    "\e[1m#{self}\e[22m"
  end

  def italic
    "\e[3m#{self}\e[23m"
  end

  def underline
    "\e[4m#{self}\e[24m"
  end

  def blink
    "\e[5m#{self}\e[25m"
  end

  def reverse_color
    "\e[7m#{self}\e[27m"
  end

  def colorless
    gsub(/\e\[\d{1,2}m/, "")
  end
end

Version data entries

15 entries across 15 versions & 3 rubygems

Version Path
nsrr-8.0.0 lib/nsrr/helpers/color.rb
nsrr-7.0.0 lib/nsrr/helpers/color.rb
nsrr-6.0.0 lib/nsrr/helpers/color.rb
nsrr-5.0.0 lib/nsrr/helpers/color.rb
nsrr-5.0.0.rc lib/nsrr/helpers/color.rb
edfize-0.6.0 lib/edfize/color.rb
spout-1.0.0 lib/spout/color.rb
spout-1.0.0.beta3 lib/spout/color.rb
spout-1.0.0.beta2 lib/spout/color.rb
spout-1.0.0.beta1 lib/spout/color.rb
spout-0.14.1 lib/spout/color.rb
spout-0.14.0 lib/spout/color.rb
spout-0.14.0.rc lib/spout/color.rb
spout-0.14.0.beta3 lib/spout/color.rb
spout-0.14.0.beta2 lib/spout/color.rb