Module: Origami::Console

Defined in:
lib/origami/parser.rb

Defined Under Namespace

Modules: Colors

Constant Summary collapse

@@setConsoleTextAttribute =
Win32API.new("kernel32", "SetConsoleTextAttribute", ['L', 'N'], 'I')
@@hOut =
getStdHandle.call(-11)

Class Method Summary collapse

Class Method Details

.colorize(text, color, bright = false) ⇒ Object



84
85
86
87
# File 'lib/origami/parser.rb', line 84

def self.colorize(text, color, bright = false)
  col, nocol = [color, Colors::GREY].map! { |key| "\033[#{key}m" }
  "#{col}#{text}#{nocol}"
end

.colorprint(text, color, bright = false, fd = STDOUT) ⇒ Object

:nodoc:



90
91
92
93
94
# File 'lib/origami/parser.rb', line 90

def self.colorprint(text, color, bright = false, fd = STDOUT) #:nodoc:
  set_fg_color(color, bright, fd) {
    fd << text
  }    
end

.set_fg_color(color, bright = false, fd = STDOUT) ⇒ Object

:nodoc:



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/origami/parser.rb', line 69

def self.set_fg_color(color, bright = false, fd = STDOUT) #:nodoc:
  if RUBY_PLATFORM =~ /win32/ or RUBY_PLATFORM =~ /mingw32/
    if bright then color |= Colors::WHITE end
    @@setConsoleTextAttribute.call(@@hOut, color)
    yield
    @@setConsoleTextAttribute.call(@@hOut, Colors::GREY)
  else
    col, nocol = [color, Colors::GREY].map! { |key| "\033[#{key}m" }
    fd << col
    yield
    fd << nocol
  end
end