pry 0.8.0pre5-i386-mswin32 → 0.8.0pre7-i386-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/bin/pry +7 -0
- data/lib/pry/command_base.rb +5 -7
- data/lib/pry/command_helpers.rb +291 -0
- data/lib/pry/commands.rb +86 -248
- data/lib/pry/hooks.rb +1 -1
- data/lib/pry/pry_class.rb +7 -1
- data/lib/pry/pry_instance.rb +11 -2
- data/lib/pry/version.rb +1 -1
- metadata +12 -3
data/Rakefile
CHANGED
data/bin/pry
CHANGED
@@ -68,6 +68,13 @@ end.parse!
|
|
68
68
|
# invoked via cli
|
69
69
|
Pry.cli = true
|
70
70
|
|
71
|
+
class Pry::Commands
|
72
|
+
command "reset", "Reset the REPL to a clean state." do
|
73
|
+
output.puts "Pry reset."
|
74
|
+
exec("pry")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
71
78
|
# load ~/.pryrc, if not suppressed with -f option
|
72
79
|
Pry.should_load_rc = false if !options[:loadrc]
|
73
80
|
|
data/lib/pry/command_base.rb
CHANGED
@@ -131,19 +131,17 @@ class Pry
|
|
131
131
|
|
132
132
|
command "help", "This menu." do |cmd|
|
133
133
|
command_info = opts[:commands]
|
134
|
-
param = cmd
|
135
134
|
|
136
|
-
if !
|
137
|
-
output.puts "Command list
|
138
|
-
output.puts "--"
|
135
|
+
if !cmd
|
136
|
+
output.puts "Command list:\n--"
|
139
137
|
command_info.each do |k, data|
|
140
138
|
output.puts "#{k}".ljust(18) + data[:description] if !data[:description].empty?
|
141
139
|
end
|
142
140
|
else
|
143
|
-
if command_info[
|
144
|
-
output.puts command_info[
|
141
|
+
if command_info[cmd]
|
142
|
+
output.puts command_info[cmd][:description]
|
145
143
|
else
|
146
|
-
output.puts "No info for command: #{
|
144
|
+
output.puts "No info for command: #{cmd}"
|
147
145
|
end
|
148
146
|
end
|
149
147
|
end
|
@@ -0,0 +1,291 @@
|
|
1
|
+
class Pry
|
2
|
+
class Commands < CommandBase
|
3
|
+
module CommandHelpers
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def try_to_load_pry_doc
|
8
|
+
|
9
|
+
# YARD crashes on rbx, so do not require it
|
10
|
+
if !Object.const_defined?(:RUBY_ENGINE) || RUBY_ENGINE !~ /rbx/
|
11
|
+
require "pry-doc"
|
12
|
+
end
|
13
|
+
rescue LoadError
|
14
|
+
end
|
15
|
+
|
16
|
+
def meth_name_from_binding(b)
|
17
|
+
meth_name = b.eval('__method__')
|
18
|
+
if [:__script__, nil, :__binding__, :__binding_impl__].include?(meth_name)
|
19
|
+
nil
|
20
|
+
else
|
21
|
+
meth_name
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def set_file_and_dir_locals(file_name)
|
26
|
+
return if !target
|
27
|
+
$_file_temp = File.expand_path(file_name)
|
28
|
+
$_dir_temp = File.dirname($_file_temp)
|
29
|
+
target.eval("_file_ = $_file_temp")
|
30
|
+
target.eval("_dir_ = $_file_temp")
|
31
|
+
end
|
32
|
+
|
33
|
+
# a simple pager for systems without `less`. A la windows.
|
34
|
+
def simple_pager(text)
|
35
|
+
page_size = 22
|
36
|
+
text_array = text.lines.to_a
|
37
|
+
text_array.each_slice(page_size) do |chunk|
|
38
|
+
output.puts chunk.join
|
39
|
+
break if chunk.size < page_size
|
40
|
+
if text_array.size > page_size
|
41
|
+
output.puts "\n<page break> --- Press enter to continue ( q<enter> to break ) --- <page break>"
|
42
|
+
break if $stdin.gets.chomp == "q"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Try to use `less` for paging, if it fails then use simple_pager
|
48
|
+
def stagger_output(text)
|
49
|
+
lesspipe { |less| less.puts text }
|
50
|
+
rescue Exception
|
51
|
+
simple_pager(text)
|
52
|
+
end
|
53
|
+
|
54
|
+
def add_line_numbers(lines, start_line)
|
55
|
+
line_array = lines.each_line.to_a
|
56
|
+
line_array.each_with_index.map do |line, idx|
|
57
|
+
adjusted_index = idx + start_line
|
58
|
+
if Pry.color
|
59
|
+
cindex = CodeRay.scan("#{adjusted_index}", :ruby).term
|
60
|
+
"#{cindex}: #{line}"
|
61
|
+
else
|
62
|
+
"#{idx}: #{line}"
|
63
|
+
end
|
64
|
+
end.join
|
65
|
+
end
|
66
|
+
|
67
|
+
# only add line numbers if start_line is not false
|
68
|
+
# if start_line is not false then add line numbers starting with start_line
|
69
|
+
def render_output(should_flood, start_line, doc)
|
70
|
+
if start_line
|
71
|
+
doc = add_line_numbers(doc, start_line)
|
72
|
+
end
|
73
|
+
|
74
|
+
if should_flood
|
75
|
+
output.puts doc
|
76
|
+
else
|
77
|
+
stagger_output(doc)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def check_for_dynamically_defined_method(meth)
|
82
|
+
file, _ = meth.source_location
|
83
|
+
if file =~ /(\(.*\))|<.*>/
|
84
|
+
raise "Cannot retrieve source for dynamically defined method."
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def remove_first_word(text)
|
89
|
+
text.split.drop(1).join(' ')
|
90
|
+
end
|
91
|
+
|
92
|
+
def get_method_object(meth_name, target, options)
|
93
|
+
if !meth_name
|
94
|
+
return nil
|
95
|
+
end
|
96
|
+
|
97
|
+
if options[:M]
|
98
|
+
target.eval("instance_method(:#{meth_name})")
|
99
|
+
elsif options[:m]
|
100
|
+
target.eval("method(:#{meth_name})")
|
101
|
+
else
|
102
|
+
begin
|
103
|
+
target.eval("instance_method(:#{meth_name})")
|
104
|
+
rescue
|
105
|
+
begin
|
106
|
+
target.eval("method(:#{meth_name})")
|
107
|
+
rescue
|
108
|
+
return nil
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def make_header(meth, code_type, content)
|
115
|
+
file, line = meth.source_location
|
116
|
+
num_lines = "Number of lines: #{content.each_line.count}"
|
117
|
+
case code_type
|
118
|
+
when :ruby
|
119
|
+
"\nFrom #{file} @ line #{line}:\n#{num_lines}\n\n"
|
120
|
+
else
|
121
|
+
"\nFrom Ruby Core (C Method):\n#{num_lines}\n\n"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def is_a_c_method?(meth)
|
126
|
+
meth.source_location.nil?
|
127
|
+
end
|
128
|
+
|
129
|
+
def should_use_pry_doc?(meth)
|
130
|
+
Pry.has_pry_doc && is_a_c_method?(meth)
|
131
|
+
end
|
132
|
+
|
133
|
+
def code_type_for(meth)
|
134
|
+
# only C methods
|
135
|
+
if should_use_pry_doc?(meth)
|
136
|
+
info = Pry::MethodInfo.info_for(meth)
|
137
|
+
if info && info.source
|
138
|
+
code_type = :c
|
139
|
+
else
|
140
|
+
output.puts "Cannot find C method: #{meth.name}"
|
141
|
+
code_type = nil
|
142
|
+
end
|
143
|
+
else
|
144
|
+
if is_a_c_method?(meth)
|
145
|
+
output.puts "Cannot locate this method: #{meth.name}. Try `gem install pry-doc` to get access to Ruby Core documentation."
|
146
|
+
code_type = nil
|
147
|
+
else
|
148
|
+
check_for_dynamically_defined_method(meth)
|
149
|
+
code_type = :ruby
|
150
|
+
end
|
151
|
+
end
|
152
|
+
code_type
|
153
|
+
end
|
154
|
+
|
155
|
+
def file_map
|
156
|
+
{
|
157
|
+
[".c", ".h"] => :c,
|
158
|
+
[".cpp", ".hpp", ".cc", ".h", "cxx"] => :cpp,
|
159
|
+
[".rb", "Rakefile"] => :ruby,
|
160
|
+
".py" => :python,
|
161
|
+
".diff" => :diff,
|
162
|
+
".css" => :css,
|
163
|
+
".html" => :html,
|
164
|
+
[".yaml", ".yml"] => :yaml,
|
165
|
+
".xml" => :xml,
|
166
|
+
".php" => :php,
|
167
|
+
".js" => :javascript,
|
168
|
+
".java" => :java,
|
169
|
+
".rhtml" => :rhtml,
|
170
|
+
".json" => :json
|
171
|
+
}
|
172
|
+
end
|
173
|
+
|
174
|
+
def syntax_highlight_by_file_type_or_specified(contents, file_name, file_type)
|
175
|
+
_, language_detected = file_map.find do |k, v|
|
176
|
+
Array(k).any? do |matcher|
|
177
|
+
matcher == File.extname(file_name) || matcher == File.basename(file_name)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
language_detected = file_type if file_type
|
182
|
+
CodeRay.scan(contents, language_detected).term
|
183
|
+
end
|
184
|
+
|
185
|
+
# convert negative line numbers to positive by wrapping around
|
186
|
+
# last line (as per array indexing with negative numbers)
|
187
|
+
def normalized_line_number(line_number, total_lines)
|
188
|
+
line_number < 0 ? line_number + total_lines : line_number
|
189
|
+
end
|
190
|
+
|
191
|
+
# returns the file content between the lines and the normalized
|
192
|
+
# start and end line numbers.
|
193
|
+
def read_between_the_lines(file_name, start_line, end_line)
|
194
|
+
content = File.read(File.expand_path(file_name))
|
195
|
+
lines_array = content.each_line.to_a
|
196
|
+
|
197
|
+
[lines_array[start_line..end_line].join, normalized_line_number(start_line, lines_array.size),
|
198
|
+
normalized_line_number(end_line, lines_array.size)]
|
199
|
+
end
|
200
|
+
|
201
|
+
# documentation related helpers
|
202
|
+
def strip_color_codes(str)
|
203
|
+
str.gsub(/\e\[.*?(\d)+m/, '')
|
204
|
+
end
|
205
|
+
|
206
|
+
def process_rdoc(comment, code_type)
|
207
|
+
comment = comment.dup
|
208
|
+
comment.gsub(/<code>(?:\s*\n)?(.*?)\s*<\/code>/m) { Pry.color ? CodeRay.scan($1, code_type).term : $1 }.
|
209
|
+
gsub(/<em>(?:\s*\n)?(.*?)\s*<\/em>/m) { Pry.color ? "\e[32m#{$1}\e[0m": $1 }.
|
210
|
+
gsub(/<i>(?:\s*\n)?(.*?)\s*<\/i>/m) { Pry.color ? "\e[34m#{$1}\e[0m" : $1 }.
|
211
|
+
gsub(/\B\+(\w*?)\+\B/) { Pry.color ? "\e[32m#{$1}\e[0m": $1 }.
|
212
|
+
gsub(/((?:^[ \t]+.+(?:\n+|\Z))+)/) { Pry.color ? CodeRay.scan($1, code_type).term : $1 }.
|
213
|
+
gsub(/`(?:\s*\n)?(.*?)\s*`/) { Pry.color ? CodeRay.scan($1, code_type).term : $1 }
|
214
|
+
end
|
215
|
+
|
216
|
+
def process_yardoc_tag(comment, tag)
|
217
|
+
in_tag_block = nil
|
218
|
+
output = comment.lines.map do |v|
|
219
|
+
if in_tag_block && v !~ /^\S/
|
220
|
+
strip_color_codes(strip_color_codes(v))
|
221
|
+
elsif in_tag_block
|
222
|
+
in_tag_block = false
|
223
|
+
v
|
224
|
+
else
|
225
|
+
in_tag_block = true if v =~ /^@#{tag}/
|
226
|
+
v
|
227
|
+
end
|
228
|
+
end.join
|
229
|
+
end
|
230
|
+
|
231
|
+
def process_yardoc(comment)
|
232
|
+
yard_tags = ["param", "return", "option", "yield", "attr", "attr_reader", "attr_writer",
|
233
|
+
"deprecate", "example"]
|
234
|
+
(yard_tags - ["example"]).inject(comment) { |a, v| process_yardoc_tag(a, v) }.
|
235
|
+
gsub(/^@(#{yard_tags.join("|")})/) { Pry.color ? "\e[33m#{$1}\e[0m": $1 }
|
236
|
+
end
|
237
|
+
|
238
|
+
def process_comment_markup(comment, code_type)
|
239
|
+
process_yardoc process_rdoc(comment, code_type)
|
240
|
+
end
|
241
|
+
|
242
|
+
# strip leading whitespace but preserve indentation
|
243
|
+
def strip_leading_whitespace(text)
|
244
|
+
return text if text.empty?
|
245
|
+
leading_spaces = text.lines.first[/^(\s+)/, 1]
|
246
|
+
text.gsub(/^#{leading_spaces}/, '')
|
247
|
+
end
|
248
|
+
|
249
|
+
def strip_leading_hash_and_whitespace_from_ruby_comments(comment)
|
250
|
+
comment = comment.dup
|
251
|
+
comment.gsub!(/\A\#+?$/, '')
|
252
|
+
comment.gsub!(/^\s*#/, '')
|
253
|
+
strip_leading_whitespace(comment)
|
254
|
+
end
|
255
|
+
|
256
|
+
def strip_comments_from_c_code(code)
|
257
|
+
code.sub /\A\s*\/\*.*?\*\/\s*/m, ''
|
258
|
+
end
|
259
|
+
|
260
|
+
# thanks to epitron for this method
|
261
|
+
def lesspipe(*args)
|
262
|
+
if args.any? and args.last.is_a?(Hash)
|
263
|
+
options = args.pop
|
264
|
+
else
|
265
|
+
options = {}
|
266
|
+
end
|
267
|
+
|
268
|
+
output = args.first if args.any?
|
269
|
+
|
270
|
+
params = []
|
271
|
+
params << "-R" unless options[:color] == false
|
272
|
+
params << "-S" unless options[:wrap] == true
|
273
|
+
params << "-F" unless options[:always] == true
|
274
|
+
if options[:tail] == true
|
275
|
+
params << "+\\>"
|
276
|
+
$stderr.puts "Seeking to end of stream..."
|
277
|
+
end
|
278
|
+
params << "-X"
|
279
|
+
|
280
|
+
IO.popen("less #{params * ' '}", "w") do |less|
|
281
|
+
if output
|
282
|
+
less.puts output
|
283
|
+
else
|
284
|
+
yield less
|
285
|
+
end
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
end
|
290
|
+
end
|
291
|
+
end
|
data/lib/pry/commands.rb
CHANGED
@@ -4,115 +4,15 @@ require "optparse"
|
|
4
4
|
require "method_source"
|
5
5
|
require "#{direc}/command_base"
|
6
6
|
require "#{direc}/pry_instance"
|
7
|
-
|
8
|
-
begin
|
9
|
-
|
10
|
-
# YARD crashes on rbx, so do not require it
|
11
|
-
if !Object.const_defined?(:RUBY_ENGINE) || RUBY_ENGINE !~ /rbx/
|
12
|
-
require "pry-doc"
|
13
|
-
end
|
14
|
-
rescue LoadError
|
15
|
-
end
|
7
|
+
require "#{direc}/command_helpers"
|
16
8
|
|
17
9
|
class Pry
|
18
10
|
|
19
11
|
# Default commands used by Pry.
|
20
12
|
class Commands < CommandBase
|
13
|
+
extend CommandHelpers
|
21
14
|
|
22
|
-
|
23
|
-
meth_name_from_binding = lambda do |b|
|
24
|
-
meth_name = b.eval('__method__')
|
25
|
-
|
26
|
-
# :__script__ for rubinius
|
27
|
-
if [:__script__, nil, :__binding__, :__binding_impl__].include?(meth_name)
|
28
|
-
nil
|
29
|
-
else
|
30
|
-
meth_name
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
set_file_and_dir_locals = lambda do |file_name|
|
35
|
-
return if !target
|
36
|
-
FILE_TEMP = File.expand_path(file_name)
|
37
|
-
DIR_TEMP = File.dirname(FILE_TEMP)
|
38
|
-
target.eval("_file_ = Pry::Commands::FILE_TEMP")
|
39
|
-
target.eval("_dir_ = Pry::Commands::DIR_TEMP")
|
40
|
-
remove_const(:FILE_TEMP)
|
41
|
-
remove_const(:DIR_TEMP)
|
42
|
-
end
|
43
|
-
|
44
|
-
check_for_dynamically_defined_method = lambda do |meth|
|
45
|
-
file, _ = meth.source_location
|
46
|
-
if file =~ /(\(.*\))|<.*>/
|
47
|
-
raise "Cannot retrieve source for dynamically defined method."
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
remove_first_word = lambda do |text|
|
52
|
-
text.split.drop(1).join(' ')
|
53
|
-
end
|
54
|
-
|
55
|
-
get_method_object = lambda do |meth_name, target, options|
|
56
|
-
if !meth_name
|
57
|
-
return nil
|
58
|
-
end
|
59
|
-
|
60
|
-
if options[:M]
|
61
|
-
target.eval("instance_method(:#{meth_name})")
|
62
|
-
elsif options[:m]
|
63
|
-
target.eval("method(:#{meth_name})")
|
64
|
-
else
|
65
|
-
begin
|
66
|
-
target.eval("instance_method(:#{meth_name})")
|
67
|
-
rescue
|
68
|
-
begin
|
69
|
-
target.eval("method(:#{meth_name})")
|
70
|
-
rescue
|
71
|
-
return nil
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
make_header = lambda do |meth, code_type|
|
78
|
-
file, line = meth.source_location
|
79
|
-
header = case code_type
|
80
|
-
when :ruby
|
81
|
-
"--\nFrom #{file} @ line #{line}:\n--"
|
82
|
-
else
|
83
|
-
"--\nFrom Ruby Core (C Method):\n--"
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
is_a_c_method = lambda do |meth|
|
88
|
-
meth.source_location.nil?
|
89
|
-
end
|
90
|
-
|
91
|
-
should_use_pry_doc = lambda do |meth|
|
92
|
-
Pry.has_pry_doc && is_a_c_method.call(meth)
|
93
|
-
end
|
94
|
-
|
95
|
-
code_type_for = lambda do |meth|
|
96
|
-
# only C methods
|
97
|
-
if should_use_pry_doc.call(meth)
|
98
|
-
info = Pry::MethodInfo.info_for(meth)
|
99
|
-
if info && info.source
|
100
|
-
code_type = :c
|
101
|
-
else
|
102
|
-
output.puts "Cannot find C method: #{meth.name}"
|
103
|
-
code_type = nil
|
104
|
-
end
|
105
|
-
else
|
106
|
-
if is_a_c_method.call(meth)
|
107
|
-
output.puts "Cannot locate this method: #{meth.name}. Try `gem install pry-doc` to get access to Ruby Core documentation."
|
108
|
-
code_type = nil
|
109
|
-
else
|
110
|
-
check_for_dynamically_defined_method.call(meth)
|
111
|
-
code_type = :ruby
|
112
|
-
end
|
113
|
-
end
|
114
|
-
code_type
|
115
|
-
end
|
15
|
+
try_to_load_pry_doc
|
116
16
|
|
117
17
|
command "!", "Clear the input buffer. Useful if the parsing process goes wrong and you get stuck in the read loop." do
|
118
18
|
output.puts "Input buffer cleared!"
|
@@ -151,7 +51,7 @@ class Pry
|
|
151
51
|
end
|
152
52
|
end
|
153
53
|
|
154
|
-
command "
|
54
|
+
command "shell-mode", "Toggle shell mode. Bring in pwd prompt and file completion." do
|
155
55
|
case Pry.active_instance.prompt
|
156
56
|
when Pry::FILE_PROMPT
|
157
57
|
Pry.active_instance.prompt = Pry::DEFAULT_PROMPT
|
@@ -164,6 +64,8 @@ class Pry
|
|
164
64
|
end
|
165
65
|
end
|
166
66
|
|
67
|
+
alias_command "file-mode", "shell-mode", ""
|
68
|
+
|
167
69
|
command "nesting", "Show nesting information." do
|
168
70
|
nesting = opts[:nesting]
|
169
71
|
|
@@ -188,7 +90,7 @@ class Pry
|
|
188
90
|
output.puts "Pry version: #{Pry::VERSION}"
|
189
91
|
output.puts "Ruby version: #{RUBY_VERSION}"
|
190
92
|
|
191
|
-
mn = meth_name_from_binding
|
93
|
+
mn = meth_name_from_binding(target)
|
192
94
|
output.puts "Current method: #{mn ? mn : "N/A"}"
|
193
95
|
output.puts "Pry instance: #{Pry.active_instance}"
|
194
96
|
output.puts "Last result: #{Pry.view(Pry.last_result)}"
|
@@ -204,8 +106,8 @@ class Pry
|
|
204
106
|
else
|
205
107
|
i_num = 5
|
206
108
|
end
|
207
|
-
|
208
|
-
meth_name = meth_name_from_binding
|
109
|
+
|
110
|
+
meth_name = meth_name_from_binding(target)
|
209
111
|
meth_name = "N/A" if !meth_name
|
210
112
|
|
211
113
|
if file =~ /(\(.*\))|<.*>/ || file == ""
|
@@ -213,9 +115,8 @@ class Pry
|
|
213
115
|
next
|
214
116
|
end
|
215
117
|
|
216
|
-
set_file_and_dir_locals
|
217
|
-
puts "
|
218
|
-
output.puts "--\nFrom #{file} @ line #{line_num} in #{klass}##{meth_name}:\n--"
|
118
|
+
set_file_and_dir_locals(file)
|
119
|
+
output.puts "\nFrom #{file} @ line #{line_num} in #{klass}##{meth_name}:\n\n"
|
219
120
|
|
220
121
|
# This method inspired by http://rubygems.org/gems/ir_b
|
221
122
|
File.open(file).each_with_index do |line, index|
|
@@ -245,13 +146,13 @@ class Pry
|
|
245
146
|
end
|
246
147
|
|
247
148
|
command "exit-all", "End all nested Pry sessions. Accepts optional return value. Aliases: !@" do
|
248
|
-
str = remove_first_word
|
149
|
+
str = remove_first_word(opts[:val])
|
249
150
|
throw(:breakout, [0, target.eval(str)])
|
250
151
|
end
|
251
152
|
|
252
153
|
alias_command "!@", "exit-all", ""
|
253
154
|
|
254
|
-
command "ls", "Show the list of vars in the current scope. Type `ls --help` for more info." do |*args|
|
155
|
+
command "ls", "Show the list of vars and methods in the current scope. Type `ls --help` for more info." do |*args|
|
255
156
|
options = {}
|
256
157
|
|
257
158
|
# Set target local to the default -- note that we can set a different target for
|
@@ -416,48 +317,7 @@ Shows local and instance variables by default.
|
|
416
317
|
end
|
417
318
|
end
|
418
319
|
|
419
|
-
|
420
|
-
[".c", ".h"] => :c,
|
421
|
-
[".cpp", ".hpp", ".cc", ".h", "cxx"] => :cpp,
|
422
|
-
".rb" => :ruby,
|
423
|
-
".py" => :python,
|
424
|
-
".diff" => :diff,
|
425
|
-
".css" => :css,
|
426
|
-
".html" => :html,
|
427
|
-
[".yaml", ".yml"] => :yaml,
|
428
|
-
".xml" => :xml,
|
429
|
-
".php" => :php,
|
430
|
-
".js" => :javascript,
|
431
|
-
".java" => :java,
|
432
|
-
".rhtml" => :rhtml,
|
433
|
-
".json" => :json
|
434
|
-
}
|
435
|
-
|
436
|
-
syntax_highlight_by_file_type_or_specified = lambda do |contents, file_name, file_type|
|
437
|
-
_, language_detected = file_map.find { |k, v| Array(k).include?(File.extname(file_name)) }
|
438
|
-
|
439
|
-
language_detected = file_type if file_type
|
440
|
-
CodeRay.scan(contents, language_detected).term
|
441
|
-
end
|
442
|
-
|
443
|
-
read_between_the_lines = lambda do |file_name, start_line, end_line|
|
444
|
-
content = File.read(File.expand_path(file_name))
|
445
|
-
content.each_line.to_a[start_line..end_line].join
|
446
|
-
end
|
447
|
-
|
448
|
-
add_line_numbers = lambda do |lines, start_line|
|
449
|
-
lines.each_line.each_with_index.map do |line, idx|
|
450
|
-
adjusted_index = idx + start_line
|
451
|
-
if Pry.color
|
452
|
-
cindex = CodeRay.scan("#{adjusted_index}", :ruby).term
|
453
|
-
"#{cindex}: #{line}"
|
454
|
-
else
|
455
|
-
"#{idx}: #{line}"
|
456
|
-
end
|
457
|
-
end
|
458
|
-
end
|
459
|
-
|
460
|
-
command "cat-file", "Show output of file FILE. Type `cat --help` for more information." do |*args|
|
320
|
+
command "cat-file", "Show output of file FILE. Type `cat-file --help` for more information." do |*args|
|
461
321
|
options= {}
|
462
322
|
file_name = nil
|
463
323
|
start_line = 0
|
@@ -484,7 +344,11 @@ e.g: cat-file hello.rb
|
|
484
344
|
|
485
345
|
opts.on("-t", "--type TYPE", "The specific file type for syntax higlighting (e.g ruby, python, cpp, java)") do |type|
|
486
346
|
file_type = type.to_sym
|
487
|
-
end
|
347
|
+
end
|
348
|
+
|
349
|
+
opts.on("-f", "--flood", "Do not use a pager to view text longer than one screen.") do
|
350
|
+
options[:f] = true
|
351
|
+
end
|
488
352
|
|
489
353
|
opts.on_tail("-h", "--help", "This message.") do
|
490
354
|
output.puts opts
|
@@ -501,18 +365,14 @@ e.g: cat-file hello.rb
|
|
501
365
|
next
|
502
366
|
end
|
503
367
|
|
504
|
-
contents = read_between_the_lines
|
368
|
+
contents, normalized_start_line, _ = read_between_the_lines(file_name, start_line, end_line)
|
505
369
|
|
506
370
|
if Pry.color
|
507
|
-
contents = syntax_highlight_by_file_type_or_specified
|
371
|
+
contents = syntax_highlight_by_file_type_or_specified(contents, file_name, file_type)
|
508
372
|
end
|
509
373
|
|
510
|
-
|
511
|
-
|
512
|
-
end
|
513
|
-
|
514
|
-
set_file_and_dir_locals.call(file_name)
|
515
|
-
output.puts contents
|
374
|
+
set_file_and_dir_locals(file_name)
|
375
|
+
render_output(options[:f], options[:l] ? normalized_start_line + 1 : false, contents)
|
516
376
|
contents
|
517
377
|
end
|
518
378
|
|
@@ -556,7 +416,7 @@ e.g: eval-file -c self "hello.rb"
|
|
556
416
|
TOPLEVEL_BINDING.eval(File.read(File.expand_path(file_name)))
|
557
417
|
output.puts "--\nEval'd '#{file_name}' at top-level."
|
558
418
|
end
|
559
|
-
set_file_and_dir_locals
|
419
|
+
set_file_and_dir_locals(file_name)
|
560
420
|
|
561
421
|
new_constants = Object.constants - old_constants
|
562
422
|
output.puts "Brought in the following top-level constants: #{new_constants.inspect}" if !new_constants.empty?
|
@@ -589,61 +449,6 @@ e.g: eval-file -c self "hello.rb"
|
|
589
449
|
Pry.start target.eval("#{obj}")
|
590
450
|
end
|
591
451
|
|
592
|
-
strip_color_codes = lambda do |str|
|
593
|
-
str.gsub(/\e\[.*?(\d)+m/, '')
|
594
|
-
end
|
595
|
-
|
596
|
-
process_rdoc = lambda do |comment, code_type|
|
597
|
-
comment = comment.dup
|
598
|
-
comment.gsub(/<code>(?:\s*\n)?(.*?)\s*<\/code>/m) { Pry.color ? CodeRay.scan($1, code_type).term : $1 }.
|
599
|
-
gsub(/<em>(?:\s*\n)?(.*?)\s*<\/em>/m) { Pry.color ? "\e[32m#{$1}\e[0m": $1 }.
|
600
|
-
gsub(/<i>(?:\s*\n)?(.*?)\s*<\/i>/m) { Pry.color ? "\e[34m#{$1}\e[0m" : $1 }.
|
601
|
-
gsub(/\B\+(\w*?)\+\B/) { Pry.color ? "\e[32m#{$1}\e[0m": $1 }.
|
602
|
-
gsub(/((?:^[ \t]+.+(?:\n+|\Z))+)/) { Pry.color ? CodeRay.scan($1, code_type).term : $1 }.
|
603
|
-
gsub(/`(?:\s*\n)?(.*?)\s*`/) { Pry.color ? CodeRay.scan($1, code_type).term : $1 }
|
604
|
-
end
|
605
|
-
|
606
|
-
process_yardoc_tag = lambda do |comment, tag|
|
607
|
-
in_tag_block = nil
|
608
|
-
output = comment.lines.map do |v|
|
609
|
-
if in_tag_block && v !~ /^\S/
|
610
|
-
strip_color_codes.call(strip_color_codes.call(v))
|
611
|
-
elsif in_tag_block
|
612
|
-
in_tag_block = false
|
613
|
-
v
|
614
|
-
else
|
615
|
-
in_tag_block = true if v =~ /^@#{tag}/
|
616
|
-
v
|
617
|
-
end
|
618
|
-
end.join
|
619
|
-
end
|
620
|
-
|
621
|
-
# FIXME - invert it -- should only ALLOW color if @example
|
622
|
-
process_yardoc = lambda do |comment|
|
623
|
-
yard_tags = ["param", "return", "option", "yield", "attr", "attr_reader", "attr_writer",
|
624
|
-
"deprecate", "example"]
|
625
|
-
(yard_tags - ["example"]).inject(comment) { |a, v| process_yardoc_tag.call(a, v) }.
|
626
|
-
gsub(/^@(#{yard_tags.join("|")})/) { Pry.color ? "\e[33m#{$1}\e[0m": $1 }
|
627
|
-
end
|
628
|
-
|
629
|
-
process_comment_markup = lambda do |comment, code_type|
|
630
|
-
process_yardoc.call process_rdoc.call(comment, code_type)
|
631
|
-
end
|
632
|
-
|
633
|
-
# strip leading whitespace but preserve indentation
|
634
|
-
strip_leading_whitespace = lambda do |text|
|
635
|
-
return text if text.empty?
|
636
|
-
leading_spaces = text.lines.first[/^(\s+)/, 1]
|
637
|
-
text.gsub(/^#{leading_spaces}/, '')
|
638
|
-
end
|
639
|
-
|
640
|
-
strip_leading_hash_and_whitespace_from_ruby_comments = lambda do |comment|
|
641
|
-
comment = comment.dup
|
642
|
-
comment.gsub!(/\A\#+?$/, '')
|
643
|
-
comment.gsub!(/^\s*#/, '')
|
644
|
-
strip_leading_whitespace.call(comment)
|
645
|
-
end
|
646
|
-
|
647
452
|
command "show-doc", "Show the comments above METH. Type `show-doc --help` for more info. Aliases: \?" do |*args|
|
648
453
|
options = {}
|
649
454
|
target = target()
|
@@ -667,6 +472,10 @@ e.g show-doc hello_method
|
|
667
472
|
target = Pry.binding_for(target.eval(context))
|
668
473
|
end
|
669
474
|
|
475
|
+
opts.on("-f", "--flood", "Do not use a pager to view text longer than one screen.") do
|
476
|
+
options[:f] = true
|
477
|
+
end
|
478
|
+
|
670
479
|
opts.on_tail("-h", "--help", "This message.") do
|
671
480
|
output.puts opts
|
672
481
|
options[:h] = true
|
@@ -677,37 +486,34 @@ e.g show-doc hello_method
|
|
677
486
|
|
678
487
|
next if options[:h]
|
679
488
|
|
680
|
-
if (meth = get_method_object
|
489
|
+
if (meth = get_method_object(meth_name, target, options)).nil?
|
681
490
|
output.puts "Invalid method name: #{meth_name}. Type `show-doc --help` for help"
|
682
491
|
next
|
683
492
|
end
|
684
493
|
|
685
|
-
case code_type = code_type_for
|
494
|
+
case code_type = code_type_for(meth)
|
686
495
|
when nil
|
687
496
|
next
|
688
497
|
when :c
|
689
498
|
doc = Pry::MethodInfo.info_for(meth).docstring
|
690
499
|
when :ruby
|
691
500
|
doc = meth.comment
|
692
|
-
doc = strip_leading_hash_and_whitespace_from_ruby_comments
|
693
|
-
set_file_and_dir_locals
|
501
|
+
doc = strip_leading_hash_and_whitespace_from_ruby_comments(doc)
|
502
|
+
set_file_and_dir_locals(meth.source_location.first)
|
694
503
|
end
|
695
504
|
|
696
505
|
next output.puts("No documentation found.") if doc.empty?
|
697
506
|
|
698
|
-
doc = process_comment_markup
|
507
|
+
doc = process_comment_markup(doc, code_type)
|
699
508
|
|
700
|
-
output.puts make_header
|
701
|
-
|
509
|
+
output.puts make_header(meth, code_type, doc)
|
510
|
+
|
511
|
+
render_output(options[:f], false, doc)
|
702
512
|
doc
|
703
513
|
end
|
704
514
|
|
705
515
|
alias_command "?", "show-doc", ""
|
706
516
|
|
707
|
-
strip_comments_from_c_code = lambda do |code|
|
708
|
-
code.sub /\A\s*\/\*.*?\*\/\s*/m, ''
|
709
|
-
end
|
710
|
-
|
711
517
|
command "show-method", "Show the source for METH. Type `show-method --help` for more info. Aliases: show-source" do |*args|
|
712
518
|
options = {}
|
713
519
|
target = target()
|
@@ -731,6 +537,10 @@ e.g: show-method hello_method
|
|
731
537
|
options[:m] = true
|
732
538
|
end
|
733
539
|
|
540
|
+
opts.on("-f", "--flood", "Do not use a pager to view text longer than one screen.") do
|
541
|
+
options[:f] = true
|
542
|
+
end
|
543
|
+
|
734
544
|
opts.on("-c", "--context CONTEXT", "Select object context to run under.") do |context|
|
735
545
|
target = Pry.binding_for(target.eval(context))
|
736
546
|
end
|
@@ -745,41 +555,69 @@ e.g: show-method hello_method
|
|
745
555
|
|
746
556
|
next if options[:h]
|
747
557
|
|
748
|
-
meth_name = meth_name_from_binding
|
558
|
+
meth_name = meth_name_from_binding(target) if !meth_name
|
749
559
|
|
750
|
-
if (meth = get_method_object
|
560
|
+
if (meth = get_method_object(meth_name, target, options)).nil?
|
751
561
|
output.puts "Invalid method name: #{meth_name}. Type `show-method --help` for help"
|
752
562
|
next
|
753
563
|
end
|
754
564
|
|
755
|
-
case code_type = code_type_for
|
565
|
+
case code_type = code_type_for(meth)
|
756
566
|
when nil
|
757
567
|
next
|
758
568
|
when :c
|
759
569
|
code = Pry::MethodInfo.info_for(meth).source
|
760
|
-
code = strip_comments_from_c_code
|
570
|
+
code = strip_comments_from_c_code(code)
|
761
571
|
when :ruby
|
762
|
-
code = strip_leading_whitespace
|
763
|
-
set_file_and_dir_locals
|
572
|
+
code = strip_leading_whitespace(meth.source)
|
573
|
+
set_file_and_dir_locals(meth.source_location.first)
|
764
574
|
end
|
765
575
|
|
766
|
-
output.puts make_header
|
576
|
+
output.puts make_header(meth, code_type, code)
|
767
577
|
if Pry.color
|
768
578
|
code = CodeRay.scan(code, code_type).term
|
769
579
|
end
|
770
580
|
|
581
|
+
start_line = false
|
771
582
|
if options[:l]
|
772
583
|
start_line = meth.source_location ? meth.source_location.last : 1
|
773
|
-
code = add_line_numbers.call(code, start_line)
|
774
584
|
end
|
775
585
|
|
776
|
-
|
586
|
+
render_output(options[:f], start_line, code)
|
777
587
|
code
|
778
588
|
end
|
779
589
|
|
780
590
|
alias_command "show-source", "show-method", ""
|
781
|
-
|
782
|
-
command "show-command", "Show
|
591
|
+
|
592
|
+
command "show-command", "Show the source for CMD. Type `show-command --help` for more info." do |*args|
|
593
|
+
options = {}
|
594
|
+
target = target()
|
595
|
+
command_name = nil
|
596
|
+
|
597
|
+
OptionParser.new do |opts|
|
598
|
+
opts.banner = %{Usage: show-command [OPTIONS] [CMD]
|
599
|
+
Show the source for command CMD.
|
600
|
+
e.g: show-command show-method
|
601
|
+
--
|
602
|
+
}
|
603
|
+
opts.on("-l", "--line-numbers", "Show line numbers.") do |line|
|
604
|
+
options[:l] = true
|
605
|
+
end
|
606
|
+
|
607
|
+
opts.on("-f", "--flood", "Do not use a pager to view text longer than one screen.") do
|
608
|
+
options[:f] = true
|
609
|
+
end
|
610
|
+
|
611
|
+
opts.on_tail("-h", "--help", "This message.") do
|
612
|
+
output.puts opts
|
613
|
+
options[:h] = true
|
614
|
+
end
|
615
|
+
end.order(args) do |v|
|
616
|
+
command_name = v
|
617
|
+
end
|
618
|
+
|
619
|
+
next if options[:h]
|
620
|
+
|
783
621
|
if !command_name
|
784
622
|
output.puts "You must provide a command name."
|
785
623
|
next
|
@@ -788,18 +626,18 @@ e.g: show-method hello_method
|
|
788
626
|
if commands[command_name]
|
789
627
|
meth = commands[command_name][:action]
|
790
628
|
|
791
|
-
code = strip_leading_whitespace
|
629
|
+
code = strip_leading_whitespace(meth.source)
|
792
630
|
file, line = meth.source_location
|
793
|
-
set_file_and_dir_locals
|
794
|
-
check_for_dynamically_defined_method
|
631
|
+
set_file_and_dir_locals(file)
|
632
|
+
check_for_dynamically_defined_method(meth)
|
795
633
|
|
796
|
-
output.puts
|
634
|
+
output.puts make_header(meth, :ruby, code)
|
797
635
|
|
798
636
|
if Pry.color
|
799
637
|
code = CodeRay.scan(code, :ruby).term
|
800
638
|
end
|
801
639
|
|
802
|
-
|
640
|
+
render_output(options[:f], options[:l] ? meth.source_location.last : false, code)
|
803
641
|
code
|
804
642
|
else
|
805
643
|
output.puts "No such command: #{command_name}."
|
@@ -822,7 +660,7 @@ e.g: show-method hello_method
|
|
822
660
|
end
|
823
661
|
|
824
662
|
command "exit", "End the current Pry session. Accepts optional return value. Aliases: quit, back" do
|
825
|
-
str = remove_first_word
|
663
|
+
str = remove_first_word(opts[:val])
|
826
664
|
throw(:breakout, [opts[:nesting].level, target.eval(str)])
|
827
665
|
end
|
828
666
|
|
@@ -862,7 +700,7 @@ Is absorbed, not refracted, by grey stone.
|
|
862
700
|
The dahlias sleep in the empty silence.
|
863
701
|
Wait for the early owl.
|
864
702
|
-- T.S Eliot
|
865
|
-
}
|
703
|
+
}
|
866
704
|
output.puts text
|
867
705
|
text
|
868
706
|
end
|
data/lib/pry/hooks.rb
CHANGED
@@ -12,7 +12,7 @@ class Pry
|
|
12
12
|
|
13
13
|
# /unknown/ for rbx
|
14
14
|
if file !~ /(\(.*\))|<.*>/ && file !~ /__unknown__/ && file != ""
|
15
|
-
Pry.run_command "whereami", :output => out, :show_output => true, :context => target, :commands => Pry::Commands
|
15
|
+
Pry.run_command "whereami 5", :output => out, :show_output => true, :context => target, :commands => Pry::Commands
|
16
16
|
end
|
17
17
|
end,
|
18
18
|
|
data/lib/pry/pry_class.rb
CHANGED
@@ -179,7 +179,13 @@ class Pry
|
|
179
179
|
|
180
180
|
null_output = Object.new.tap { |v| v.instance_eval { def puts(*) end } }
|
181
181
|
|
182
|
-
|
182
|
+
# FIXME! ugly hack to get around broken methods in both YARD and RBX
|
183
|
+
if RUBY_VERSION =~ /1.9/
|
184
|
+
commands = options[:commands].dup
|
185
|
+
else
|
186
|
+
commands = options[:commands].clone
|
187
|
+
end
|
188
|
+
|
183
189
|
commands.output = options[:show_output] ? options[:output] : null_output
|
184
190
|
commands.target = Pry.binding_for(options[:context])
|
185
191
|
|
data/lib/pry/pry_instance.rb
CHANGED
@@ -143,7 +143,7 @@ class Pry
|
|
143
143
|
target = Pry.binding_for(target)
|
144
144
|
result = re(target)
|
145
145
|
|
146
|
-
print.call output, result if
|
146
|
+
print.call output, result if should_print?(result)
|
147
147
|
end
|
148
148
|
|
149
149
|
# Perform a read-eval
|
@@ -202,7 +202,7 @@ class Pry
|
|
202
202
|
@suppress_output = true if eval_string =~ /;\Z/
|
203
203
|
|
204
204
|
eval_string
|
205
|
-
end
|
205
|
+
end
|
206
206
|
|
207
207
|
# Returns true if input is "" and a command is not returning a
|
208
208
|
# value.
|
@@ -284,6 +284,15 @@ class Pry
|
|
284
284
|
end
|
285
285
|
end
|
286
286
|
|
287
|
+
# Whether the print proc should be invoked.
|
288
|
+
# Currently only invoked if the output is not suppressed OR the output
|
289
|
+
# is an exception regardless of suppression.
|
290
|
+
# @param [Object] result The result of evaluation stage of the REPL
|
291
|
+
# @return [Boolean] Whether the print proc should be invoked.
|
292
|
+
def should_print?(result)
|
293
|
+
!@suppress_output || result.is_a?(Exception)
|
294
|
+
end
|
295
|
+
|
287
296
|
# Returns the appropriate prompt to use.
|
288
297
|
# This method should not need to be invoked directly.
|
289
298
|
# @param [Boolean] first_line Whether this is the first line of input
|
data/lib/pry/version.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: -766259880
|
4
5
|
prerelease: true
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 8
|
8
|
-
-
|
9
|
-
version: 0.8.
|
9
|
+
- 0pre7
|
10
|
+
version: 0.8.0pre7
|
10
11
|
platform: i386-mswin32
|
11
12
|
authors:
|
12
13
|
- John Mair (banisterfiend)
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2011-04-
|
18
|
+
date: 2011-04-12 00:00:00 +12:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
@@ -25,6 +26,7 @@ dependencies:
|
|
25
26
|
requirements:
|
26
27
|
- - ">="
|
27
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 5
|
28
30
|
segments:
|
29
31
|
- 2
|
30
32
|
- 0
|
@@ -40,6 +42,7 @@ dependencies:
|
|
40
42
|
requirements:
|
41
43
|
- - ">="
|
42
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 53
|
43
46
|
segments:
|
44
47
|
- 0
|
45
48
|
- 9
|
@@ -55,6 +58,7 @@ dependencies:
|
|
55
58
|
requirements:
|
56
59
|
- - ">="
|
57
60
|
- !ruby/object:Gem::Version
|
61
|
+
hash: 19
|
58
62
|
segments:
|
59
63
|
- 1
|
60
64
|
- 1
|
@@ -70,6 +74,7 @@ dependencies:
|
|
70
74
|
requirements:
|
71
75
|
- - ">="
|
72
76
|
- !ruby/object:Gem::Version
|
77
|
+
hash: 15
|
73
78
|
segments:
|
74
79
|
- 0
|
75
80
|
- 4
|
@@ -85,6 +90,7 @@ dependencies:
|
|
85
90
|
requirements:
|
86
91
|
- - ">="
|
87
92
|
- !ruby/object:Gem::Version
|
93
|
+
hash: 27
|
88
94
|
segments:
|
89
95
|
- 1
|
90
96
|
- 3
|
@@ -109,6 +115,7 @@ files:
|
|
109
115
|
- lib/pry/hooks.rb
|
110
116
|
- lib/pry/custom_completions.rb
|
111
117
|
- lib/pry/core_extensions.rb
|
118
|
+
- lib/pry/command_helpers.rb
|
112
119
|
- lib/pry/command_processor.rb
|
113
120
|
- lib/pry/completion.rb
|
114
121
|
- lib/pry/print.rb
|
@@ -148,6 +155,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
148
155
|
requirements:
|
149
156
|
- - ">="
|
150
157
|
- !ruby/object:Gem::Version
|
158
|
+
hash: 3
|
151
159
|
segments:
|
152
160
|
- 0
|
153
161
|
version: "0"
|
@@ -156,6 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
164
|
requirements:
|
157
165
|
- - ">"
|
158
166
|
- !ruby/object:Gem::Version
|
167
|
+
hash: 25
|
159
168
|
segments:
|
160
169
|
- 1
|
161
170
|
- 3
|