ripl-color_result 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +7 -0
- data/README.rdoc +7 -3
- data/lib/ripl/color_result/{default.rb → default_colorizer.rb} +3 -100
- data/lib/ripl/color_result.rb +56 -3
- metadata +5 -5
data/CHANGELOG.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -4,13 +4,13 @@ This {ripl}[http://github.com/cldwalker/ripl] plugin colorizes your results.
|
|
4
4
|
== Install
|
5
5
|
Install the gem with:
|
6
6
|
|
7
|
-
|
7
|
+
sudo gem install ripl-color_result
|
8
8
|
|
9
9
|
== Usage
|
10
10
|
|
11
11
|
Add to your ~/.riplrc
|
12
12
|
|
13
|
-
|
13
|
+
require 'ripl/color_result'
|
14
14
|
|
15
15
|
You can choose a <tt>:color_result_engine</tt>. By default, the bundled +Wirble+-like colorization is used. Possible other values are:
|
16
16
|
|
@@ -19,10 +19,14 @@ You can choose a <tt>:color_result_engine</tt>. By default, the bundled +Wirble+
|
|
19
19
|
|
20
20
|
Example (in your ~/.riplrc)
|
21
21
|
|
22
|
-
|
22
|
+
Ripl.config[:color_result_engine] = :coderay
|
23
23
|
|
24
24
|
Set it to +nil+ to deactivate result colorization.
|
25
25
|
|
26
|
+
You can change the colors used by the default colorization by editing the <tt>:color_result_scheme</tt> hash:
|
27
|
+
|
28
|
+
Ripl.config[:color_result_scheme][:comma] = :green
|
29
|
+
|
26
30
|
== Credits
|
27
31
|
|
28
32
|
The default colorization uses code from Wirble
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Default colorization module:
|
2
2
|
# Code taken from the (blackwinter) wirble gem, adjusted api. See COPYING for credits.
|
3
3
|
|
4
|
-
class << Ripl::ColorResult::
|
4
|
+
class << Ripl::ColorResult::DefaultColorizer = Module.new
|
5
5
|
def tokenize(str)
|
6
6
|
raise 'missing block' unless block_given?
|
7
7
|
chars = str.split(//)
|
@@ -161,108 +161,11 @@ class << Ripl::ColorResult::Default = Module.new
|
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
164
|
-
#
|
165
|
-
# Terminal escape codes for colors.
|
166
|
-
#
|
167
|
-
COLORS = {
|
168
|
-
:nothing => '0;0',
|
169
|
-
:black => '0;30',
|
170
|
-
:red => '0;31',
|
171
|
-
:green => '0;32',
|
172
|
-
:brown => '0;33',
|
173
|
-
:blue => '0;34',
|
174
|
-
:cyan => '0;36',
|
175
|
-
:purple => '0;35',
|
176
|
-
:light_gray => '0;37',
|
177
|
-
:dark_gray => '1;30',
|
178
|
-
:light_red => '1;31',
|
179
|
-
:light_green => '1;32',
|
180
|
-
:yellow => '1;33',
|
181
|
-
:light_blue => '1;34',
|
182
|
-
:light_cyan => '1;36',
|
183
|
-
:light_purple => '1;35',
|
184
|
-
:white => '1;37',
|
185
|
-
}
|
186
|
-
|
187
164
|
#
|
188
165
|
# Return the escape code for a given color.
|
189
166
|
#
|
190
167
|
def get_color(key)
|
191
|
-
COLORS.key?(key) && "\033[#{COLORS[key]}m"
|
192
|
-
end
|
193
|
-
|
194
|
-
#
|
195
|
-
# Default Wirble color scheme.
|
196
|
-
#
|
197
|
-
DEFAULT_SCHEME = {
|
198
|
-
# delimiter colors
|
199
|
-
:comma => :blue,
|
200
|
-
:refers => :blue,
|
201
|
-
|
202
|
-
# container colors (hash and array)
|
203
|
-
:open_hash => :green,
|
204
|
-
:close_hash => :green,
|
205
|
-
:open_array => :green,
|
206
|
-
:close_array => :green,
|
207
|
-
|
208
|
-
# object colors
|
209
|
-
:open_object => :light_red,
|
210
|
-
:object_class => :white,
|
211
|
-
:object_addr_prefix => :blue,
|
212
|
-
:object_line_prefix => :blue,
|
213
|
-
:close_object => :light_red,
|
214
|
-
|
215
|
-
# symbol colors
|
216
|
-
:symbol => :yellow,
|
217
|
-
:symbol_prefix => :yellow,
|
218
|
-
|
219
|
-
# string colors
|
220
|
-
:open_string => :red,
|
221
|
-
:string => :cyan,
|
222
|
-
:close_string => :red,
|
223
|
-
|
224
|
-
# misc colors
|
225
|
-
:number => :cyan,
|
226
|
-
:keyword => :green,
|
227
|
-
:class => :light_green,
|
228
|
-
:range => :red,
|
229
|
-
}
|
230
|
-
|
231
|
-
#
|
232
|
-
# Fruity testing colors.
|
233
|
-
#
|
234
|
-
TESTING_SCHEME = {
|
235
|
-
:comma => :red,
|
236
|
-
:refers => :red,
|
237
|
-
:open_hash => :blue,
|
238
|
-
:close_hash => :blue,
|
239
|
-
:open_array => :green,
|
240
|
-
:close_array => :green,
|
241
|
-
:open_object => :light_red,
|
242
|
-
:object_class => :light_green,
|
243
|
-
:object_addr => :purple,
|
244
|
-
:object_line => :light_purple,
|
245
|
-
:close_object => :light_red,
|
246
|
-
:symbol => :yellow,
|
247
|
-
:symbol_prefix => :yellow,
|
248
|
-
:number => :cyan,
|
249
|
-
:string => :cyan,
|
250
|
-
:keyword => :white,
|
251
|
-
:range => :light_blue,
|
252
|
-
}
|
253
|
-
|
254
|
-
#
|
255
|
-
# Set color map to hash
|
256
|
-
#
|
257
|
-
def scheme=(hash)
|
258
|
-
@scheme = hash
|
259
|
-
end
|
260
|
-
|
261
|
-
#
|
262
|
-
# Get current color map
|
263
|
-
#
|
264
|
-
def scheme
|
265
|
-
@scheme ||= {}.update(DEFAULT_SCHEME)
|
168
|
+
Ripl::ColorResult::COLORS.key?(key) && "\033[#{Ripl::ColorResult::COLORS[key]}m"
|
266
169
|
end
|
267
170
|
|
268
171
|
#
|
@@ -279,7 +182,7 @@ class << Ripl::ColorResult::Default = Module.new
|
|
279
182
|
def colorize_code(str)
|
280
183
|
ret, nocol = '', get_color(:nothing)
|
281
184
|
tokenize(str) do |tok, val|
|
282
|
-
ret << colorize_string(val,
|
185
|
+
ret << colorize_string(val, Ripl.config[:color_result_scheme][tok])
|
283
186
|
end
|
284
187
|
ret
|
285
188
|
rescue # catch any errors from the tokenizer (just in case)
|
data/lib/ripl/color_result.rb
CHANGED
@@ -2,7 +2,26 @@ require 'ripl'
|
|
2
2
|
|
3
3
|
module Ripl
|
4
4
|
module ColorResult
|
5
|
-
VERSION = '0.1.
|
5
|
+
VERSION = '0.1.2'
|
6
|
+
COLORS = {
|
7
|
+
:nothing => '0;0',
|
8
|
+
:black => '0;30',
|
9
|
+
:red => '0;31',
|
10
|
+
:green => '0;32',
|
11
|
+
:brown => '0;33',
|
12
|
+
:blue => '0;34',
|
13
|
+
:purple => '0;35',
|
14
|
+
:cyan => '0;36',
|
15
|
+
:light_gray => '0;37',
|
16
|
+
:dark_gray => '1;30',
|
17
|
+
:light_red => '1;31',
|
18
|
+
:light_green => '1;32',
|
19
|
+
:yellow => '1;33',
|
20
|
+
:light_blue => '1;34',
|
21
|
+
:light_purple => '1;35',
|
22
|
+
:light_cyan => '1;36',
|
23
|
+
:white => '1;37',
|
24
|
+
}
|
6
25
|
|
7
26
|
# def inspect_result(result)
|
8
27
|
# result.inspect
|
@@ -28,8 +47,8 @@ module Ripl
|
|
28
47
|
require 'ap'
|
29
48
|
result.awesome_inspect
|
30
49
|
else # :default
|
31
|
-
require 'ripl/color_result/
|
32
|
-
|
50
|
+
require 'ripl/color_result/default_colorizer'
|
51
|
+
DefaultColorizer.colorize_code( result.inspect )
|
33
52
|
end
|
34
53
|
|
35
54
|
end
|
@@ -37,6 +56,40 @@ module Ripl
|
|
37
56
|
end
|
38
57
|
|
39
58
|
Ripl::Shell.send :include, Ripl::ColorResult if defined? Ripl::Shell
|
59
|
+
|
40
60
|
Ripl.config[:color_result_engine] ||= :default
|
61
|
+
Ripl.config[:color_result_scheme] ||= { # color scheme for default colorization, original from wirble
|
62
|
+
# delimiter colors
|
63
|
+
:comma => :blue,
|
64
|
+
:refers => :blue,
|
65
|
+
|
66
|
+
# container colors (hash and array)
|
67
|
+
:open_hash => :green,
|
68
|
+
:close_hash => :green,
|
69
|
+
:open_array => :green,
|
70
|
+
:close_array => :green,
|
71
|
+
|
72
|
+
# object colors
|
73
|
+
:open_object => :light_red,
|
74
|
+
:object_class => :white,
|
75
|
+
:object_addr_prefix => :blue,
|
76
|
+
:object_line_prefix => :blue,
|
77
|
+
:close_object => :light_red,
|
78
|
+
|
79
|
+
# symbol colors
|
80
|
+
:symbol => :yellow,
|
81
|
+
:symbol_prefix => :yellow,
|
82
|
+
|
83
|
+
# string colors
|
84
|
+
:open_string => :red,
|
85
|
+
:string => :cyan,
|
86
|
+
:close_string => :red,
|
87
|
+
|
88
|
+
# misc colors
|
89
|
+
:number => :cyan,
|
90
|
+
:keyword => :green,
|
91
|
+
:class => :light_green,
|
92
|
+
:range => :red,
|
93
|
+
}
|
41
94
|
|
42
95
|
# J-_-L
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ripl-color_result
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jan Lelis
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-18 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -44,7 +44,7 @@ extra_rdoc_files:
|
|
44
44
|
- README.rdoc
|
45
45
|
- COPYING
|
46
46
|
files:
|
47
|
-
- lib/ripl/color_result/
|
47
|
+
- lib/ripl/color_result/default_colorizer.rb
|
48
48
|
- lib/ripl/color_result.rb
|
49
49
|
- README.rdoc
|
50
50
|
- CHANGELOG.rdoc
|