#-- # rbmh/ansi.rb : rbmhshow 0.4.2 # # Copyright (C) 2004--2005 Merlin Hughes # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # #++ # ANSI colouring module RBMH class ANSI end def ANSI.color(*attrs) return '' if ENV['MONOCHROME'] == 'true' str = "" attrs.each { |attr| case attr when 'bold' esc = 1 when 'italics' esc = 3 when 'underline' esc = 4 when 'inverse' esc = 7 when 'strikethrough' esc = 9 when '-bold' esc = 22 when '-italics' esc = 23 when '-underline' esc = 24 when '-inverse' esc = 27 when '-strikethrough' esc = 29 when 'black' esc = 30 when 'red' esc = 31 when 'green' esc = 32 when 'yellow' esc = 33 when 'blue' esc = 34 when 'magenta' esc = 35 when 'cyan' esc = 36 when 'white' esc = 37 when '-color' esc = 39 else raise RBMH::Exception, "unknown attribute - #{attr}" end str << (str.empty? ? "\e[" : ';') << esc.to_s } str.empty? ? str : (str << 'm') end def ANSI.uncolor return '' if ENV['MONOCHROME'] == 'true' "\e[0m" end end # module RBMH