Module: Tracer::Color

Included in:
Base
Defined in:
lib/tracer/color.rb

Constant Summary collapse

CLEAR =
0
BOLD =
1
UNDERLINE =
4
REVERSE =
7
RED =
31
GREEN =
32
YELLOW =
33
BLUE =
34
MAGENTA =
35
CYAN =
36

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.clearObject



22
23
24
# File 'lib/tracer/color.rb', line 22

def clear
  "\e[#{CLEAR}m"
end

.colorize(text, seq) ⇒ Object



17
18
19
20
# File 'lib/tracer/color.rb', line 17

def colorize(text, seq)
  seq = seq.map { |s| "\e[#{const_get(s)}m" }.join("")
  "#{seq}#{text}#{clear}"
end

Instance Method Details

#colorize(str, seq, colorize: @colorize) ⇒ Object



27
28
29
# File 'lib/tracer/color.rb', line 27

def colorize(str, seq, colorize: @colorize)
  !colorize ? str : Color.colorize(str, seq)
end

#colorize_blue(str) ⇒ Object



35
36
37
# File 'lib/tracer/color.rb', line 35

def colorize_blue(str)
  colorize(str, %i[BLUE BOLD])
end

#colorize_cyan(str) ⇒ Object



31
32
33
# File 'lib/tracer/color.rb', line 31

def colorize_cyan(str)
  colorize(str, %i[CYAN BOLD])
end

#colorize_magenta(str) ⇒ Object



39
40
41
# File 'lib/tracer/color.rb', line 39

def colorize_magenta(str)
  colorize(str, %i[MAGENTA BOLD])
end