Module: Atto::Ansi

Extended by:
Ansi
Included in:
Ansi
Defined in:
lib/atto/ansi.rb

Overview

ANSI colors

Constant Summary collapse

ATTRIBUTES =
{ 
:reset     => 0 , :bold     => 1 , :dark      => 2 , :underline => 4 ,
:blink     => 5 , :negative => 7 , :concealed => 8 , :black     => 30,
:red       => 31, :green    => 32, :yellow    => 33, :blue      => 34,
:magenta   => 35, :cyan     => 36, :white     => 37, :on_black  => 40,
:on_red    => 41, :on_green => 42, :on_yellow => 43, :on_blue   => 44,
:on_magenta=> 45, :on_cyan  => 46, :on_white  => 47,  }

Instance Method Summary collapse

Instance Method Details

#color(*args) ⇒ Object

Replaces symbols witch refer to ANSI escape codes with those escape codes.



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/atto/ansi.rb', line 15

def color(*args)
  out = []
  for arg in args
    col = ATTRIBUTES[arg] 
    if col  
      out << "\e[#{col}m"
    else
      out << arg
    end
  end
  out << "\e[0m"
  return out
end

#color_string(*args) ⇒ Object

Replaces ansi codes and returns the joined string



30
31
32
# File 'lib/atto/ansi.rb', line 30

def color_string(*args)
  return color(*args).map { |e| e.to_s }.join
end

#puts(*args) ⇒ Object

puts output colored with ANSI escape codes



35
36
37
# File 'lib/atto/ansi.rb', line 35

def puts(*args)
  Kernel.puts(*self.color(*args))
end