class String
Public Instance Methods
black()
click to toggle source
# File lib/utils.rb, line 35 def black; colorize(30) end
blink()
click to toggle source
# File lib/utils.rb, line 47 def blink; colorize(5, 25) end
blue()
click to toggle source
# File lib/utils.rb, line 39 def blue; colorize(34) end
bold()
click to toggle source
# File lib/utils.rb, line 44 def bold; colorize(1, 22) end
center_colors(x)
click to toggle source
# File lib/utils.rb, line 15 def center_colors(x) self.no_colors.center(x).gsub(self.no_colors, self) end
center_lines(cols)
click to toggle source
Magic strings metaprogramming screwery Modified from: stackoverflow.com/questions/1489183/colorized-ruby-output
# File lib/utils.rb, line 11 def center_lines(cols) self.split("\n").map{|x| x.center_colors(cols)}.join("\n") end
colorize(code1, code2=0)
click to toggle source
# File lib/utils.rb, line 19 def colorize(code1, code2=0) tmp = "\e[#{code1}m#{self}\e[#{code2}m" if tmp.scan(/\e\[#{code2}m/).count >= 2 tmp = tmp.split("\e\[#{code2}m") tmp = tmp[0..-2].map!{ |x| "#{x}\e\[#{code2}m\e[#{code1}m" } + [tmp[-1]] return tmp.join("") end return tmp end
cyan()
click to toggle source
# File lib/utils.rb, line 41 def cyan; colorize(36) end
gray()
click to toggle source
# File lib/utils.rb, line 42 def gray; colorize(37) end
green()
click to toggle source
# File lib/utils.rb, line 37 def green; colorize(32) end
italic()
click to toggle source
# File lib/utils.rb, line 45 def italic; colorize(3, 24) end
no_bold()
click to toggle source
# File lib/utils.rb, line 32 def no_bold; colorize(22, 22) end
no_colors()
click to toggle source
# File lib/utils.rb, line 29 def no_colors self.gsub(/\e\[\d+m/, "") end
purple()
click to toggle source
# File lib/utils.rb, line 40 def purple; colorize(35) end
red()
click to toggle source
# File lib/utils.rb, line 36 def red; colorize(31) end
reset_colors()
click to toggle source
# File lib/utils.rb, line 33 def reset_colors; colorize(0) end
reverse_color()
click to toggle source
# File lib/utils.rb, line 48 def reverse_color; colorize(7, 27) end
underline()
click to toggle source
# File lib/utils.rb, line 46 def underline; colorize(4, 34) end
yellow()
click to toggle source
# File lib/utils.rb, line 38 def yellow; colorize(33) end