Module: Vkit::Core::Ansi

Defined in:
lib/vkit/core/ansi.rb

Constant Summary collapse

COLORS =
{
  red:    31,
  green:  32,
  yellow: 33,
  blue:   34,
  gray:   90
}.freeze

Class Method Summary collapse

Class Method Details

.blue(text) ⇒ Object



24
# File 'lib/vkit/core/ansi.rb', line 24

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

.color(text, color) ⇒ Object



14
15
16
17
18
19
# File 'lib/vkit/core/ansi.rb', line 14

def self.color(text, color)
  return text unless $stdout.tty?

  code = COLORS[color]
  "\e[#{code}m#{text}\e[0m"
end

.gray(text) ⇒ Object



25
# File 'lib/vkit/core/ansi.rb', line 25

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

.green(text) ⇒ Object



21
# File 'lib/vkit/core/ansi.rb', line 21

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

.red(text) ⇒ Object



22
# File 'lib/vkit/core/ansi.rb', line 22

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

.yellow(text) ⇒ Object



23
# File 'lib/vkit/core/ansi.rb', line 23

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