Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/utils.rb
Instance Method Summary collapse
- #black ⇒ Object
- #blink ⇒ Object
- #blue ⇒ Object
- #bold ⇒ Object
- #center_colors(x) ⇒ Object
-
#center_lines(cols) ⇒ Object
Magic strings metaprogramming screwery Modified from: stackoverflow.com/questions/1489183/colorized-ruby-output.
- #colorize(code1, code2 = 0) ⇒ Object
- #cyan ⇒ Object
- #gray ⇒ Object
- #green ⇒ Object
- #italic ⇒ Object
- #no_bold ⇒ Object
- #no_colors ⇒ Object
- #purple ⇒ Object
- #red ⇒ Object
- #reset_colors ⇒ Object
- #reverse_color ⇒ Object
- #underline ⇒ Object
- #yellow ⇒ Object
Instance Method Details
#black ⇒ Object
35 |
# File 'lib/utils.rb', line 35 def black; colorize(30) end |
#blink ⇒ Object
47 |
# File 'lib/utils.rb', line 47 def blink; colorize(5, 25) end |
#blue ⇒ Object
39 |
# File 'lib/utils.rb', line 39 def blue; colorize(34) end |
#bold ⇒ Object
44 |
# File 'lib/utils.rb', line 44 def bold; colorize(1, 22) end |
#center_colors(x) ⇒ Object
15 16 17 |
# File 'lib/utils.rb', line 15 def center_colors(x) self.no_colors.center(x).gsub(self.no_colors, self) end |
#center_lines(cols) ⇒ Object
Magic strings metaprogramming screwery Modified from: stackoverflow.com/questions/1489183/colorized-ruby-output
11 12 13 |
# 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) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# 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 ⇒ Object
41 |
# File 'lib/utils.rb', line 41 def cyan; colorize(36) end |
#gray ⇒ Object
42 |
# File 'lib/utils.rb', line 42 def gray; colorize(37) end |
#green ⇒ Object
37 |
# File 'lib/utils.rb', line 37 def green; colorize(32) end |
#italic ⇒ Object
45 |
# File 'lib/utils.rb', line 45 def italic; colorize(3, 24) end |
#no_bold ⇒ Object
32 |
# File 'lib/utils.rb', line 32 def no_bold; colorize(22, 22) end |
#no_colors ⇒ Object
29 30 31 |
# File 'lib/utils.rb', line 29 def no_colors self.gsub(/\e\[\d+m/, "") end |
#purple ⇒ Object
40 |
# File 'lib/utils.rb', line 40 def purple; colorize(35) end |
#red ⇒ Object
36 |
# File 'lib/utils.rb', line 36 def red; colorize(31) end |
#reset_colors ⇒ Object
33 |
# File 'lib/utils.rb', line 33 def reset_colors; colorize(0) end |
#reverse_color ⇒ Object
48 |
# File 'lib/utils.rb', line 48 def reverse_color; colorize(7, 27) end |
#underline ⇒ Object
46 |
# File 'lib/utils.rb', line 46 def underline; colorize(4, 34) end |
#yellow ⇒ Object
38 |
# File 'lib/utils.rb', line 38 def yellow; colorize(33) end |