wirb 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +8 -0
- data/README.rdoc +31 -9
- data/data/wirb/classic_paint.yml +137 -0
- data/data/wirb/classic_wirb0.yml +69 -0
- data/lib/wirb.rb +103 -30
- data/lib/wirb/colorizer.rb +26 -0
- data/lib/wirb/colorizer/highline.rb +16 -0
- data/lib/wirb/colorizer/paint.rb +11 -0
- data/lib/wirb/{colors.rb → colorizer/wirb0.rb} +9 -3
- data/lib/wirb/colorizer/wirb0_highline.rb +73 -0
- data/lib/wirb/colorizer/wirb0_paint.rb +71 -0
- data/lib/wirb/colorizer/wirble.rb +30 -0
- data/lib/wirb/tokenizer.rb +1 -1
- data/lib/wirb/version.rb +1 -1
- data/spec/colorizer_highline_spec.rb +23 -0
- data/spec/colorizer_paint_spec.rb +33 -0
- data/spec/colorizer_spec.rb +67 -0
- data/spec/colorizer_wirb0_highline_spec.rb +78 -0
- data/spec/colorizer_wirb0_paint_spec.rb +35 -0
- data/spec/colorizer_wirb0_spec.rb +11 -0
- data/spec/colorizer_wirble_spec.rb +24 -0
- data/spec/spec_helper.rb +117 -6
- data/wirb.gemspec +6 -4
- metadata +31 -6
- data/lib/wirb/schema.rb +0 -72
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
== 0.4.0
|
2
|
+
* Add support for loading color schemas from yaml files
|
3
|
+
* Add ability to hook in a custom colorizer
|
4
|
+
* Support for Paint, HighLine (1.6.3), old Wirb color names (Wirb0) and even older Wirble color names
|
5
|
+
* Wirb0(-like) colors are still default, but will be dropped (as default) in 1.0
|
6
|
+
* Provides hybrid connectors to Paint and HighLine that also enable Wirb colors (Wirb0_Paint, Wirb0_HighLine)
|
7
|
+
* Only display error on failed tokenizations if $VERBOSE is not false
|
8
|
+
|
1
9
|
== 0.3.2
|
2
10
|
* Improve :<=> parsing :D
|
3
11
|
* Support gem requirements (:gem_requirement_condition, :gem_requirement_version) and gem dependencies
|
data/README.rdoc
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
== Wavy Interactive Ruby
|
2
|
-
*Wirb* colorizes your inspected Ruby objects. It is based on Wirble[http://pablotron.org/software/wirble/], but only provides and improves result highlighting.
|
2
|
+
*Wirb* colorizes your inspected Ruby objects. It is based on Wirble[http://pablotron.org/software/wirble/], but only provides and improves result highlighting. It also provides a colorization engine abstraction layer and offers flexible schemas using yaml. Wirb is part of the {irbtools suite}[https://github.com/janlelis/irbtools].
|
3
3
|
|
4
|
-
http://travis-ci.org/janlelis/wirb.png
|
4
|
+
{Travis}[http://travis-ci.org/janlelis/wirb]: http://travis-ci.org/janlelis/wirb.png
|
5
5
|
|
6
6
|
== Install
|
7
7
|
Install the gem with:
|
@@ -23,15 +23,28 @@ Add to your <tt>~/.irbrc</tt>
|
|
23
23
|
* Can be used without irb
|
24
24
|
* Limited stdlib/gem objects support (e.g. Set, Gem::Requirement)
|
25
25
|
* Supports 1.8, 1.9, jruby, rbx, head
|
26
|
+
* Usable with any supported terminal colors engine
|
27
|
+
* Color schemas in yaml files
|
26
28
|
|
27
|
-
==
|
28
|
-
|
29
|
+
== Colors
|
30
|
+
To only tweak some colors, take a look at the <tt>Wirb.schema</tt> hash. To use a custom schema, inspect the yaml files in the <tt>data/wirb/</tt> directory. You can create your own schema and load it using <tt>Wirb.load_schema(path_to_yaml_file)</tt>. Alternatively, you can use one of the bundled ones by passing a symbol instead of a path.
|
29
31
|
|
30
|
-
|
32
|
+
=== Colorizer
|
33
|
+
Wirb supports multiple colorization engines. Available engines can be found in <tt>lib/wirb/colorizer/*</tt>. Some of them require external gems as dependencies (e.g. HighLine). The current default engine is <em>Wirb0</em> (the one of previous Wirb versions, inherited from the original Wirble). It will be dropped as default engine in 1.0 (later this year), because it uses wrong color names. It will be replaced by Paint[https://github.com/janlelis/paint] or a simple colorizer engine with proper color names. You can change the colorizer using:
|
31
34
|
|
32
|
-
Wirb
|
35
|
+
Wirb.load_colorizer :Paint # or :HighLine or whatever
|
33
36
|
|
34
|
-
|
37
|
+
Be careful, though! You also need to select a color schema that supports your colorizer (Schemas define supported colorizers using the <tt>:colorizer</tt> key). Load a schema with:
|
38
|
+
|
39
|
+
Wirb.load_schema! :classic_paint # make sure your colorizer is paint
|
40
|
+
|
41
|
+
You can automatically use the first colorizer of the schema by using the non-exclamation mark version:
|
42
|
+
|
43
|
+
Wirb.load_schema :classic_paint # will fail if paint is not installed
|
44
|
+
|
45
|
+
Color schemas wanted! You've got a good looking alternative color schema? Please fork and add it to <tt>data/wirb/*</tt> :)
|
46
|
+
|
47
|
+
Colorizers wanted! Your favorite terminal colors gem is not supported yet? Please fork and add it to <tt>lib/wirb/colorizer/*</tt> :D
|
35
48
|
|
36
49
|
== wp
|
37
50
|
You can colorize any object with <tt>wp</tt> (wavy_print):
|
@@ -43,11 +56,20 @@ You can colorize any object with <tt>wp</tt> (wavy_print):
|
|
43
56
|
* Configure views for specific objects: hirb[https://github.com/cldwalker/hirb]
|
44
57
|
* Wirb is part of: irbtools[https://github.com/janlelis/irbtools]
|
45
58
|
* ripl is an irb alternative, syntax highlighting plugin (uses wirb by default): ripl-color_result[https://github.com/janlelis/ripl-color_result]
|
59
|
+
* Advanced terminal color gems: Paint[https://github.com/janlelis/paint], HighLine[https://github.com/JEG2/highline]
|
60
|
+
|
61
|
+
== Todo
|
62
|
+
* Tests for schema stuff
|
63
|
+
* More colorizers and themes
|
64
|
+
* More support for stdlib (most important: Complex)
|
46
65
|
|
47
66
|
== Credits
|
48
|
-
Copyright (c) 2011 Jan Lelis <http://rbjl.net>, see COPYING for details.
|
67
|
+
* Copyright (c) 2011 Jan Lelis <http://rbjl.net>, see COPYING for details.
|
68
|
+
|
69
|
+
Contributions[https://github.com/janlelis/wirb/contributors] by and thanks to:
|
70
|
+
* {Richard LeBer}[https://github.com/rleber]
|
49
71
|
|
50
|
-
|
72
|
+
Influenced by code from and thanks to:
|
51
73
|
* Copyright (C) 2006-2009 Paul Duncan <pabs@pablotron.org>
|
52
74
|
|
53
75
|
J-_-L
|
@@ -0,0 +1,137 @@
|
|
1
|
+
colorizer:
|
2
|
+
- Paint
|
3
|
+
- Wirb0_Paint
|
4
|
+
|
5
|
+
# container
|
6
|
+
open_hash:
|
7
|
+
- :green
|
8
|
+
- :bright
|
9
|
+
close_hash:
|
10
|
+
- :green
|
11
|
+
- :bright
|
12
|
+
open_array:
|
13
|
+
- :green
|
14
|
+
- :bright
|
15
|
+
close_array:
|
16
|
+
- nil
|
17
|
+
- :green
|
18
|
+
- :bright
|
19
|
+
open_set:
|
20
|
+
- :green
|
21
|
+
close_set:
|
22
|
+
- :green
|
23
|
+
|
24
|
+
# delimiter
|
25
|
+
comma: :green
|
26
|
+
refers: :green
|
27
|
+
|
28
|
+
# class
|
29
|
+
class:
|
30
|
+
- :green
|
31
|
+
- :bright
|
32
|
+
class_separator:
|
33
|
+
- :green
|
34
|
+
object_class:
|
35
|
+
- :green
|
36
|
+
- :bright
|
37
|
+
|
38
|
+
# object
|
39
|
+
open_object:
|
40
|
+
- :green
|
41
|
+
object_description_prefix:
|
42
|
+
- :green
|
43
|
+
object_description:
|
44
|
+
- :yellow
|
45
|
+
object_address_prefix:
|
46
|
+
- :yellow
|
47
|
+
- :underline
|
48
|
+
object_address:
|
49
|
+
- :yellow
|
50
|
+
- :underline
|
51
|
+
object_line_prefix:
|
52
|
+
- :yellow
|
53
|
+
- :underline
|
54
|
+
object_line:
|
55
|
+
- :yellow
|
56
|
+
- :underline
|
57
|
+
object_line_number:
|
58
|
+
- :brown
|
59
|
+
- :underline
|
60
|
+
object_variable_prefix:
|
61
|
+
- :purple
|
62
|
+
- :bright
|
63
|
+
object_variable:
|
64
|
+
- :purple
|
65
|
+
- :bright
|
66
|
+
close_object:
|
67
|
+
- :green
|
68
|
+
|
69
|
+
# symbol
|
70
|
+
symbol_prefix:
|
71
|
+
- :yellow
|
72
|
+
- :bright
|
73
|
+
symbol:
|
74
|
+
- :yellow
|
75
|
+
- :bright
|
76
|
+
open_symbol_string:
|
77
|
+
- :yellow
|
78
|
+
symbol_string:
|
79
|
+
- :yellow
|
80
|
+
- :bright
|
81
|
+
close_symbol_string:
|
82
|
+
- :yellow
|
83
|
+
|
84
|
+
# string
|
85
|
+
open_string:
|
86
|
+
- :white
|
87
|
+
string:
|
88
|
+
- :black
|
89
|
+
- :bright
|
90
|
+
close_string:
|
91
|
+
- :white
|
92
|
+
|
93
|
+
# regexp
|
94
|
+
open_regexp:
|
95
|
+
- :blue
|
96
|
+
- :bright
|
97
|
+
regexp:
|
98
|
+
- :white
|
99
|
+
close_regexp:
|
100
|
+
- :blue
|
101
|
+
- :bright
|
102
|
+
regexp_flags:
|
103
|
+
- :red
|
104
|
+
- :bright
|
105
|
+
|
106
|
+
# number
|
107
|
+
number:
|
108
|
+
- :cyan
|
109
|
+
range:
|
110
|
+
- :red
|
111
|
+
open_rational:
|
112
|
+
- :cyan
|
113
|
+
- :bright
|
114
|
+
rational_separator:
|
115
|
+
- :cyan
|
116
|
+
- :bright
|
117
|
+
close_rational:
|
118
|
+
- :cyan
|
119
|
+
- :bright
|
120
|
+
|
121
|
+
# misc
|
122
|
+
#default:
|
123
|
+
#keyword:
|
124
|
+
time:
|
125
|
+
- :purple
|
126
|
+
nil:
|
127
|
+
- :red
|
128
|
+
- :bright
|
129
|
+
false:
|
130
|
+
- :red
|
131
|
+
true:
|
132
|
+
- :green
|
133
|
+
gem_requirement_condition:
|
134
|
+
- :cyan
|
135
|
+
gem_requirement_version:
|
136
|
+
- :cyan
|
137
|
+
- :bright
|
@@ -0,0 +1,69 @@
|
|
1
|
+
colorizer:
|
2
|
+
- Wirb0
|
3
|
+
- Wirb0_Paint
|
4
|
+
- Wirb0_HighLine
|
5
|
+
|
6
|
+
# container
|
7
|
+
open_hash: light_green
|
8
|
+
close_hash: light_green
|
9
|
+
open_array: light_green
|
10
|
+
close_array: light_green
|
11
|
+
open_set: green
|
12
|
+
close_set: green
|
13
|
+
|
14
|
+
# delimiter
|
15
|
+
comma: green
|
16
|
+
refers: green
|
17
|
+
|
18
|
+
# class
|
19
|
+
class: light_green
|
20
|
+
class_separator: green
|
21
|
+
object_class: light_green
|
22
|
+
|
23
|
+
# object
|
24
|
+
open_object: green
|
25
|
+
object_description_prefix: green
|
26
|
+
object_description: brown
|
27
|
+
object_address_prefix: brown_underline
|
28
|
+
object_address: brown_underline
|
29
|
+
object_line_prefix: brown_underline
|
30
|
+
object_line: brown_underline
|
31
|
+
object_line_number: brown_underline
|
32
|
+
object_variable_prefix: light_purple
|
33
|
+
object_variable: light_purple
|
34
|
+
close_object: green
|
35
|
+
|
36
|
+
# symbol
|
37
|
+
symbol_prefix: yellow
|
38
|
+
symbol: yellow
|
39
|
+
open_symbol_string: brown
|
40
|
+
symbol_string: yellow
|
41
|
+
close_symbol_string: brown
|
42
|
+
|
43
|
+
# string
|
44
|
+
open_string: light_gray
|
45
|
+
string: dark_gray
|
46
|
+
close_string: light_gray
|
47
|
+
|
48
|
+
# regexp
|
49
|
+
open_regexp: light_blue
|
50
|
+
regexp: dark_gray
|
51
|
+
close_regexp: light_blue
|
52
|
+
regexp_flags: light_red
|
53
|
+
|
54
|
+
# number
|
55
|
+
number: cyan
|
56
|
+
range: red
|
57
|
+
open_rational: light_cyan
|
58
|
+
rational_separator: light_cyan
|
59
|
+
close_rational: light_cyan
|
60
|
+
|
61
|
+
# misc
|
62
|
+
#default:
|
63
|
+
#keyword:
|
64
|
+
time: purple
|
65
|
+
nil: light_red
|
66
|
+
false: red
|
67
|
+
true: green
|
68
|
+
gem_requirement_condition: cyan
|
69
|
+
gem_requirement_version: light_cyan
|
data/lib/wirb.rb
CHANGED
@@ -1,28 +1,97 @@
|
|
1
|
-
require File.
|
2
|
-
require File.
|
3
|
-
require File.
|
4
|
-
require
|
1
|
+
require File.dirname(__FILE__) + '/wirb/version'
|
2
|
+
require File.dirname(__FILE__) + '/wirb/colorizer'
|
3
|
+
require File.dirname(__FILE__) + '/wirb/tokenizer'
|
4
|
+
require 'yaml'
|
5
5
|
|
6
6
|
class << Wirb
|
7
|
-
|
7
|
+
def running?() @running end
|
8
8
|
|
9
9
|
@running = false
|
10
|
-
def running?() @running end
|
11
10
|
|
12
|
-
#
|
13
|
-
def
|
14
|
-
if
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
# Start colorizing results, will hook into irb if IRB is defined
|
12
|
+
def start
|
13
|
+
require File.dirname(__FILE__) + '/wirb/irb' if defined?(IRB) && !IRB::Irb.instance_methods.include?(:prompt_non_fancy)
|
14
|
+
@running = true
|
15
|
+
rescue LoadError
|
16
|
+
warn "Couldn't activate Wirb"
|
17
|
+
end
|
18
|
+
alias activate start
|
19
|
+
alias enable start
|
20
|
+
|
21
|
+
# Stop colorizing
|
22
|
+
def stop
|
23
|
+
@running = false
|
24
|
+
end
|
25
|
+
alias deactivate stop
|
26
|
+
alias disable stop
|
27
|
+
|
28
|
+
# extend getter & setter for colorizer & schema
|
29
|
+
def colorizer
|
30
|
+
@colorizer ||= Wirb::Colorizer::Wirb0
|
31
|
+
end
|
32
|
+
|
33
|
+
def colorizer=(col)
|
34
|
+
@colorizer = col
|
35
|
+
end
|
36
|
+
|
37
|
+
# Convenience method, permits simplified syntax like:
|
38
|
+
# Wirb.load_colorizer :HighLine
|
39
|
+
def load_colorizer(colorizer_name)
|
40
|
+
# @colorizer = Wirb::Colorizer.const_get(colorizer_name, false)
|
41
|
+
@colorizer = eval "Wirb::Colorizer::#{colorizer_name}"
|
42
|
+
compatibile_colorizer?(@colorizer)
|
43
|
+
@colorizer
|
44
|
+
end
|
45
|
+
|
46
|
+
def schema
|
47
|
+
@schema || load_schema
|
48
|
+
end
|
49
|
+
|
50
|
+
def schema=(val)
|
51
|
+
@schema = val
|
52
|
+
end
|
53
|
+
|
54
|
+
# Loads a color schema from a yaml file
|
55
|
+
# If first argument is a String: path to yaml file
|
56
|
+
# If first argument is a Symbol: bundled schema
|
57
|
+
def load_schema!(yaml_path = :classic_wirb0)
|
58
|
+
if yaml_path.is_a? Symbol # bundled themes
|
59
|
+
schema_name = yaml_path.to_s
|
60
|
+
schema_yaml = YAML.load_file(File.join( Gem.datadir('wirb'), schema_name + '.yml' ))
|
61
|
+
else
|
62
|
+
schema_name = File.basename(yaml_path).gsub(/\.yml$/, '')
|
63
|
+
schema_yaml = YAML.load_file(yaml_path)
|
64
|
+
end
|
65
|
+
|
66
|
+
if schema_yaml.is_a?(Hash)
|
67
|
+
@schema = Hash[ schema_yaml.map{ |k,v|
|
68
|
+
[k.to_s.to_sym, Array( v )]
|
69
|
+
} ]
|
70
|
+
@schema[:name] = schema_name.to_sym
|
71
|
+
@schema[:colorizer].map!(&:to_sym)
|
72
|
+
else
|
73
|
+
raise LoadError, "Could not load the Wirb schema at: #{yaml_path}"
|
18
74
|
end
|
19
75
|
|
20
|
-
|
76
|
+
@schema
|
21
77
|
end
|
22
78
|
|
79
|
+
# Loads a color schema from a yaml file and sets colorizer to first suggested one in schema
|
80
|
+
def load_schema(yaml_path = :classic_wirb0)
|
81
|
+
load_schema! yaml_path
|
82
|
+
load_colorizer schema[:colorizer].first
|
83
|
+
@schema
|
84
|
+
end
|
85
|
+
|
86
|
+
# Return the escape code for a given color
|
87
|
+
def get_color(*keys)
|
88
|
+
colorizer.color(*keys)
|
89
|
+
end
|
90
|
+
alias color get_color
|
91
|
+
|
23
92
|
# Colorize a string
|
24
|
-
def colorize_string(string,
|
25
|
-
|
93
|
+
def colorize_string(string, *colors)
|
94
|
+
colorizer.run(string, *colors)
|
26
95
|
end
|
27
96
|
|
28
97
|
# Colorize a result string
|
@@ -31,7 +100,7 @@ class << Wirb
|
|
31
100
|
check = ''
|
32
101
|
colorful = tokenize(string).map do |kind, token|
|
33
102
|
check << token
|
34
|
-
colorize_string token, custom_schema[kind]
|
103
|
+
colorize_string token, *Array( custom_schema[kind] )
|
35
104
|
end.join
|
36
105
|
|
37
106
|
# always display the correct inspect string!
|
@@ -40,23 +109,27 @@ class << Wirb
|
|
40
109
|
string
|
41
110
|
end
|
42
111
|
end
|
112
|
+
alias colorize_code colorize_result
|
113
|
+
alias colorize_ruby colorize_result
|
43
114
|
|
44
|
-
|
45
|
-
# Will hook into irb if IRB is defined
|
46
|
-
def start
|
47
|
-
require File.dirname(__FILE__) + '/wirb/irb' if defined?(IRB)
|
48
|
-
@running = true
|
49
|
-
rescue LoadError
|
50
|
-
warn "Couldn't activate Wirb"
|
51
|
-
end
|
52
|
-
alias activate start
|
53
|
-
alias enable start
|
115
|
+
private
|
54
116
|
|
55
|
-
def
|
56
|
-
|
117
|
+
def compatibile_colorizer?(col)
|
118
|
+
short_col = col.to_s.sub(/^.*::(.*?)$/, '\1').to_sym
|
119
|
+
if !col
|
120
|
+
warn "No colorizer selected!"
|
121
|
+
false
|
122
|
+
elsif !Array( @schema[:colorizer] ).include?(short_col)
|
123
|
+
warn "Your current color schema does not support this colorizer:\n" +
|
124
|
+
" #{ short_col }\n" +
|
125
|
+
"The following colorizeres are supported with this schema (use Wirb.load_colorizer :Name):\n " +
|
126
|
+
Array( @schema[:colorizer] ).join("\n ")
|
127
|
+
false
|
128
|
+
else
|
129
|
+
true
|
130
|
+
end
|
57
131
|
end
|
58
|
-
|
59
|
-
alias disable stop
|
132
|
+
|
60
133
|
end
|
61
134
|
|
62
135
|
# J-_-L
|