clio 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. data/COPYING +170 -0
  2. data/HISTORY +11 -0
  3. data/MANIFEST +181 -0
  4. data/METADATA +18 -0
  5. data/NEWS +10 -0
  6. data/README +52 -0
  7. data/admin/config/reap.yaml +30 -0
  8. data/admin/depot/commandline.rb +219 -0
  9. data/admin/depot/multicommand.rb +403 -0
  10. data/admin/depot/test_multicommand.rb +40 -0
  11. data/admin/log/notes.xml +28 -0
  12. data/admin/log/stats.html +25 -0
  13. data/admin/log/syntax.log +0 -0
  14. data/admin/log/testunit.log +16 -0
  15. data/admin/pack/clio-0.0.1.gem +0 -0
  16. data/admin/share/reap/example.rb +7 -0
  17. data/admin/temps/lib/clio/about.rb.erb +4 -0
  18. data/lib/clio/ansicode.rb +319 -0
  19. data/lib/clio/command.rb +296 -0
  20. data/lib/clio/commandable.rb +195 -0
  21. data/lib/clio/commandline.rb +275 -0
  22. data/lib/clio/consoleutils.rb +117 -0
  23. data/lib/clio/errors.rb +16 -0
  24. data/lib/clio/option.rb +36 -0
  25. data/lib/clio/progressbar.rb +253 -0
  26. data/lib/clio/runmode.rb +126 -0
  27. data/lib/clio/string.rb +147 -0
  28. data/test/test_command.rb +42 -0
  29. data/test/test_commandline.rb +83 -0
  30. data/vendor/Console/Console.cpp +1203 -0
  31. data/vendor/Console/Console.rdoc +690 -0
  32. data/vendor/Console/Console_ANSI.rdoc +302 -0
  33. data/vendor/Console/HISTORY.txt +7 -0
  34. data/vendor/Console/INSTALL.txt +18 -0
  35. data/vendor/Console/Makefile +162 -0
  36. data/vendor/Console/README.txt +26 -0
  37. data/vendor/Console/doc/classes/Win32.html +115 -0
  38. data/vendor/Console/doc/classes/Win32/Console.html +650 -0
  39. data/vendor/Console/doc/classes/Win32/Console.src/M000001.html +31 -0
  40. data/vendor/Console/doc/classes/Win32/Console.src/M000002.html +23 -0
  41. data/vendor/Console/doc/classes/Win32/Console.src/M000003.html +23 -0
  42. data/vendor/Console/doc/classes/Win32/Console.src/M000004.html +27 -0
  43. data/vendor/Console/doc/classes/Win32/Console.src/M000005.html +23 -0
  44. data/vendor/Console/doc/classes/Win32/Console.src/M000006.html +28 -0
  45. data/vendor/Console/doc/classes/Win32/Console.src/M000007.html +23 -0
  46. data/vendor/Console/doc/classes/Win32/Console.src/M000008.html +24 -0
  47. data/vendor/Console/doc/classes/Win32/Console.src/M000009.html +44 -0
  48. data/vendor/Console/doc/classes/Win32/Console.src/M000010.html +23 -0
  49. data/vendor/Console/doc/classes/Win32/Console.src/M000011.html +33 -0
  50. data/vendor/Console/doc/classes/Win32/Console.src/M000012.html +26 -0
  51. data/vendor/Console/doc/classes/Win32/Console.src/M000013.html +27 -0
  52. data/vendor/Console/doc/classes/Win32/Console.src/M000014.html +28 -0
  53. data/vendor/Console/doc/classes/Win32/Console.src/M000015.html +23 -0
  54. data/vendor/Console/doc/classes/Win32/Console.src/M000016.html +23 -0
  55. data/vendor/Console/doc/classes/Win32/Console.src/M000017.html +23 -0
  56. data/vendor/Console/doc/classes/Win32/Console.src/M000018.html +29 -0
  57. data/vendor/Console/doc/classes/Win32/Console.src/M000019.html +23 -0
  58. data/vendor/Console/doc/classes/Win32/Console.src/M000020.html +23 -0
  59. data/vendor/Console/doc/classes/Win32/Console.src/M000021.html +28 -0
  60. data/vendor/Console/doc/classes/Win32/Console.src/M000022.html +23 -0
  61. data/vendor/Console/doc/classes/Win32/Console.src/M000023.html +28 -0
  62. data/vendor/Console/doc/classes/Win32/Console.src/M000024.html +35 -0
  63. data/vendor/Console/doc/classes/Win32/Console.src/M000025.html +28 -0
  64. data/vendor/Console/doc/classes/Win32/Console.src/M000026.html +28 -0
  65. data/vendor/Console/doc/classes/Win32/Console.src/M000027.html +28 -0
  66. data/vendor/Console/doc/classes/Win32/Console.src/M000028.html +31 -0
  67. data/vendor/Console/doc/classes/Win32/Console.src/M000029.html +23 -0
  68. data/vendor/Console/doc/classes/Win32/Console.src/M000030.html +23 -0
  69. data/vendor/Console/doc/classes/Win32/Console.src/M000031.html +23 -0
  70. data/vendor/Console/doc/classes/Win32/Console.src/M000032.html +27 -0
  71. data/vendor/Console/doc/classes/Win32/Console.src/M000033.html +27 -0
  72. data/vendor/Console/doc/classes/Win32/Console.src/M000034.html +25 -0
  73. data/vendor/Console/doc/classes/Win32/Console/ANSI.html +103 -0
  74. data/vendor/Console/doc/classes/Win32/Console/ANSI/IO.html +220 -0
  75. data/vendor/Console/doc/classes/Win32/Console/ANSI/IO.src/M000035.html +32 -0
  76. data/vendor/Console/doc/classes/Win32/Console/ANSI/IO.src/M000036.html +205 -0
  77. data/vendor/Console/doc/classes/Win32/Console/ANSI/IO.src/M000037.html +40 -0
  78. data/vendor/Console/doc/classes/Win32/Console/ANSI/IO.src/M000038.html +25 -0
  79. data/vendor/Console/doc/classes/Win32/Console/API.html +758 -0
  80. data/vendor/Console/doc/classes/Win32/Console/API.src/M000039.html +27 -0
  81. data/vendor/Console/doc/classes/Win32/Console/API.src/M000040.html +27 -0
  82. data/vendor/Console/doc/classes/Win32/Console/API.src/M000041.html +27 -0
  83. data/vendor/Console/doc/classes/Win32/Console/API.src/M000042.html +32 -0
  84. data/vendor/Console/doc/classes/Win32/Console/API.src/M000043.html +32 -0
  85. data/vendor/Console/doc/classes/Win32/Console/API.src/M000044.html +28 -0
  86. data/vendor/Console/doc/classes/Win32/Console/API.src/M000045.html +26 -0
  87. data/vendor/Console/doc/classes/Win32/Console/API.src/M000046.html +26 -0
  88. data/vendor/Console/doc/classes/Win32/Console/API.src/M000047.html +27 -0
  89. data/vendor/Console/doc/classes/Win32/Console/API.src/M000048.html +30 -0
  90. data/vendor/Console/doc/classes/Win32/Console/API.src/M000049.html +29 -0
  91. data/vendor/Console/doc/classes/Win32/Console/API.src/M000050.html +27 -0
  92. data/vendor/Console/doc/classes/Win32/Console/API.src/M000051.html +28 -0
  93. data/vendor/Console/doc/classes/Win32/Console/API.src/M000052.html +30 -0
  94. data/vendor/Console/doc/classes/Win32/Console/API.src/M000053.html +27 -0
  95. data/vendor/Console/doc/classes/Win32/Console/API.src/M000054.html +29 -0
  96. data/vendor/Console/doc/classes/Win32/Console/API.src/M000055.html +29 -0
  97. data/vendor/Console/doc/classes/Win32/Console/API.src/M000056.html +28 -0
  98. data/vendor/Console/doc/classes/Win32/Console/API.src/M000057.html +27 -0
  99. data/vendor/Console/doc/classes/Win32/Console/API.src/M000058.html +47 -0
  100. data/vendor/Console/doc/classes/Win32/Console/API.src/M000059.html +32 -0
  101. data/vendor/Console/doc/classes/Win32/Console/API.src/M000060.html +47 -0
  102. data/vendor/Console/doc/classes/Win32/Console/API.src/M000061.html +34 -0
  103. data/vendor/Console/doc/classes/Win32/Console/API.src/M000062.html +32 -0
  104. data/vendor/Console/doc/classes/Win32/Console/API.src/M000063.html +32 -0
  105. data/vendor/Console/doc/classes/Win32/Console/API.src/M000064.html +35 -0
  106. data/vendor/Console/doc/classes/Win32/Console/API.src/M000065.html +26 -0
  107. data/vendor/Console/doc/classes/Win32/Console/API.src/M000066.html +27 -0
  108. data/vendor/Console/doc/classes/Win32/Console/API.src/M000067.html +29 -0
  109. data/vendor/Console/doc/classes/Win32/Console/API.src/M000068.html +27 -0
  110. data/vendor/Console/doc/classes/Win32/Console/API.src/M000069.html +27 -0
  111. data/vendor/Console/doc/classes/Win32/Console/API.src/M000070.html +28 -0
  112. data/vendor/Console/doc/classes/Win32/Console/API.src/M000071.html +27 -0
  113. data/vendor/Console/doc/classes/Win32/Console/API.src/M000072.html +26 -0
  114. data/vendor/Console/doc/classes/Win32/Console/API.src/M000073.html +27 -0
  115. data/vendor/Console/doc/classes/Win32/Console/API.src/M000074.html +31 -0
  116. data/vendor/Console/doc/classes/Win32/Console/API.src/M000075.html +27 -0
  117. data/vendor/Console/doc/classes/Win32/Console/API.src/M000076.html +32 -0
  118. data/vendor/Console/doc/classes/Win32/Console/API.src/M000077.html +27 -0
  119. data/vendor/Console/doc/classes/Win32/Console/API.src/M000078.html +32 -0
  120. data/vendor/Console/doc/classes/Win32/Console/API.src/M000079.html +32 -0
  121. data/vendor/Console/doc/classes/Win32/Console/API.src/M000080.html +32 -0
  122. data/vendor/Console/doc/classes/Win32/Console/Constants.html +360 -0
  123. data/vendor/Console/doc/created.rid +1 -0
  124. data/vendor/Console/doc/files/Console_ANSI_rdoc.html +407 -0
  125. data/vendor/Console/doc/files/Console_cpp.html +104 -0
  126. data/vendor/Console/doc/files/Console_rdoc.html +964 -0
  127. data/vendor/Console/doc/files/lib/Win32/Console/ANSI_rb.html +123 -0
  128. data/vendor/Console/doc/files/lib/Win32/Console_rb.html +297 -0
  129. data/vendor/Console/doc/fr_class_index.html +32 -0
  130. data/vendor/Console/doc/fr_file_index.html +31 -0
  131. data/vendor/Console/doc/fr_method_index.html +106 -0
  132. data/vendor/Console/doc/index.html +24 -0
  133. data/vendor/Console/doc/rdoc-style.css +172 -0
  134. data/vendor/Console/extconf.rb +18 -0
  135. data/vendor/Console/lib/Term/ansicolor.rb +76 -0
  136. data/vendor/Console/lib/Win32/Console.rb +970 -0
  137. data/vendor/Console/lib/Win32/Console/ANSI.rb +305 -0
  138. data/vendor/Console/test/test_cursor.rb +9 -0
  139. data/vendor/Console/test/test_mouse.rb +6 -0
  140. data/vendor/Console/test/test_readinput.rb +62 -0
  141. data/vendor/Console/test/test_readoutput.rb +52 -0
  142. data/vendor/Console/test/test_sendevent.rb +17 -0
  143. data/vendor/Console/test/test_title.rb +14 -0
  144. data/vendor/Console/test/test_write.rb +36 -0
  145. metadata +253 -0
@@ -0,0 +1,40 @@
1
+ require 'test/unit'
2
+ require 'clio/multicommand'
3
+
4
+ class TestCommand < Test::Unit::TestCase
5
+
6
+ class ExampleCommand < Clio::MultiCommand
7
+
8
+ def setup
9
+ @check = {}
10
+ end
11
+
12
+ # No arguments and no options.
13
+ def a
14
+ @check['a'] = true
15
+ end
16
+
17
+ # Takes only options.
18
+ def b(opts)
19
+ @check['b'] = opts
20
+ end
21
+
22
+ # Takes multiple arguments and options. (Ruby 1.9 only)
23
+ #def c(*args, opts)
24
+ #end
25
+
26
+ # opt 'a', :bolean, 'example option a'
27
+
28
+ # Takes one argument and options.
29
+ def d(args, opts)
30
+ @check['d'] = [args, opts]
31
+ end
32
+
33
+ def e(args, opts)
34
+ opts.has_only! %w{a b c}
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+
@@ -0,0 +1,28 @@
1
+ <notes>
2
+ <set label="FIXME">
3
+ <file src="lib/clio/progressbar.rb">
4
+ <note line="134" type="FIXME">FIXME: I don&apos;t know how portable it is.</note>
5
+ </file>
6
+ </set>
7
+ <set label="TODO">
8
+ <file src="lib/clio/string.rb">
9
+ <note line="76" type="TODO">TODO: No doubt the delegation will need to be made more robust.</note>
10
+ </file>
11
+ <file src="lib/clio/commandline.rb">
12
+ <note line="30" type="TODO">TODO: Rename this method.</note>
13
+ </file>
14
+ <file src="lib/clio/commandable.rb">
15
+ <note line="118" type="TODO">TODO: to_b if &apos;true&apos; or &apos;false&apos; ?</note>
16
+ </file>
17
+ <file src="lib/clio/runmode.rb">
18
+ <note line="117" type="TODO">TODO: Reduce to one, two at most.</note>
19
+ </file>
20
+ <file src="lib/clio/consoleutils.rb">
21
+ <note line="66" type="TODO">TODO: Don&apos;t know how portable #screen_width is.</note>
22
+ </file>
23
+ <file src="lib/clio/command.rb">
24
+ <note line="79" type="TODO">TODO: Support passing a string or *args, opts in place of ARGV.</note>
25
+ <note line="201" type="TODO">TODO: use clio/option</note>
26
+ </file>
27
+ </set>
28
+ </notes>
@@ -0,0 +1,25 @@
1
+ <html><head>
2
+ <title>Clio Code Statistics</title>
3
+ <link rel="stylesheet" type="text/css" href="log.css"/>
4
+ </head><body>
5
+ <div class="basic_statistics">
6
+ <h1>Clio -- Basic Code Statistics</h1>
7
+ <table class="counts" border="1">
8
+ <tr><th colspan="9"><h2>Code Counts</h2></th></tr>
9
+ <tr><th>TYPE</th><th>Total</th><th>Code</th><th>-%-</th><th>Docs</th><th>-%-</th><th>Blank</th><th>-%-</th><th>Files</th></tr>
10
+ <tr><th>Source</th><td>1780</td><td>888</td><td>49%</td><td>641</td><td>36%</td><td>251</td><td>14%</td><td>10</td></tr>
11
+ <tr><th>Test</th><td>125</td><td>81</td><td>4%</td><td>7</td><td>0%</td><td>37</td><td>2%</td><td>2</td></tr>
12
+ <tr><th>Total</th><td>1905</td><td>969</td><td>50%</td><td>648</td><td>34%</td><td>288</td><td>15%</td><td>12</td></tr>
13
+ </table>
14
+ <table class="ratios" border="1">
15
+ <tr><th colspan="6"><h2>Code Ratios</h2></th></tr>
16
+ <tr><th>RATIO</th><th>Code</th><th>Docs</th><th>Blank</th><th>Test</th><th>Total</th></tr>
17
+ <tr><th>Code</th><td> 1.0</td><td> 1.4</td><td> 3.5</td><td> 7.1</td><td> -</td></tr>
18
+ <tr><th>Docs</th><td> -</td><td> 1.0</td><td> 2.6</td><td> 5.1</td><td> -</td></tr>
19
+ <tr><th>Blank</th><td> -</td><td> -</td><td> 1.0</td><td> 2.0</td><td> -</td></tr>
20
+ <tr><th>Test</th><td> -</td><td> -</td><td> -</td><td> 1.0</td><td> -</td></tr>
21
+ <tr><th>Total</th><td> 2.0</td><td> 2.8</td><td> 7.1</td><td> 14.2</td><td> 1.0</td></tr>
22
+ </table>
23
+ <div class="date">Wed Sep 03 06:57:55 -0400 2008</div>
24
+ </div>
25
+ </body></html>
File without changes
@@ -0,0 +1,16 @@
1
+ Loaded suite [test/test_command.rb, test/test_commandline.rb]
2
+ Started
3
+ F...Loaded suite [test/test_command.rb, test/test_commandline.rb]
4
+ Started
5
+ ....Loaded suite [test/test_command.rb, test/test_commandline.rb]
6
+ Started
7
+ ............
8
+ Finished in 0.004846 seconds.
9
+
10
+ 12 tests, 13 assertions, 0 failures, 0 errors
11
+ Loaded suite [test/test_command.rb, test/test_commandline.rb]
12
+ Started
13
+ ............
14
+ Finished in 0.004963 seconds.
15
+
16
+ 12 tests, 13 assertions, 0 failures, 0 errors
Binary file
@@ -0,0 +1,7 @@
1
+ # This is just an example of how reap
2
+ # can be extended on a per-project basis.
3
+ #
4
+ # There is nothing special about these scripts
5
+ # they are just ruby and loaded up once the
6
+ # main or reap has been loaded.
7
+
@@ -0,0 +1,4 @@
1
+ module Clio
2
+ VERSION = "<%= version %>"
3
+ end
4
+
@@ -0,0 +1,319 @@
1
+ # = ANSICode
2
+ #
3
+ # Module which makes it very easy to use ANSI codes.
4
+ # These are esspecially nice for beautifying shell output.
5
+ #
6
+ # include ANSICode
7
+ #
8
+ # p red, "Hello", blue, "World"
9
+ # => "\e[31mHello\e[34mWorld"
10
+ #
11
+ # p red { "Hello" } + blue { "World" }
12
+ # => "\e[31mHello\e[0m\e[34mWorld\e[0m"
13
+ #
14
+ # == Supported ANSI Comands
15
+ #
16
+ # The following is a list of supported codes.
17
+ #
18
+ # save
19
+ # restore
20
+ # clear_screen
21
+ # cls # synonym for :clear_screen
22
+ # clear_line
23
+ # clr # synonym for :clear_line
24
+ # move
25
+ # up
26
+ # down
27
+ # left
28
+ # right
29
+ # display
30
+ #
31
+ # clear
32
+ # reset # synonym for :clear
33
+ # bold
34
+ # dark
35
+ # italic # not widely implemented
36
+ # underline
37
+ # underscore # synonym for :underline
38
+ # blink
39
+ # rapid_blink # not widely implemented
40
+ # negative # no reverse because of String#reverse
41
+ # concealed
42
+ # strikethrough # not widely implemented
43
+ #
44
+ # black
45
+ # red
46
+ # green
47
+ # yellow
48
+ # blue
49
+ # magenta
50
+ # cyan
51
+ # white
52
+ #
53
+ # on_black
54
+ # on_red
55
+ # on_green
56
+ # on_yellow
57
+ # on_blue
58
+ # on_magenta
59
+ # on_cyan
60
+ # on_white
61
+ #
62
+ # == Authors
63
+ #
64
+ # * Florian Frank
65
+ # * Thomas Sawyer
66
+ #
67
+ # == Speical Thanks
68
+ #
69
+ # Special thanks to Florian Frank. ANSICode is a partial adaptation
70
+ # of ANSIColor, Copyright (c) 2002 Florian Frank, LGPL.
71
+ #
72
+ # == Todo
73
+ #
74
+ # * Need to add rest of ANSI codes. Include modes?
75
+ # * Re-evaluate how color/yielding methods are defined.
76
+ # * Maybe up, down, right, left should have yielding methods too?
77
+ #
78
+ # == Copying
79
+ #
80
+ # Copyright (c) 2004 Florian Frank, Thomas Sawyer
81
+ #
82
+ # Ruby License
83
+ #
84
+ # This module is free software. You may use, modify, and/or redistribute this
85
+ # software under the same terms as Ruby.
86
+ #
87
+ # This program is distributed in the hope that it will be useful, but WITHOUT
88
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
89
+ # FOR A PARTICULAR PURPOSE.
90
+
91
+
92
+ # = ANSICode
93
+ #
94
+ # Module which makes it very easy to use ANSI codes.
95
+ # These are esspecially nice for beautifying shell output.
96
+ #
97
+ # include ANSICode
98
+ #
99
+ # p red, "Hello", blue, "World"
100
+ # => "\e[31mHello\e[34mWorld"
101
+ #
102
+ # p red { "Hello" } + blue { "World" }
103
+ # => "\e[31mHello\e[0m\e[34mWorld\e[0m"
104
+ #
105
+ # == Supported ANSI Comands
106
+ #
107
+ # The following is a list of supported codes.
108
+ #
109
+ # save
110
+ # restore
111
+ # clear_screen
112
+ # cls # synonym for :clear_screen
113
+ # clear_line
114
+ # clr # synonym for :clear_line
115
+ # move
116
+ # up
117
+ # down
118
+ # left
119
+ # right
120
+ # display
121
+ #
122
+ # clear
123
+ # reset # synonym for :clear
124
+ # bold
125
+ # dark
126
+ # italic # not widely implemented
127
+ # underline
128
+ # underscore # synonym for :underline
129
+ # blink
130
+ # rapid_blink # not widely implemented
131
+ # negative # no reverse because of String#reverse
132
+ # concealed
133
+ # strikethrough # not widely implemented
134
+ #
135
+ # black
136
+ # red
137
+ # green
138
+ # yellow
139
+ # blue
140
+ # magenta
141
+ # cyan
142
+ # white
143
+ #
144
+ # on_black
145
+ # on_red
146
+ # on_green
147
+ # on_yellow
148
+ # on_blue
149
+ # on_magenta
150
+ # on_cyan
151
+ # on_white
152
+ #
153
+
154
+ module Clio
155
+
156
+ module ANSICode
157
+
158
+ extend self
159
+
160
+ # Save current cursor positon.
161
+
162
+ def save
163
+ "\e[s"
164
+ end
165
+
166
+ # Restore saved cursor positon.
167
+
168
+ def restore
169
+ "\e[u"
170
+ end
171
+
172
+ # Clear the screen and move cursor to home.
173
+
174
+ def clear_screen
175
+ "\e[2J"
176
+ end
177
+ alias_method :cls, :clear_screen
178
+
179
+ # Clear to the end of the current line.
180
+
181
+ def clear_line
182
+ "\e[K"
183
+ end
184
+ alias_method :clr, :clear_line
185
+
186
+ #--
187
+ #def position
188
+ # "\e[#;#R"
189
+ #end
190
+ #++
191
+
192
+ # Move curose to line and column.
193
+
194
+ def move( line, column=0 )
195
+ "\e[#{line.to_i};#{column.to_i}H"
196
+ end
197
+
198
+ # Move cursor up a specificed number of spaces.
199
+
200
+ def up( spaces=1 )
201
+ "\e[#{spaces.to_i}A"
202
+ end
203
+
204
+ # Move cursor down a specificed number of spaces.
205
+
206
+ def down( spaces=1 )
207
+ "\e[#{spaces.to_i}B"
208
+ end
209
+
210
+ # Move cursor left a specificed number of spaces.
211
+
212
+ def left( spaces=1 )
213
+ "\e[#{spaces.to_i}D"
214
+ end
215
+
216
+ # Move cursor right a specificed number of spaces.
217
+
218
+ def right( spaces=1 )
219
+ "\e[#{spaces.to_i}C"
220
+ end
221
+
222
+ # Like +move+ but returns to original positon
223
+ # after yielding block or adding string argument.
224
+
225
+ def display( line, column=0, string=nil ) #:yield:
226
+ result = "\e[s"
227
+ result << "\e[#{line.to_i};#{column.to_i}H"
228
+ if block_given?
229
+ result << yield
230
+ result << "\e[u"
231
+ elsif string
232
+ result << string
233
+ result << "\e[u"
234
+ elsif respond_to?(:to_str)
235
+ result << self
236
+ result << "\e[u"
237
+ end
238
+ return result
239
+ end
240
+
241
+ # Define color codes.
242
+
243
+ def self.define_ansicolor_method(name,code)
244
+ class_eval <<-HERE
245
+ def #{name.to_s}(string = nil)
246
+ result = "\e[#{code}m"
247
+ if block_given?
248
+ result << yield
249
+ result << "\e[0m"
250
+ elsif string
251
+ result << string
252
+ result << "\e[0m"
253
+ elsif respond_to?(:to_str)
254
+ result << self
255
+ result << "\e[0m"
256
+ end
257
+ return result
258
+ end
259
+ HERE
260
+ end
261
+
262
+ @@colors = [
263
+ [ :clear , 0 ],
264
+ [ :reset , 0 ], # synonym for :clear
265
+ [ :bold , 1 ],
266
+ [ :dark , 2 ],
267
+ [ :italic , 3 ], # not widely implemented
268
+ [ :underline , 4 ],
269
+ [ :underscore , 4 ], # synonym for :underline
270
+ [ :blink , 5 ],
271
+ [ :rapid_blink , 6 ], # not widely implemented
272
+ [ :negative , 7 ], # no reverse because of String#reverse
273
+ [ :concealed , 8 ],
274
+ [ :strikethrough, 9 ], # not widely implemented
275
+ [ :black , 30 ],
276
+ [ :red , 31 ],
277
+ [ :green , 32 ],
278
+ [ :yellow , 33 ],
279
+ [ :blue , 34 ],
280
+ [ :magenta , 35 ],
281
+ [ :cyan , 36 ],
282
+ [ :white , 37 ],
283
+ [ :on_black , 40 ],
284
+ [ :on_red , 41 ],
285
+ [ :on_green , 42 ],
286
+ [ :on_yellow , 43 ],
287
+ [ :on_blue , 44 ],
288
+ [ :on_magenta , 45 ],
289
+ [ :on_cyan , 46 ],
290
+ [ :on_white , 47 ],
291
+ ]
292
+
293
+ @@colors.each do |c, v|
294
+ define_ansicolor_method(c, v)
295
+ end
296
+
297
+ ColoredRegexp = /\e\[([34][0-7]|[0-9])m/
298
+
299
+ def uncolored(string = nil)
300
+ if block_given?
301
+ yield.gsub(ColoredRegexp, '')
302
+ elsif string
303
+ string.gsub(ColoredRegexp, '')
304
+ elsif respond_to?(:to_str)
305
+ gsub(ColoredRegexp, '')
306
+ else
307
+ ''
308
+ end
309
+ end
310
+
311
+ module_function
312
+
313
+ def colors
314
+ @@colors.map { |c| c[0] }
315
+ end
316
+
317
+ end
318
+
319
+ end