Module: Antigravity::Colors

Defined in:
lib/antigravity/colors.rb

Constant Summary collapse

CODES =
{
  reset:     "\e[0m",
  bold:      "\e[1m",
  dim:       "\e[2m",
  italic:    "\e[3m",
  # Foreground
  gray:      "\e[90m",
  red:       "\e[31m",
  green:     "\e[32m",
  yellow:    "\e[33m",
  blue:      "\e[34m",
  magenta:   "\e[35m",
  cyan:      "\e[36m",
  white:     "\e[37m",
  # Bright
  bright_green:  "\e[92m",
  bright_yellow: "\e[93m",
  bright_cyan:   "\e[96m",
}.freeze

Class Method Summary collapse

Class Method Details

.blue(text) ⇒ Object



39
# File 'lib/antigravity/colors.rb', line 39

def self.blue(text)    = colorize(text, :blue)

.bold(text) ⇒ Object



41
# File 'lib/antigravity/colors.rb', line 41

def self.bold(text)    = colorize(text, :bold)

.colorize(text, *styles) ⇒ Object



27
28
29
30
31
# File 'lib/antigravity/colors.rb', line 27

def self.colorize(text, *styles)
  return text.to_s unless $stdout.tty?
  prefix = styles.map { |s| CODES[s] || "" }.join
  "#{prefix}#{text}#{CODES[:reset]}"
end

.cyan(text) ⇒ Object



38
# File 'lib/antigravity/colors.rb', line 38

def self.cyan(text)    = colorize(text, :cyan)

.dim(text) ⇒ Object



34
# File 'lib/antigravity/colors.rb', line 34

def self.dim(text)     = colorize(text, :dim)

.gray(text) ⇒ Object



33
# File 'lib/antigravity/colors.rb', line 33

def self.gray(text)    = colorize(text, :gray)

.green(text) ⇒ Object



35
# File 'lib/antigravity/colors.rb', line 35

def self.green(text)   = colorize(text, :green)

.magenta(text) ⇒ Object



40
# File 'lib/antigravity/colors.rb', line 40

def self.magenta(text) = colorize(text, :magenta)

.red(text) ⇒ Object



37
# File 'lib/antigravity/colors.rb', line 37

def self.red(text)     = colorize(text, :red)

.yellow(text) ⇒ Object



36
# File 'lib/antigravity/colors.rb', line 36

def self.yellow(text)  = colorize(text, :yellow)