pry 0.9.9.3-i386-mingw32 → 0.9.9.4-i386-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ 26/4/2012 version 0.9.9.4 major bugfix
2
+ * fixed `NoMethodError: undefined method `winsize' for #<IO:<STDOUT>>`, bug #549
3
+ * fixes for jruby
4
+ * breakage on `exit` syntax error, fixes, #550
5
+ * heredoc content no longer auto-indented
6
+
1
7
  19/4/2012 version 0.9.9.3 major doc bugfix
2
8
  * show-doc would fail on some core classes, i.e `show-doc Bignum`. This is now fixed
3
9
  and show allow a wider range of core documentation to be viewed directly in Pry.
@@ -254,25 +254,29 @@ class Pry
254
254
 
255
255
  file_name, line = mod.source_location
256
256
  set_file_and_dir_locals(file_name)
257
- code = ""
258
- code << "\n#{Pry::Helpers::Text.bold('From:')} #{file_name} @ line #{line}:\n\n"
259
- code << Code.from_module(mod, module_start_line(mod)).with_line_numbers(use_line_numbers?).to_s
257
+ code = Code.from_module(mod, module_start_line(mod)).with_line_numbers(use_line_numbers?).to_s
258
+ result = ""
259
+ result << "\n#{Pry::Helpers::Text.bold('From:')} #{file_name} @ line #{line}:\n"
260
+ result << "#{Pry::Helpers::Text.bold('Number of lines:')} #{code.lines.count}\n\n"
261
+ result << code
260
262
  end
261
263
 
262
264
  def all_modules
263
265
  mod = module_object
264
266
 
265
- code = ""
266
- code << "Found #{mod.number_of_candidates} candidates for `#{mod.name}` definition:\n"
267
+ result = ""
268
+ result << "Found #{mod.number_of_candidates} candidates for `#{mod.name}` definition:\n"
267
269
  mod.number_of_candidates.times do |v|
268
270
  begin
269
- code << "\nCandidate #{v+1}/#{mod.number_of_candidates}: #{mod.source_file_for_candidate(v)} @ line #{mod.source_line_for_candidate(v)}:\n\n"
270
- code << Code.new(mod.source_for_candidate(v), module_start_line(mod, v)).with_line_numbers(use_line_numbers?).to_s
271
+ code = Code.new(mod.source_for_candidate(v), module_start_line(mod, v)).with_line_numbers(use_line_numbers?).to_s
272
+ result << "\nCandidate #{v+1}/#{mod.number_of_candidates}: #{mod.source_file_for_candidate(v)} @ line #{mod.source_line_for_candidate(v)}:\n"
273
+ result << "Number of lines: #{code.lines.count}\n\n"
274
+ result << code
271
275
  rescue Pry::RescuableException
272
276
  next
273
277
  end
274
278
  end
275
- code
279
+ result
276
280
  end
277
281
 
278
282
  def use_line_numbers?
@@ -41,11 +41,14 @@ class Pry
41
41
  end
42
42
 
43
43
  command "exit-all", "End the current Pry session (popping all bindings) and returning to caller. Accepts optional return value. Aliases: !!@" do
44
+ # calculate user-given value
45
+ exit_value = target.eval(arg_string)
46
+
44
47
  # clear the binding stack
45
48
  _pry_.binding_stack.clear
46
49
 
47
50
  # break out of the repl loop
48
- throw(:breakout, target.eval(arg_string))
51
+ throw(:breakout, exit_value)
49
52
  end
50
53
 
51
54
  alias_command "!!@", "exit-all"
data/lib/pry/indent.rb CHANGED
@@ -1,12 +1,10 @@
1
1
  require 'coderay'
2
2
 
3
3
  class Pry
4
+ # Load io-console if possible, so that we can use $stdout.winsize.
4
5
  begin
5
6
  require 'io/console'
6
7
  rescue LoadError
7
- IO_CONSOLE_AVAILABLE = false
8
- else
9
- IO_CONSOLE_AVAILABLE = true
10
8
  end
11
9
 
12
10
  ##
@@ -56,7 +54,7 @@ class Pry
56
54
  #
57
55
  # :pre_constant and :preserved_constant are the CodeRay 0.9.8 and 1.0.0
58
56
  # classifications of "true", "false", and "nil".
59
- IGNORE_TOKENS = [:space, :content, :string, :delimiter, :method, :ident,
57
+ IGNORE_TOKENS = [:space, :content, :string, :method, :ident,
60
58
  :constant, :pre_constant, :predefined_constant]
61
59
 
62
60
  # Tokens that indicate the end of a statement (i.e. that, if they appear
@@ -65,7 +63,8 @@ class Pry
65
63
  #
66
64
  # :reserved and :keywords are the CodeRay 0.9.8 and 1.0.0 respectively
67
65
  # classifications of "super", "next", "return", etc.
68
- STATEMENT_END_TOKENS = IGNORE_TOKENS + [:regexp, :integer, :float, :keyword, :reserved]
66
+ STATEMENT_END_TOKENS = IGNORE_TOKENS + [:regexp, :integer, :float, :keyword,
67
+ :delimiter, :reserved]
69
68
 
70
69
  # Collection of tokens that should appear dedented even though they
71
70
  # don't affect the surrounding code.
@@ -79,6 +78,9 @@ class Pry
79
78
  def reset
80
79
  @stack = []
81
80
  @indent_level = ''
81
+ @heredoc_queue = []
82
+ @close_heredocs = {}
83
+ @string_start = nil
82
84
  self
83
85
  end
84
86
 
@@ -109,14 +111,27 @@ class Pry
109
111
  prefix = indent_level
110
112
 
111
113
  input.lines.each do |line|
112
- tokens = CodeRay.scan(line, :ruby)
113
- tokens = tokens.tokens.each_slice(2) if tokens.respond_to?(:tokens) # Coderay 1.0.0
114
+
115
+ if in_string?
116
+ tokens = tokenize("#{open_delimiters_line}\n#{line}")
117
+ tokens = tokens.drop_while{ |token, type| !(String === token && token.include?("\n")) }
118
+ previously_in_string = true
119
+ else
120
+ tokens = tokenize(line)
121
+ previously_in_string = false
122
+ end
114
123
 
115
124
  before, after = indentation_delta(tokens)
116
125
 
117
126
  before.times{ prefix.sub! SPACES, '' }
118
- output += prefix + line.strip + "\n"
119
- prefix += SPACES * after
127
+ new_prefix = prefix + SPACES * after
128
+
129
+ line = prefix + line.lstrip unless previously_in_string
130
+ line = line.rstrip + "\n" unless in_string?
131
+
132
+ output += line
133
+
134
+ prefix = new_prefix
120
135
  end
121
136
 
122
137
  @indent_level = prefix
@@ -124,6 +139,16 @@ class Pry
124
139
  return output.gsub(/\s+$/, '')
125
140
  end
126
141
 
142
+ # Get the indentation for the start of the next line.
143
+ #
144
+ # This is what's used between the prompt and the cursor in pry.
145
+ #
146
+ # @return String The correct number of spaces
147
+ #
148
+ def current_prefix
149
+ in_string? ? '' : indent_level
150
+ end
151
+
127
152
  # Get the change in indentation indicated by the line.
128
153
  #
129
154
  # By convention, you remove indent from the line containing end tokens,
@@ -167,7 +192,9 @@ class Pry
167
192
 
168
193
  seen_for_at << add_after if token == "for"
169
194
 
170
- if OPEN_TOKENS.keys.include?(token) && !is_optional_do && !is_singleline_if
195
+ if kind == :delimiter
196
+ track_delimiter(token)
197
+ elsif OPEN_TOKENS.keys.include?(token) && !is_optional_do && !is_singleline_if
171
198
  @stack << token
172
199
  add_after += 1
173
200
  elsif token == OPEN_TOKENS[@stack.last]
@@ -194,6 +221,65 @@ class Pry
194
221
  (last_token =~ /^[)\]}\/]$/ || STATEMENT_END_TOKENS.include?(last_kind))
195
222
  end
196
223
 
224
+ # Are we currently in the middle of a string literal.
225
+ #
226
+ # This is used to determine whether to re-indent a given line, we mustn't re-indent
227
+ # within string literals because to do so would actually change the value of the
228
+ # String!
229
+ #
230
+ # @return Boolean
231
+ def in_string?
232
+ !open_delimiters.empty?
233
+ end
234
+
235
+ # Given a string of Ruby code, use CodeRay to export the tokens.
236
+ #
237
+ # @param String The Ruby to lex.
238
+ # @return [Array] An Array of pairs of [token_value, token_type]
239
+ def tokenize(string)
240
+ tokens = CodeRay.scan(string, :ruby)
241
+ tokens = tokens.tokens.each_slice(2) if tokens.respond_to?(:tokens) # Coderay 1.0.0
242
+ tokens.to_a
243
+ end
244
+
245
+ # Update the internal state about what kind of strings are open.
246
+ #
247
+ # Most of the complication here comes from the fact that HEREDOCs can be nested. For
248
+ # normal strings (which can't be nested) we assume that CodeRay correctly pairs
249
+ # open-and-close delimiters so we don't bother checking what they are.
250
+ #
251
+ # @param String The token (of type :delimiter)
252
+ def track_delimiter(token)
253
+ case token
254
+ when /^<<-(["'`]?)(.*)\\1/
255
+ @heredoc_queue << token
256
+ @close_heredocs[token] = /^\s*$2/
257
+ when @close_heredocs[@heredoc_queue.first]
258
+ @heredoc_queue.shift
259
+ else
260
+ if @string_start
261
+ @string_start = nil
262
+ else
263
+ @string_start = token
264
+ end
265
+ end
266
+ end
267
+
268
+ # All the open delimiters, in the order that they first appeared.
269
+ #
270
+ # @return [String]
271
+ def open_delimiters
272
+ @heredoc_queue + [@string_start].compact
273
+ end
274
+
275
+ # Return a string which restores the CodeRay string status to the correct value by
276
+ # opening HEREDOCs and strings.
277
+ #
278
+ # @return String
279
+ def open_delimiters_line
280
+ "puts #{open_delimiters.join(", ")}"
281
+ end
282
+
197
283
  # Return a string which, when printed, will rewrite the previous line with
198
284
  # the correct indentation. Mostly useful for fixing 'end'.
199
285
  #
@@ -204,19 +290,18 @@ class Pry
204
290
  # @return [String]
205
291
  def correct_indentation(prompt, code, overhang=0)
206
292
  full_line = prompt + code
207
- if IO_CONSOLE_AVAILABLE && $stdout.tty?
293
+ whitespace = ' ' * overhang
294
+
295
+ if $stdout.tty? && $stdout.respond_to?(:winsize)
208
296
  _, cols = $stdout.winsize
209
- lines = full_line.length / cols + 1
210
297
  elsif Readline.respond_to?(:get_screen_size)
211
298
  _, cols = Readline.get_screen_size
212
- lines = full_line.length / cols + 1
213
299
  elsif ENV['COLUMNS'] && ENV['COLUMNS'] != ''
214
300
  cols = ENV['COLUMNS'].to_i
215
- lines = full_line.length / cols + 1
216
- else
217
- lines = 1
218
301
  end
219
302
 
303
+ lines = cols ? (full_line.length / cols + 1) : 1
304
+
220
305
  if defined?(Win32::Console)
221
306
  move_up = "\e[#{lines}F"
222
307
  move_down = "\e[#{lines}E"
@@ -224,7 +309,6 @@ class Pry
224
309
  move_up = "\e[#{lines}A\e[0G"
225
310
  move_down = "\e[#{lines}B\e[0G"
226
311
  end
227
- whitespace = ' ' * overhang
228
312
 
229
313
  "#{move_up}#{prompt}#{colorize_code(code)}#{whitespace}#{move_down}"
230
314
  end
@@ -338,7 +338,7 @@ class Pry
338
338
  instance_eval(&custom_completions))
339
339
 
340
340
 
341
- indentation = Pry.config.auto_indent ? @indent.indent_level : ''
341
+ indentation = Pry.config.auto_indent ? @indent.current_prefix : ''
342
342
 
343
343
  begin
344
344
  val = readline("#{current_prompt}#{indentation}", completion_proc)
data/lib/pry/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Pry
2
- VERSION = "0.9.9.3"
2
+ VERSION = "0.9.9.4"
3
3
  end
data/pry.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "pry"
5
- s.version = "0.9.9.3"
5
+ s.version = "0.9.9.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["John Mair (banisterfiend)"]
9
- s.date = "2012-04-20"
9
+ s.date = "2012-04-26"
10
10
  s.description = "An IRB alternative and runtime developer console"
11
11
  s.email = "jrmair@gmail.com"
12
12
  s.executables = ["pry"]
@@ -77,6 +77,12 @@ describe "Pry::DefaultCommands::Context" do
77
77
  it 'should break out of the repl loop of Pry instance when binding_stack has only one binding with exit, and return user-given value' do
78
78
  Pry.start(0, :input => StringIO.new("exit :john")).should == :john
79
79
  end
80
+
81
+ it 'should break out the repl loop of Pry instance even after an exception in user-given value' do
82
+ redirect_pry_io(InputTester.new("exit = 42", "exit"), StringIO.new) do
83
+ ins = Pry.new.tap { |v| v.repl(0).should == nil }
84
+ end
85
+ end
80
86
  end
81
87
 
82
88
  describe "jump-to" do
data/test/test_indent.rb CHANGED
@@ -230,6 +230,46 @@ begin
230
230
  rescue => e
231
231
  doit :right
232
232
  end
233
+ OUTPUT
234
+
235
+ @indent.indent(input).should == output
236
+ end
237
+
238
+ it "should not indent inside strings" do
239
+ @indent.indent(%(def a\n"foo\nbar"\n end)).should == %(def a\n "foo\nbar"\nend)
240
+ @indent.indent(%(def a\nputs %w(foo\nbar), 'foo\nbar'\n end)).should == %(def a\n puts %w(foo\nbar), 'foo\nbar'\nend)
241
+ end
242
+
243
+ it "should not indent inside HEREDOCs" do
244
+ @indent.indent(%(def a\nputs <<FOO\n bar\nFOO\nbaz\nend)).should == %(def a\n puts <<FOO\n bar\nFOO\n baz\nend)
245
+ @indent.indent(%(def a\nputs <<-'^^'\n bar\n\t^^\nbaz\nend)).should == %(def a\n puts <<-'^^'\n bar\n\t^^\n baz\nend)
246
+ end
247
+
248
+ it "should not indent nested HEREDOCs" do
249
+ input = <<INPUT.strip
250
+ def a
251
+ puts <<FOO, <<-BAR, "baz", <<-':p'
252
+ foo
253
+ FOO
254
+ bar
255
+ BAR
256
+ tongue
257
+ :p
258
+ puts :p
259
+ end
260
+ INPUT
261
+
262
+ output = <<OUTPUT.strip
263
+ def a
264
+ puts <<FOO, <<-BAR, "baz", <<-':p'
265
+ foo
266
+ FOO
267
+ bar
268
+ BAR
269
+ tongue
270
+ :p
271
+ puts :p
272
+ end
233
273
  OUTPUT
234
274
 
235
275
  @indent.indent(input).should == output
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.9.3
4
+ version: 0.9.9.4
5
5
  prerelease:
6
6
  platform: i386-mingw32
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-20 00:00:00.000000000 Z
12
+ date: 2012-04-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: coderay
16
- requirement: &70353477842680 !ruby/object:Gem::Requirement
16
+ requirement: &70146513554660 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.0.5
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70353477842680
24
+ version_requirements: *70146513554660
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: slop
27
- requirement: &70353477842120 !ruby/object:Gem::Requirement
27
+ requirement: &70146513554080 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -35,10 +35,10 @@ dependencies:
35
35
  version: '3'
36
36
  type: :runtime
37
37
  prerelease: false
38
- version_requirements: *70353477842120
38
+ version_requirements: *70146513554080
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: method_source
41
- requirement: &70353477841100 !ruby/object:Gem::Requirement
41
+ requirement: &70146513569540 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
44
  - - ~>
@@ -46,10 +46,10 @@ dependencies:
46
46
  version: 0.7.1
47
47
  type: :runtime
48
48
  prerelease: false
49
- version_requirements: *70353477841100
49
+ version_requirements: *70146513569540
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: bacon
52
- requirement: &70353477840520 !ruby/object:Gem::Requirement
52
+ requirement: &70146513568940 !ruby/object:Gem::Requirement
53
53
  none: false
54
54
  requirements:
55
55
  - - ~>
@@ -57,10 +57,10 @@ dependencies:
57
57
  version: '1.1'
58
58
  type: :development
59
59
  prerelease: false
60
- version_requirements: *70353477840520
60
+ version_requirements: *70146513568940
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: open4
63
- requirement: &70353477840040 !ruby/object:Gem::Requirement
63
+ requirement: &70146513568400 !ruby/object:Gem::Requirement
64
64
  none: false
65
65
  requirements:
66
66
  - - ~>
@@ -68,10 +68,10 @@ dependencies:
68
68
  version: '1.3'
69
69
  type: :development
70
70
  prerelease: false
71
- version_requirements: *70353477840040
71
+ version_requirements: *70146513568400
72
72
  - !ruby/object:Gem::Dependency
73
73
  name: rake
74
- requirement: &70353477839380 !ruby/object:Gem::Requirement
74
+ requirement: &70146513567800 !ruby/object:Gem::Requirement
75
75
  none: false
76
76
  requirements:
77
77
  - - ~>
@@ -79,10 +79,10 @@ dependencies:
79
79
  version: '0.9'
80
80
  type: :development
81
81
  prerelease: false
82
- version_requirements: *70353477839380
82
+ version_requirements: *70146513567800
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: win32console
85
- requirement: &70353477838860 !ruby/object:Gem::Requirement
85
+ requirement: &70146513567220 !ruby/object:Gem::Requirement
86
86
  none: false
87
87
  requirements:
88
88
  - - ~>
@@ -90,7 +90,7 @@ dependencies:
90
90
  version: '1.3'
91
91
  type: :runtime
92
92
  prerelease: false
93
- version_requirements: *70353477838860
93
+ version_requirements: *70146513567220
94
94
  description: An IRB alternative and runtime developer console
95
95
  email: jrmair@gmail.com
96
96
  executables: