wirb 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +2 -0
- data/COPYING +21 -0
- data/README.rdoc +52 -0
- data/Rakefile +47 -0
- data/lib/wirb.rb +45 -0
- data/lib/wirb/colors.rb +47 -0
- data/lib/wirb/irb.rb +13 -0
- data/lib/wirb/schema.rb +68 -0
- data/lib/wirb/tokenizer.rb +307 -0
- data/lib/wirb/wp.rb +13 -0
- data/wirb.gemspec +18 -0
- metadata +79 -0
data/CHANGELOG.rdoc
ADDED
data/COPYING
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (C) 2011 Jan Lelis <mail@janlelis.de>
|
2
|
+
Copyright (C) 2006-2009 Paul Duncan <pabs@pablotron.org>
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
5
|
+
copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included
|
13
|
+
in all copies or substantial portions of the of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
16
|
+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
18
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
20
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
21
|
+
DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
== Wavy Interactive Ruby
|
2
|
+
*Wirb* colorizes your inspected Ruby objects. It is based on Wirble[http://pablotron.org/software/wirble/], but only provides result highlighting.
|
3
|
+
|
4
|
+
It fixes some displaying bugs and extends the original tokenizer.
|
5
|
+
|
6
|
+
== Install
|
7
|
+
Install the gem with:
|
8
|
+
|
9
|
+
gem install wirb
|
10
|
+
|
11
|
+
== Usage
|
12
|
+
Add to your <tt>~/.irbrc</tt>
|
13
|
+
|
14
|
+
require 'rubygems' unless defined? Gem
|
15
|
+
require 'wirb'
|
16
|
+
Wirb.start
|
17
|
+
|
18
|
+
== Improvements and fixed Wirble bugs
|
19
|
+
* Basic support for regexes (Wirble displayed them as keywords)
|
20
|
+
* Support for generic objects, especially sets and enumerators
|
21
|
+
* Fixes some symbol bugs (e.g. :+, :*, ...)
|
22
|
+
* Does not change the inspect value (e.g. ranges with 4 instead of 3 dots)
|
23
|
+
* Comes with tests
|
24
|
+
* Can be used without irb
|
25
|
+
|
26
|
+
== Customize
|
27
|
+
The color schema can be changed with:
|
28
|
+
|
29
|
+
Wirb.schema = { :comma => :purple, ... }
|
30
|
+
|
31
|
+
Wirb color schemas are (almost) compatible with those from the original Wirble, but there are many extensions. Take a look at wirb/schema.rb or </tt>Wirb.schema</tt> for a list of available token descriptions. See wirb/colors.rb or <tt>Wirb::COLORS</tt> for the available colors.
|
32
|
+
|
33
|
+
Color schemas wanted! You've got a good looking alternative color schema? Please post it on the wiki[https://github.com/janlelis/wirb/wiki/schemas], it may be bundled with a next version ;)
|
34
|
+
|
35
|
+
== wp
|
36
|
+
You can colorize any object with <tt>wp</tt> (wavy_print):
|
37
|
+
require 'wirb/wp'
|
38
|
+
wp some_object
|
39
|
+
wp some_object, :light_red
|
40
|
+
|
41
|
+
== Also see
|
42
|
+
* hirb[https://github.com/cldwalker/hirb]
|
43
|
+
* irbtools[https://github.com/janlelis/irbtools]
|
44
|
+
* ripl-color_result[https://github.com/janlelis/ripl-color_result]
|
45
|
+
|
46
|
+
== Credits
|
47
|
+
Copyright (c) 2011 Jan Lelis <http://rbjl.net>, see COPYING for details.
|
48
|
+
|
49
|
+
Contains code from (and thanks to)
|
50
|
+
* Copyright (C) 2006-2009 Paul Duncan <pabs@pablotron.org>
|
51
|
+
|
52
|
+
J-_-L
|
data/Rakefile
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/rdoctask'
|
3
|
+
require 'fileutils'
|
4
|
+
require "rspec/core/rake_task"
|
5
|
+
task :default => :spec
|
6
|
+
|
7
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
8
|
+
t.rspec_opts = [
|
9
|
+
# '--color',
|
10
|
+
'-r ' + File.expand_path( File.join( 'spec', 'spec_helper') ),
|
11
|
+
]
|
12
|
+
end
|
13
|
+
|
14
|
+
def gemspec
|
15
|
+
@gemspec ||= eval(File.read('wirb.gemspec'), binding, 'wirb.gemspec')
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "Build the gem"
|
19
|
+
task :gem => :gemspec do
|
20
|
+
sh "gem build wirb.gemspec"
|
21
|
+
FileUtils.mkdir_p 'pkg'
|
22
|
+
FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "Install the gem locally"
|
26
|
+
task :install => :gem do
|
27
|
+
sh %{gem install pkg/#{gemspec.name}-#{gemspec.version} --no-rdoc --no-ri}
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "Generate the gemspec"
|
31
|
+
task :generate do
|
32
|
+
puts gemspec.to_ruby
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "Validate the gemspec"
|
36
|
+
task :gemspec do
|
37
|
+
gemspec.validate
|
38
|
+
end
|
39
|
+
|
40
|
+
Rake::RDocTask.new do |rdoc|
|
41
|
+
require File.expand_path( File.join( 'lib', 'wirb') )
|
42
|
+
|
43
|
+
rdoc.rdoc_dir = 'doc'
|
44
|
+
rdoc.title = "Wirb #{Wirb::VERSION}"
|
45
|
+
rdoc.rdoc_files.include('README*')
|
46
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
47
|
+
end
|
data/lib/wirb.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
module Wirb
|
2
|
+
VERSION = '0.2.0'
|
3
|
+
end
|
4
|
+
|
5
|
+
require File.dirname(__FILE__) + '/wirb/colors'
|
6
|
+
require File.dirname(__FILE__) + '/wirb/schema'
|
7
|
+
require File.dirname(__FILE__) + '/wirb/tokenizer'
|
8
|
+
|
9
|
+
class << Wirb
|
10
|
+
attr_accessor :schema
|
11
|
+
|
12
|
+
# Return the escape code for a given color
|
13
|
+
def get_color(key)
|
14
|
+
if key.is_a? String
|
15
|
+
color = key
|
16
|
+
elsif Wirb::COLORS.key?(key)
|
17
|
+
color = Wirb::COLORS[key]
|
18
|
+
end
|
19
|
+
|
20
|
+
color ? "\033[#{ color }m" : ''
|
21
|
+
end
|
22
|
+
|
23
|
+
# Colorize a string
|
24
|
+
def colorize_string(string, color)
|
25
|
+
get_color(color) + string.to_s + get_color(:nothing)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Colorize a result string
|
29
|
+
def colorize_result(str, custom_schema = schema)
|
30
|
+
tokenize(str).map{ |kind, token|
|
31
|
+
colorize_string token, custom_schema[kind]
|
32
|
+
}.join
|
33
|
+
end
|
34
|
+
|
35
|
+
# Colorize results in irb/ripl (or whatever might be supported in future)
|
36
|
+
def start
|
37
|
+
require File.dirname(__FILE__) + '/wirb/irb'
|
38
|
+
rescue LoadError
|
39
|
+
warn "Couldn't activate Wirb for #{which}"
|
40
|
+
end
|
41
|
+
alias activate start
|
42
|
+
alias enable start
|
43
|
+
end
|
44
|
+
|
45
|
+
# J-_-L
|
data/lib/wirb/colors.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
module Wirb
|
2
|
+
COLORS = {
|
3
|
+
:nothing => '0;0',
|
4
|
+
|
5
|
+
# light
|
6
|
+
:black => '0;30',
|
7
|
+
:red => '0;31',
|
8
|
+
:green => '0;32',
|
9
|
+
:brown => '0;33',
|
10
|
+
:blue => '0;34',
|
11
|
+
:purple => '0;35',
|
12
|
+
:cyan => '0;36',
|
13
|
+
:light_gray => '0;37',
|
14
|
+
|
15
|
+
# bold
|
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
|
+
|
25
|
+
# underline
|
26
|
+
:black_underline => '4;30',
|
27
|
+
:red_underline => '4;31',
|
28
|
+
:green_underline => '4;32',
|
29
|
+
:brown_underline => '4;33',
|
30
|
+
:blue_underline => '4;34',
|
31
|
+
:purple_underline => '4;35',
|
32
|
+
:cyan_underline => '4;36',
|
33
|
+
:white_underline => '4;37',
|
34
|
+
|
35
|
+
# background
|
36
|
+
:black_background => '7;30',
|
37
|
+
:red_background => '7;31',
|
38
|
+
:green_background => '7;32',
|
39
|
+
:brown_background => '7;33',
|
40
|
+
:blue_background => '7;34',
|
41
|
+
:purple_background => '7;35',
|
42
|
+
:cyan_background => '7;36',
|
43
|
+
:white_background => '7;37',
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
# J-_-L
|
data/lib/wirb/irb.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../wirb' unless defined? Wirb
|
2
|
+
|
3
|
+
class IRB::Irb
|
4
|
+
alias :output_value_without_wirb :output_value
|
5
|
+
|
6
|
+
def output_value
|
7
|
+
if @context.inspect?
|
8
|
+
printf @context.return_format, ::Wirb.colorize_result( @context.last_value.inspect )
|
9
|
+
else
|
10
|
+
printf @context.return_format, @context.last_value
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/wirb/schema.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
module Wirb
|
2
|
+
@schema = { # you can also use escape codes directly, e.g. "4;31"
|
3
|
+
|
4
|
+
# container
|
5
|
+
:open_hash => :light_green,
|
6
|
+
:close_hash => :light_green,
|
7
|
+
:open_array => :light_green,
|
8
|
+
:close_array => :light_green,
|
9
|
+
|
10
|
+
:open_set => :green,
|
11
|
+
:close_set => :green,
|
12
|
+
:open_enumerator => :green,
|
13
|
+
:close_enumerator => :green,
|
14
|
+
|
15
|
+
# delimiter colors
|
16
|
+
:comma => :green,
|
17
|
+
:refers => :green,
|
18
|
+
|
19
|
+
# class
|
20
|
+
:class => :light_green,
|
21
|
+
:class_separator => :green,
|
22
|
+
:object_class => :light_green,
|
23
|
+
|
24
|
+
# object
|
25
|
+
:open_object => :green,
|
26
|
+
:object_description_prefix => :green,
|
27
|
+
:object_description => :brown,
|
28
|
+
:object_addr_prefix => :brown_underline,
|
29
|
+
:object_addr => :brown_underline,
|
30
|
+
:object_line_prefix => :brown_underline,
|
31
|
+
:object_line => :brown_underline,
|
32
|
+
:object_line_number => :brown_underline,
|
33
|
+
:close_object => :green,
|
34
|
+
|
35
|
+
# symbol
|
36
|
+
:symbol_prefix => :yellow,
|
37
|
+
:symbol => :yellow,
|
38
|
+
:open_symbol_string => :brown,
|
39
|
+
:symbol_string => :yellow,
|
40
|
+
:close_symbol_string => :brown,
|
41
|
+
|
42
|
+
# string
|
43
|
+
:open_string => :light_gray,
|
44
|
+
:string => :dark_gray,
|
45
|
+
:close_string => :light_gray,
|
46
|
+
|
47
|
+
# regexp
|
48
|
+
:open_regexp => :light_blue,
|
49
|
+
:regexp => :dark_gray,
|
50
|
+
:close_regexp => :light_blue,
|
51
|
+
:regexp_flags => :light_red,
|
52
|
+
|
53
|
+
# number
|
54
|
+
:number => :cyan,
|
55
|
+
:range => :red,
|
56
|
+
:open_rational => :light_cyan,
|
57
|
+
:rational_separator => :light_cyan,
|
58
|
+
:close_rational => :light_cyan,
|
59
|
+
|
60
|
+
# misc
|
61
|
+
:keyword => nil, # rename to default?
|
62
|
+
:nil => :light_red,
|
63
|
+
:false => :red,
|
64
|
+
:true => :green,
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
# J-_-L
|
@@ -0,0 +1,307 @@
|
|
1
|
+
class << Wirb
|
2
|
+
# This is an extended version of the original wirble tokenizer.
|
3
|
+
# Almost everyone would say that 300 lines long case statements need refactoring, but
|
4
|
+
# ...sometimes it just doesn't matter ;)
|
5
|
+
def tokenize(str)
|
6
|
+
raise ArgumentError, 'Tokenizer needs an inspect-string' unless str.is_a? String
|
7
|
+
return enum_for(:tokenize, str) unless block_given?
|
8
|
+
|
9
|
+
chars = str.split(//)
|
10
|
+
|
11
|
+
@state, @token, i = [], '', 0
|
12
|
+
|
13
|
+
# helpers
|
14
|
+
pass_custom_state = lambda{ |kind, *options|
|
15
|
+
yield kind, @token unless @token.empty?
|
16
|
+
@state.pop if options.include?(:remove)
|
17
|
+
@token = '' unless options.include?(:keep_token)
|
18
|
+
@repeat = true if options.include?(:repeat)
|
19
|
+
}
|
20
|
+
|
21
|
+
pass_state = lambda{ |*options| pass_custom_state[ @state[-1], *options ] }
|
22
|
+
|
23
|
+
pass = lambda{ |kind, string| yield kind, string }
|
24
|
+
|
25
|
+
set_state = lambda{ |state| @state[-1] = state }
|
26
|
+
|
27
|
+
get_state = lambda{ |state| @state[-1] == state }
|
28
|
+
|
29
|
+
get_previous_state =
|
30
|
+
lambda{ |state| @state[-2] == state }
|
31
|
+
|
32
|
+
push_state = lambda{ |state, *options|
|
33
|
+
@state << state
|
34
|
+
@repeat = true if options.include? :repeat
|
35
|
+
}
|
36
|
+
|
37
|
+
pop_state = lambda{ |*options|
|
38
|
+
@state.pop
|
39
|
+
@repeat = true if options.include? :repeat
|
40
|
+
}
|
41
|
+
|
42
|
+
# action!
|
43
|
+
while i <= chars.size
|
44
|
+
@repeat = false
|
45
|
+
llc, lc, c, nc = lc, c, chars[i], chars[i+1]
|
46
|
+
|
47
|
+
# warn "char = #{c} state = #{@state*':'}"
|
48
|
+
|
49
|
+
case @state[-1]
|
50
|
+
when nil, :hash, :array, :enumerator, :set # "default" state
|
51
|
+
case c
|
52
|
+
when ':' then push_state[:symbol]
|
53
|
+
when '"' then push_state[:string]
|
54
|
+
when '/' then push_state[:regexp]
|
55
|
+
when '#' then push_state[:object]
|
56
|
+
when /[A-Z]/ then push_state[:class, :repeat]
|
57
|
+
when /[a-z]/ then push_state[:keyword, :repeat]
|
58
|
+
when /[0-9-]/ then push_state[:number, :repeat]
|
59
|
+
when '(' then push_state[:rational, :repeat]
|
60
|
+
when '.' then push_state[:range, :repeat]
|
61
|
+
when /\s/ then pass[:whitespace, c]
|
62
|
+
when ',' then pass[:comma, ',']
|
63
|
+
when '>' then pass[:refers, '=>'] if lc == '='
|
64
|
+
|
65
|
+
when '{'
|
66
|
+
if get_state[:set]
|
67
|
+
pass[:open_set, '{']; push_state[nil]
|
68
|
+
else
|
69
|
+
pass[:open_hash, '{']; push_state[:hash]
|
70
|
+
end
|
71
|
+
|
72
|
+
when '['
|
73
|
+
if get_state[:enumerator]
|
74
|
+
pass[:open_enumerator, '[']; push_state[nil]
|
75
|
+
else
|
76
|
+
pass[:open_array, '[']; push_state[:array]
|
77
|
+
end
|
78
|
+
|
79
|
+
when ']'
|
80
|
+
if get_state[:array]
|
81
|
+
pass[:close_array, ']']; pop_state[]
|
82
|
+
elsif get_previous_state[:enumerator]
|
83
|
+
pass[:close_enumerator, ']']; pop_state[]
|
84
|
+
set_state[:object_description]
|
85
|
+
end
|
86
|
+
|
87
|
+
when '}'
|
88
|
+
if get_state[:hash]
|
89
|
+
pass[:close_hash, '}']; pop_state[]
|
90
|
+
elsif get_previous_state[:set]
|
91
|
+
pass[:close_set, '}']; pop_state[]
|
92
|
+
set_state[:object_description]
|
93
|
+
end
|
94
|
+
|
95
|
+
# else
|
96
|
+
# warn "ignoring char #{c.inspect}" if @debug
|
97
|
+
end
|
98
|
+
|
99
|
+
when :class
|
100
|
+
case c
|
101
|
+
when /[a-z0-9_]/i
|
102
|
+
@token << c
|
103
|
+
else
|
104
|
+
if c ==':' && nc == ':'
|
105
|
+
pass_state[]
|
106
|
+
pass[:class_separator, '::']
|
107
|
+
elsif !(c == ':' && lc == ':')
|
108
|
+
pass_state[:remove, :repeat]
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
when :symbol
|
113
|
+
case c
|
114
|
+
when /"/
|
115
|
+
pass[:symbol_prefix, ':']
|
116
|
+
set_state[:symbol_string]
|
117
|
+
@token = ''
|
118
|
+
when /[^"., }\])=]/
|
119
|
+
@token << c
|
120
|
+
else
|
121
|
+
if ( c == '=' && !(nc == '>' && lc != '<' ) ) ||
|
122
|
+
( c == ']' && lc == '[' )
|
123
|
+
@token << c
|
124
|
+
else
|
125
|
+
pass[:symbol_prefix, ':']
|
126
|
+
pass_state[:remove, :repeat]
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
when :symbol_string
|
131
|
+
if c == '"' && lc != '\\'
|
132
|
+
pass[:open_symbol_string, '"']
|
133
|
+
pass_state[:remove]
|
134
|
+
pop_state[]
|
135
|
+
pass[:close_symbol_string, '"']
|
136
|
+
else
|
137
|
+
@token << c
|
138
|
+
end
|
139
|
+
|
140
|
+
when :string
|
141
|
+
if c == '"' && lc != '\\'
|
142
|
+
pass[:open_string, '"']
|
143
|
+
pass_state[:remove]
|
144
|
+
pass[:close_string, '"']
|
145
|
+
else
|
146
|
+
@token << c
|
147
|
+
end
|
148
|
+
|
149
|
+
when :regexp
|
150
|
+
if c == '/' && lc != '\\'
|
151
|
+
pass[:open_regexp, '/']
|
152
|
+
pass_state[:remove]
|
153
|
+
pass[:close_regexp, '/']
|
154
|
+
push_state[:regexp_flags]
|
155
|
+
else
|
156
|
+
@token << c
|
157
|
+
end
|
158
|
+
|
159
|
+
when :regexp_flags
|
160
|
+
if c =~ /[a-z]/i #*%w[m i x o n e u s]
|
161
|
+
@token << c
|
162
|
+
else
|
163
|
+
pass_state[:remove, :repeat]
|
164
|
+
end
|
165
|
+
|
166
|
+
when :keyword
|
167
|
+
if c =~ /[a-z0-9_]/i
|
168
|
+
@token << c
|
169
|
+
pass_custom_state[@token.to_sym, :remove] if %w[nil false true].include?(@token)
|
170
|
+
else
|
171
|
+
pass_state[:remove, :repeat]
|
172
|
+
end
|
173
|
+
|
174
|
+
when :number
|
175
|
+
if c =~ /[0-9e+.-]/ && !(c == '.' && nc == '.')
|
176
|
+
@token << c
|
177
|
+
else
|
178
|
+
pass_state[:remove, :repeat]
|
179
|
+
end
|
180
|
+
|
181
|
+
when :range
|
182
|
+
if c == '.'
|
183
|
+
@token << c
|
184
|
+
else
|
185
|
+
pass_state[:remove, :repeat]
|
186
|
+
end
|
187
|
+
|
188
|
+
when :rational
|
189
|
+
case c
|
190
|
+
when '('
|
191
|
+
pass[:open_rational, '(']
|
192
|
+
when /[0-9e-]/
|
193
|
+
push_state[:number, :repeat]
|
194
|
+
when '/', ','
|
195
|
+
pass[:rational_separator, c]
|
196
|
+
when ' '
|
197
|
+
pass[:whitespace, c]
|
198
|
+
when ')'
|
199
|
+
pass[:close_rational, ')']
|
200
|
+
pop_state[]
|
201
|
+
end
|
202
|
+
|
203
|
+
when :object
|
204
|
+
case c
|
205
|
+
when '<'
|
206
|
+
pass[:open_object, '#<']
|
207
|
+
push_state[:object_class]
|
208
|
+
open_brackets = 0
|
209
|
+
when '>'
|
210
|
+
pass[:close_object, '>']
|
211
|
+
pop_state[]; @token = ''
|
212
|
+
end
|
213
|
+
|
214
|
+
when :object_class
|
215
|
+
case c
|
216
|
+
when /[a-z0-9_]/i
|
217
|
+
@token << c
|
218
|
+
when '>'
|
219
|
+
pass_state[:remove, :repeat]
|
220
|
+
else
|
221
|
+
if c == ':' && nc == ':'
|
222
|
+
pass_state[]
|
223
|
+
pass[:class_separator, '::']
|
224
|
+
elsif !(c == ':' && lc == ':')
|
225
|
+
pass_state[:keep_token]
|
226
|
+
pass[:object_description_prefix, c]
|
227
|
+
if %w[set].include? @token = @token.downcase
|
228
|
+
set_state[@token.to_sym]
|
229
|
+
else
|
230
|
+
set_state[:object_description]
|
231
|
+
end
|
232
|
+
@token = ''
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
when :object_description
|
237
|
+
case c
|
238
|
+
when '>', nil
|
239
|
+
if open_brackets == 0
|
240
|
+
pass_state[:remove, :repeat]
|
241
|
+
else
|
242
|
+
open_brackets -= 1
|
243
|
+
@token << c
|
244
|
+
end
|
245
|
+
when '<'
|
246
|
+
open_brackets += 1
|
247
|
+
@token << c
|
248
|
+
when '['
|
249
|
+
pass_state[:repeat]
|
250
|
+
set_state[:enumerator]
|
251
|
+
when '"'
|
252
|
+
pass_state[]
|
253
|
+
push_state[:string]
|
254
|
+
when /[0-9]/
|
255
|
+
if c == '0' && nc == 'x'
|
256
|
+
pass_state[:repeat]
|
257
|
+
push_state[:object_addr]
|
258
|
+
else
|
259
|
+
# push_state[:number, :repeat]
|
260
|
+
@token << c
|
261
|
+
end
|
262
|
+
else
|
263
|
+
@token << c
|
264
|
+
end
|
265
|
+
|
266
|
+
when :object_addr
|
267
|
+
if c =~ /[x0-9a-f]/
|
268
|
+
@token << c
|
269
|
+
else
|
270
|
+
if c == '@'
|
271
|
+
pass_state[:remove]
|
272
|
+
push_state[:object_line]
|
273
|
+
pass[:object_line_prefix, '@']
|
274
|
+
else
|
275
|
+
pass_state[:remove, :repeat]
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
when :object_line
|
280
|
+
if c == ':' && nc =~ /[0-9]/
|
281
|
+
@token << ':'
|
282
|
+
pass_state[:remove]
|
283
|
+
push_state[:object_line_number]
|
284
|
+
else
|
285
|
+
@token << c
|
286
|
+
end
|
287
|
+
|
288
|
+
when :object_line_number
|
289
|
+
if c =~ /[0-9]/
|
290
|
+
@token << c
|
291
|
+
else
|
292
|
+
pass_state[:remove, :repeat]
|
293
|
+
end
|
294
|
+
|
295
|
+
# else
|
296
|
+
# raise "unknown state #{@state[-1]} #{@state.inspect}"
|
297
|
+
end
|
298
|
+
|
299
|
+
# TODO infinite recursion detection and catch errors?
|
300
|
+
|
301
|
+
# next round :)
|
302
|
+
i += 1 unless @repeat
|
303
|
+
end
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
# J-_-L
|
data/lib/wirb/wp.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../wirb' unless defined? Wirb
|
2
|
+
|
3
|
+
module Kernel
|
4
|
+
private
|
5
|
+
|
6
|
+
def wp(object, color = nil)
|
7
|
+
if color
|
8
|
+
puts Wirb.colorize_string object.inspect, color
|
9
|
+
else
|
10
|
+
puts Wirb.colorize_result object.inspect
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/wirb.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'rubygems' unless defined? Gem
|
3
|
+
require File.dirname(__FILE__) + "/lib/wirb"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "wirb"
|
7
|
+
s.version = Wirb::VERSION
|
8
|
+
s.authors = ["Jan Lelis"]
|
9
|
+
s.email = "mail@janlelis.de"
|
10
|
+
s.homepage = "http://github.com/janlelis/wirb"
|
11
|
+
s.summary = "Colorizes your irb results."
|
12
|
+
s.description = "Colorizes your irb results. It's based on Wirble but only provides result highlighting. Just call Wirb.start and enjoy the colors ;)."
|
13
|
+
s.required_rubygems_version = '>= 1.3.6'
|
14
|
+
s.required_ruby_version = '>= 1.8.7'
|
15
|
+
s.files = Dir.glob(%w[{lib,test}/**/*.rb bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c} **/deps.rip]) + %w{Rakefile wirb.gemspec}
|
16
|
+
s.extra_rdoc_files = ["README.rdoc", "COPYING"]
|
17
|
+
s.license = 'MIT'
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wirb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Jan Lelis
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-01-27 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Colorizes your irb results. It's based on Wirble but only provides result highlighting. Just call Wirb.start and enjoy the colors ;).
|
22
|
+
email: mail@janlelis.de
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- README.rdoc
|
29
|
+
- COPYING
|
30
|
+
files:
|
31
|
+
- lib/wirb.rb
|
32
|
+
- lib/wirb/schema.rb
|
33
|
+
- lib/wirb/tokenizer.rb
|
34
|
+
- lib/wirb/wp.rb
|
35
|
+
- lib/wirb/colors.rb
|
36
|
+
- lib/wirb/irb.rb
|
37
|
+
- README.rdoc
|
38
|
+
- CHANGELOG.rdoc
|
39
|
+
- Rakefile
|
40
|
+
- wirb.gemspec
|
41
|
+
- COPYING
|
42
|
+
has_rdoc: true
|
43
|
+
homepage: http://github.com/janlelis/wirb
|
44
|
+
licenses:
|
45
|
+
- MIT
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
segments:
|
57
|
+
- 1
|
58
|
+
- 8
|
59
|
+
- 7
|
60
|
+
version: 1.8.7
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
segments:
|
67
|
+
- 1
|
68
|
+
- 3
|
69
|
+
- 6
|
70
|
+
version: 1.3.6
|
71
|
+
requirements: []
|
72
|
+
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 1.3.7
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: Colorizes your irb results.
|
78
|
+
test_files: []
|
79
|
+
|