public
Description: Simple Colorize gem to display colors on the *nix console.
Homepage: http://www.freedomcoder.com.ar
Clone URL: git://github.com/FreedomCoder/colorize.git
colorize / README
100644 80 lines (63 sloc) 1.66 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
Something should go here , but well .. I have nothing more to say that it is a freebe
under GPL 3.0 licence :)
 
Cheers
 
FreedomCoder
 
 
DOCS :
 
Colors:
:bold
            :underline
            :blink
            :reverse
            :concealed
            :black
            :red
            :green
            :yellow
            :blue
            :magenta
            :cyan
            :white
            :on_black
            :on_red
            :on_green
            :on_yellow
            :on_blue
            :on_magenta
            :on_cyan
            :on_white
 
===== test.rb ========
 
require "Colorize"
 
class Klass
  include Colors
  def initialize
    system("echo #{red("hola")} This is a #{blue("test")}")
    system("echo #{red on_white("Hola1")}")
    puts "#{red on_blue("Hola2")}"
  end
end
 
Klass.new
 
html = "<html>
<body>
<dl>
<dt>the first term</dt>
<dd>its definition</dd>
 
<dt>the second term</dt>
<dd>its definition</dd>
 
<dt>the third term</dt>
<dd>\"its definition\"</dd>
<img src=\"test.html\">
</dl>
</body>
</html>"
     
c = Colorize.new( :red => /<.*html>|<.*body>/,
                  :blue => /".*"/,
                  :cyan => /src/)
puts c.paint(html)
 
apachelog = "1.2.3.4 -- \"This is not\" - \"No way\".
4.3.2.1 -- \"This3 34 is not\" - \"No way 34343\".
4.3.2.1 -- \"This3 34 is not\" - \"No way 34343\"."
reg = /(.*) -- \"(.*)\" - \"(.*)\"\./
 
apachelog = Colorize.block_paint apachelog, reg do |m|
  Colors.red(m[0]) + " -- \"" + Colors.blue(m[1]) + "\" - \"" + Colors.white(m[2]) + "\".\n"
end
 
puts apachelog