File: color.rb

package info (click to toggle)
psicode 3.4.0-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 46,400 kB
  • ctags: 18,552
  • sloc: cpp: 291,425; ansic: 12,788; fortran: 10,489; perl: 3,206; sh: 2,702; makefile: 2,207; ruby: 2,178; yacc: 110; lex: 53
file content (18 lines) | stat: -rw-r--r-- 647 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
def colorize(text, color_code)
  # Make sure the terminal supports color
  if (ENV.has_key?("COLORTERM") and ENV["COLORTERM"] == 1) or
    (ENV.has_key?("TERM") and ENV["TERM"].include?("color"))
    "#{color_code}#{text}\e[0m"
  else
    text
  end
end

def red(text);     colorize(text, "\e[31m"); end
def green(text);   colorize(text, "\e[32m"); end
def blue(text);    colorize(text, "\e[34m"); end
def yellow(text);  colorize(text, "\e[33m"); end
def magenta(text); colorize(text, "\e[35m"); end
def cyan(text);    colorize(text, "\e[36m"); end
def white(text);   colorize(text, "\e[37m"); end
def bold(text);    colorize(text, "\e[1m");  end