pry 0.10.2-i386-mswin32 → 1.0.0.pre1-i386-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (189) hide show
  1. data/.document +2 -0
  2. data/.gitignore +16 -0
  3. data/.travis.yml +21 -0
  4. data/.yardopts +3 -0
  5. data/CHANGELOG +503 -0
  6. data/CONTRIBUTORS +55 -0
  7. data/Gemfile +9 -0
  8. data/Guardfile +62 -0
  9. data/LICENSE +2 -2
  10. data/{README.md → README.markdown} +31 -37
  11. data/Rakefile +144 -0
  12. data/TODO +117 -0
  13. data/lib/pry.rb +146 -33
  14. data/lib/pry/cli.rb +13 -35
  15. data/lib/pry/code.rb +63 -24
  16. data/lib/pry/code/loc.rb +2 -2
  17. data/lib/pry/code_object.rb +21 -40
  18. data/lib/pry/command.rb +6 -9
  19. data/lib/pry/command_set.rb +37 -80
  20. data/lib/pry/commands.rb +1 -1
  21. data/lib/pry/commands/amend_line.rb +1 -1
  22. data/lib/pry/commands/bang.rb +1 -1
  23. data/lib/pry/commands/cat.rb +2 -11
  24. data/lib/pry/commands/cat/abstract_formatter.rb +1 -1
  25. data/lib/pry/commands/cat/exception_formatter.rb +7 -6
  26. data/lib/pry/commands/cat/file_formatter.rb +32 -15
  27. data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
  28. data/lib/pry/commands/cd.rb +3 -14
  29. data/lib/pry/commands/code_collector.rb +4 -4
  30. data/lib/pry/commands/easter_eggs.rb +3 -3
  31. data/lib/pry/commands/edit.rb +22 -10
  32. data/lib/pry/commands/edit/exception_patcher.rb +1 -1
  33. data/lib/pry/commands/edit/file_and_line_locator.rb +2 -0
  34. data/lib/pry/{method/patcher.rb → commands/edit/method_patcher.rb} +37 -40
  35. data/lib/pry/commands/find_method.rb +22 -16
  36. data/lib/pry/commands/gem_install.rb +2 -5
  37. data/lib/pry/commands/gem_open.rb +1 -1
  38. data/lib/pry/commands/gist.rb +11 -10
  39. data/lib/pry/commands/help.rb +14 -14
  40. data/lib/pry/commands/hist.rb +5 -24
  41. data/lib/pry/commands/ls.rb +287 -56
  42. data/lib/pry/commands/play.rb +10 -44
  43. data/lib/pry/commands/pry_backtrace.rb +2 -1
  44. data/lib/pry/commands/raise_up.rb +1 -1
  45. data/lib/pry/commands/reload_code.rb +15 -31
  46. data/lib/pry/commands/ri.rb +3 -7
  47. data/lib/pry/commands/shell_command.rb +12 -17
  48. data/lib/pry/commands/shell_mode.rb +2 -2
  49. data/lib/pry/commands/show_doc.rb +0 -5
  50. data/lib/pry/commands/show_info.rb +10 -11
  51. data/lib/pry/commands/show_source.rb +3 -15
  52. data/lib/pry/commands/simple_prompt.rb +1 -1
  53. data/lib/pry/commands/toggle_color.rb +4 -8
  54. data/lib/pry/commands/whereami.rb +10 -18
  55. data/lib/pry/completion.rb +293 -0
  56. data/lib/pry/config.rb +233 -20
  57. data/lib/pry/core_extensions.rb +19 -29
  58. data/lib/pry/custom_completions.rb +6 -0
  59. data/lib/pry/editor.rb +103 -109
  60. data/lib/pry/helpers/base_helpers.rb +109 -22
  61. data/lib/pry/helpers/command_helpers.rb +8 -10
  62. data/lib/pry/helpers/documentation_helpers.rb +2 -1
  63. data/lib/pry/helpers/text.rb +5 -4
  64. data/lib/pry/history.rb +10 -21
  65. data/lib/pry/history_array.rb +0 -5
  66. data/lib/pry/hooks.rb +29 -9
  67. data/lib/pry/indent.rb +10 -5
  68. data/lib/pry/method.rb +86 -81
  69. data/lib/pry/method/weird_method_locator.rb +2 -4
  70. data/lib/pry/module_candidate.rb +14 -5
  71. data/lib/pry/pager.rb +48 -193
  72. data/lib/pry/plugins.rb +2 -2
  73. data/lib/pry/pry_class.rb +193 -104
  74. data/lib/pry/pry_instance.rb +154 -152
  75. data/lib/pry/rbx_method.rb +13 -0
  76. data/lib/pry/rbx_path.rb +1 -1
  77. data/lib/pry/repl.rb +14 -17
  78. data/lib/pry/repl_file_loader.rb +3 -8
  79. data/lib/pry/rubygem.rb +3 -3
  80. data/lib/pry/terminal.rb +3 -4
  81. data/lib/pry/test/helper.rb +11 -6
  82. data/lib/pry/version.rb +1 -1
  83. data/lib/pry/wrapped_module.rb +56 -49
  84. data/man/pry.1 +195 -0
  85. data/man/pry.1.html +204 -0
  86. data/man/pry.1.ronn +141 -0
  87. data/pry.gemspec +31 -0
  88. data/spec/Procfile +3 -0
  89. data/spec/cli_spec.rb +78 -0
  90. data/spec/code_object_spec.rb +277 -0
  91. data/spec/code_spec.rb +219 -0
  92. data/spec/command_helpers_spec.rb +29 -0
  93. data/spec/command_integration_spec.rb +562 -0
  94. data/spec/command_set_spec.rb +627 -0
  95. data/spec/command_spec.rb +821 -0
  96. data/spec/commands/amend_line_spec.rb +247 -0
  97. data/spec/commands/bang_spec.rb +18 -0
  98. data/spec/commands/cat_spec.rb +164 -0
  99. data/spec/commands/cd_spec.rb +250 -0
  100. data/spec/commands/disable_pry_spec.rb +25 -0
  101. data/spec/commands/edit_spec.rb +725 -0
  102. data/spec/commands/exit_all_spec.rb +27 -0
  103. data/spec/commands/exit_program_spec.rb +19 -0
  104. data/spec/commands/exit_spec.rb +28 -0
  105. data/spec/commands/find_method_spec.rb +70 -0
  106. data/spec/commands/gem_list_spec.rb +26 -0
  107. data/spec/commands/gist_spec.rb +79 -0
  108. data/spec/commands/help_spec.rb +56 -0
  109. data/spec/commands/hist_spec.rb +172 -0
  110. data/spec/commands/jump_to_spec.rb +15 -0
  111. data/spec/commands/ls_spec.rb +189 -0
  112. data/spec/commands/play_spec.rb +136 -0
  113. data/spec/commands/raise_up_spec.rb +56 -0
  114. data/spec/commands/save_file_spec.rb +177 -0
  115. data/spec/commands/show_doc_spec.rb +488 -0
  116. data/spec/commands/show_input_spec.rb +17 -0
  117. data/spec/commands/show_source_spec.rb +760 -0
  118. data/spec/commands/whereami_spec.rb +203 -0
  119. data/spec/completion_spec.rb +221 -0
  120. data/spec/control_d_handler_spec.rb +62 -0
  121. data/spec/documentation_helper_spec.rb +73 -0
  122. data/spec/editor_spec.rb +79 -0
  123. data/spec/exception_whitelist_spec.rb +21 -0
  124. data/spec/fixtures/candidate_helper1.rb +11 -0
  125. data/spec/fixtures/candidate_helper2.rb +8 -0
  126. data/spec/fixtures/example.erb +5 -0
  127. data/spec/fixtures/example_nesting.rb +33 -0
  128. data/spec/fixtures/show_source_doc_examples.rb +15 -0
  129. data/spec/fixtures/testlinkrc +2 -0
  130. data/spec/fixtures/testrc +2 -0
  131. data/spec/fixtures/testrcbad +2 -0
  132. data/spec/fixtures/whereami_helper.rb +6 -0
  133. data/spec/helper.rb +35 -0
  134. data/spec/helpers/bacon.rb +86 -0
  135. data/spec/helpers/mock_pry.rb +44 -0
  136. data/spec/helpers/repl_tester.rb +112 -0
  137. data/spec/helpers/table_spec.rb +105 -0
  138. data/spec/history_array_spec.rb +67 -0
  139. data/spec/hooks_spec.rb +522 -0
  140. data/spec/indent_spec.rb +301 -0
  141. data/spec/method_spec.rb +482 -0
  142. data/spec/prompt_spec.rb +61 -0
  143. data/spec/pry_defaults_spec.rb +420 -0
  144. data/spec/pry_history_spec.rb +69 -0
  145. data/spec/pry_output_spec.rb +95 -0
  146. data/spec/pry_repl_spec.rb +86 -0
  147. data/spec/pry_spec.rb +394 -0
  148. data/spec/pryrc_spec.rb +97 -0
  149. data/spec/run_command_spec.rb +25 -0
  150. data/spec/sticky_locals_spec.rb +147 -0
  151. data/spec/syntax_checking_spec.rb +81 -0
  152. data/spec/wrapped_module_spec.rb +261 -0
  153. data/wiki/Customizing-pry.md +397 -0
  154. data/wiki/Home.md +4 -0
  155. metadata +272 -61
  156. checksums.yaml +0 -7
  157. data/CHANGELOG.md +0 -714
  158. data/lib/pry/code/code_file.rb +0 -103
  159. data/lib/pry/color_printer.rb +0 -55
  160. data/lib/pry/commands/change_inspector.rb +0 -27
  161. data/lib/pry/commands/change_prompt.rb +0 -26
  162. data/lib/pry/commands/list_inspectors.rb +0 -35
  163. data/lib/pry/commands/list_prompts.rb +0 -35
  164. data/lib/pry/commands/ls/constants.rb +0 -47
  165. data/lib/pry/commands/ls/formatter.rb +0 -49
  166. data/lib/pry/commands/ls/globals.rb +0 -48
  167. data/lib/pry/commands/ls/grep.rb +0 -21
  168. data/lib/pry/commands/ls/instance_vars.rb +0 -39
  169. data/lib/pry/commands/ls/interrogatable.rb +0 -18
  170. data/lib/pry/commands/ls/jruby_hacks.rb +0 -49
  171. data/lib/pry/commands/ls/local_names.rb +0 -35
  172. data/lib/pry/commands/ls/local_vars.rb +0 -39
  173. data/lib/pry/commands/ls/ls_entity.rb +0 -70
  174. data/lib/pry/commands/ls/methods.rb +0 -57
  175. data/lib/pry/commands/ls/methods_helper.rb +0 -46
  176. data/lib/pry/commands/ls/self_methods.rb +0 -32
  177. data/lib/pry/commands/watch_expression.rb +0 -105
  178. data/lib/pry/commands/watch_expression/expression.rb +0 -38
  179. data/lib/pry/config/behavior.rb +0 -139
  180. data/lib/pry/config/convenience.rb +0 -25
  181. data/lib/pry/config/default.rb +0 -161
  182. data/lib/pry/exceptions.rb +0 -78
  183. data/lib/pry/input_completer.rb +0 -242
  184. data/lib/pry/input_lock.rb +0 -132
  185. data/lib/pry/inspector.rb +0 -27
  186. data/lib/pry/last_exception.rb +0 -61
  187. data/lib/pry/object_path.rb +0 -82
  188. data/lib/pry/output.rb +0 -50
  189. data/lib/pry/prompt.rb +0 -26
@@ -89,7 +89,7 @@ class Object
89
89
  # If we can't define methods on the Object's singleton_class. Then we fall
90
90
  # back to setting the default definee to be the Object's class. That seems
91
91
  # nicer than having a REPL in which you can't define methods.
92
- rescue TypeError, Pry::FrozenObjectException
92
+ rescue TypeError
93
93
  # class_eval sets the default definee to self.class
94
94
  self.class.class_eval(*Pry::BINDING_METHOD_IMPL)
95
95
  end
@@ -99,33 +99,23 @@ class Object
99
99
  end
100
100
  end
101
101
 
102
- class BasicObject
103
- # Return a binding object for the receiver.
104
- #
105
- # The `self` of the binding is set to the current object, and it contains no
106
- # local variables.
107
- #
108
- # The default definee (http://yugui.jp/articles/846) is set such that new
109
- # methods defined will be added to the singleton class of the BasicObject.
110
- #
111
- # @return [Binding]
112
- def __binding__
113
- # BasicObjects don't have respond_to?, so we just define the method
114
- # every time. As they also don't have `.freeze`, this call won't
115
- # fail as it can for normal Objects.
116
- (class << self; self; end).class_eval <<-EOF, __FILE__, __LINE__ + 1
117
- # Get a binding with 'self' set to self, and no locals.
118
- #
119
- # The default definee is determined by the context in which the
120
- # definition is eval'd.
121
- #
122
- # Please don't call this method directly, see {__binding__}.
123
- #
124
- # @return [Binding]
125
- def __pry__
126
- ::Kernel.binding
127
- end
128
- EOF
129
- self.__pry__
102
+ # There's a splat bug on jruby in 1.9 emulation mode, which breaks the
103
+ # pp library.
104
+ #
105
+ # * http://jira.codehaus.org/browse/JRUBY-6687
106
+ # * https://github.com/pry/pry/issues/568
107
+ #
108
+ # Until that gets fixed upstream, let's monkey-patch here:
109
+ if [[1, 2]].pretty_inspect == "[1]\n"
110
+ class Array
111
+ def pretty_print(q)
112
+ q.group(1, '[', ']') {
113
+ i = 0
114
+ q.seplist(self) { |*|
115
+ q.pp self[i]
116
+ i += 1
117
+ }
118
+ }
119
+ end
130
120
  end
131
121
  end
@@ -0,0 +1,6 @@
1
+ class Pry
2
+
3
+ # This proc will be instance_eval's against the active Pry instance
4
+ DEFAULT_CUSTOM_COMPLETIONS = proc { commands.commands.keys }
5
+ FILE_COMPLETIONS = proc { commands.commands.keys + Dir.entries('.') }
6
+ end
@@ -1,135 +1,129 @@
1
1
  class Pry
2
2
  class Editor
3
- include Pry::Helpers::BaseHelpers
4
- include Pry::Helpers::CommandHelpers
5
-
6
- attr_reader :_pry_
7
-
8
- def initialize(_pry_)
9
- @_pry_ = _pry_
10
- end
11
-
12
- def edit_tempfile_with_content(initial_content, line=1)
13
- temp_file do |f|
14
- f.puts(initial_content)
15
- f.flush
16
- f.close(false)
17
- invoke_editor(f.path, line, true)
18
- File.read(f.path)
3
+ extend Pry::Helpers::BaseHelpers
4
+ extend Pry::Helpers::CommandHelpers
5
+
6
+ class << self
7
+ def edit_tempfile_with_content(initial_content, line=1)
8
+ temp_file do |f|
9
+ f.puts(initial_content)
10
+ f.flush
11
+ f.close(false)
12
+ invoke_editor(f.path, line, true)
13
+ File.read(f.path)
14
+ end
19
15
  end
20
- end
21
16
 
22
- def invoke_editor(file, line, blocking=true)
23
- raise CommandError, "Please set Pry.config.editor or export $VISUAL or $EDITOR" unless _pry_.config.editor
17
+ def invoke_editor(file, line, blocking=true)
18
+ raise CommandError, "Please set Pry.config.editor or export $VISUAL or $EDITOR" unless Pry.config.editor
24
19
 
25
- editor_invocation = build_editor_invocation_string(file, line, blocking)
26
- return nil unless editor_invocation
20
+ editor_invocation = build_editor_invocation_string(file, line, blocking)
21
+ return nil unless editor_invocation
27
22
 
28
- if jruby?
29
- open_editor_on_jruby(editor_invocation)
30
- else
31
- open_editor(editor_invocation)
23
+ if jruby?
24
+ open_editor_on_jruby(editor_invocation)
25
+ else
26
+ open_editor(editor_invocation)
27
+ end
32
28
  end
33
- end
34
29
 
35
- private
30
+ private
36
31
 
37
- # Generate the string that's used to start the editor. This includes
38
- # all the flags we want as well as the file and line number we
39
- # want to open at.
40
- def build_editor_invocation_string(file, line, blocking)
32
+ # Generate the string that's used to start the editor. This includes
33
+ # all the flags we want as well as the file and line number we
34
+ # want to open at.
35
+ def build_editor_invocation_string(file, line, blocking)
41
36
 
42
- if _pry_.config.editor.respond_to?(:call)
43
- args = [file, line, blocking][0...(_pry_.config.editor.arity)]
44
- _pry_.config.editor.call(*args)
45
- else
46
- sanitized_file = if windows?
47
- file.gsub(/\//, '\\')
48
- else
49
- Shellwords.escape(file)
50
- end
37
+ if Pry.config.editor.respond_to?(:call)
38
+ args = [file, line, blocking][0...(Pry.config.editor.arity)]
39
+ Pry.config.editor.call(*args)
40
+ else
41
+ sanitized_file = if windows?
42
+ file.gsub(/\//, '\\')
43
+ else
44
+ Shellwords.escape(file)
45
+ end
51
46
 
52
- "#{_pry_.config.editor} #{blocking_flag_for_editor(blocking)} #{start_line_syntax_for_editor(sanitized_file, line)}"
47
+ "#{Pry.config.editor} #{blocking_flag_for_editor(blocking)} #{start_line_syntax_for_editor(sanitized_file, line)}"
48
+ end
53
49
  end
54
- end
55
50
 
56
- # Start the editor running, using the calculated invocation string
57
- def open_editor(editor_invocation)
58
- # Note we dont want to use Pry.config.system here as that
59
- # may be invoked non-interactively (i.e via Open4), whereas we want to
60
- # ensure the editor is always interactive
61
- system(*Shellwords.split(editor_invocation)) or raise CommandError, "`#{editor_invocation}` gave exit status: #{$?.exitstatus}"
62
- end
51
+ # Start the editor running, using the calculated invocation string
52
+ def open_editor(editor_invocation)
53
+ # Note we dont want to use Pry.config.system here as that
54
+ # may be invoked non-interactively (i.e via Open4), whereas we want to
55
+ # ensure the editor is always interactive
56
+ system(editor_invocation) or raise CommandError, "`#{editor_invocation}` gave exit status: #{$?.exitstatus}"
57
+ end
63
58
 
64
- # We need JRuby specific code here cos just shelling out using
65
- # system() appears to be pretty broken :/
66
- def open_editor_on_jruby(editor_invocation)
67
- begin
68
- require 'spoon'
69
- pid = Spoon.spawnp(*Shellwords.split(editor_invocation))
70
- Process.waitpid(pid)
71
- rescue FFI::NotFoundError
72
- system(editor_invocation)
59
+ # We need JRuby specific code here cos just shelling out using
60
+ # system() appears to be pretty broken :/
61
+ def open_editor_on_jruby(editor_invocation)
62
+ begin
63
+ require 'spoon'
64
+ pid = Spoon.spawnp(*editor_invocation.split)
65
+ Process.waitpid(pid)
66
+ rescue FFI::NotFoundError
67
+ system(editor_invocation)
68
+ end
73
69
  end
74
- end
75
70
 
76
- # Some editors that run outside the terminal allow you to control whether or
77
- # not to block the process from which they were launched (in this case, Pry).
78
- # For those editors, return the flag that produces the desired behavior.
79
- def blocking_flag_for_editor(blocking)
80
- case editor_name
81
- when /^emacsclient/
82
- '--no-wait' unless blocking
83
- when /^[gm]vim/
84
- '--nofork' if blocking
85
- when /^jedit/
86
- '-wait' if blocking
87
- when /^mate/, /^subl/, /^redcar/
88
- '-w' if blocking
71
+ # Some editors that run outside the terminal allow you to control whether or
72
+ # not to block the process from which they were launched (in this case, Pry).
73
+ # For those editors, return the flag that produces the desired behavior.
74
+ def blocking_flag_for_editor(blocking)
75
+ case editor_name
76
+ when /^emacsclient/
77
+ '--no-wait' unless blocking
78
+ when /^[gm]vim/
79
+ '--nofork' if blocking
80
+ when /^jedit/
81
+ '-wait' if blocking
82
+ when /^mate/, /^subl/
83
+ '-w' if blocking
84
+ end
89
85
  end
90
- end
91
86
 
92
- # Return the syntax for a given editor for starting the editor
93
- # and moving to a particular line within that file
94
- def start_line_syntax_for_editor(file_name, line_number)
95
- # special case for 1st line
96
- return file_name if line_number <= 1
87
+ # Return the syntax for a given editor for starting the editor
88
+ # and moving to a particular line within that file
89
+ def start_line_syntax_for_editor(file_name, line_number)
90
+ # special case for 1st line
91
+ return file_name if line_number <= 1
97
92
 
98
- case editor_name
99
- when /^[gm]?vi/, /^emacs/, /^nano/, /^pico/, /^gedit/, /^kate/
100
- "+#{line_number} #{file_name}"
101
- when /^mate/, /^geany/
102
- "-l #{line_number} #{file_name}"
103
- when /^subl/
104
- "#{file_name}:#{line_number}"
105
- when /^uedit32/
106
- "#{file_name}/#{line_number}"
107
- when /^jedit/
108
- "#{file_name} +line:#{line_number}"
109
- when /^redcar/
110
- "-l#{line_number} #{file_name}"
111
- else
112
- if windows?
113
- "#{file_name}"
114
- else
93
+ case editor_name
94
+ when /^[gm]?vi/, /^emacs/, /^nano/, /^pico/, /^gedit/, /^kate/
115
95
  "+#{line_number} #{file_name}"
96
+ when /^mate/, /^geany/
97
+ "-l #{line_number} #{file_name}"
98
+ when /^subl/
99
+ "#{file_name}:#{line_number}"
100
+ when /^uedit32/
101
+ "#{file_name}/#{line_number}"
102
+ when /^jedit/
103
+ "#{file_name} +line:#{line_number}"
104
+ else
105
+ if windows?
106
+ "#{file_name}"
107
+ else
108
+ "+#{line_number} #{file_name}"
109
+ end
116
110
  end
117
111
  end
118
- end
119
112
 
120
- # Get the name of the binary that Pry.config.editor points to.
121
- #
122
- # This is useful for deciding which flags we pass to the editor as
123
- # we can just use the program's name and ignore any absolute paths.
124
- #
125
- # @example
126
- # Pry.config.editor="/home/conrad/bin/textmate -w"
127
- # editor_name
128
- # # => textmate
129
- #
130
- def editor_name
131
- File.basename(_pry_.config.editor).split(" ").first
132
- end
113
+ # Get the name of the binary that Pry.config.editor points to.
114
+ #
115
+ # This is useful for deciding which flags we pass to the editor as
116
+ # we can just use the program's name and ignore any absolute paths.
117
+ #
118
+ # @example
119
+ # Pry.config.editor="/home/conrad/bin/textmate -w"
120
+ # editor_name
121
+ # # => textmate
122
+ #
123
+ def editor_name
124
+ File.basename(Pry.config.editor).split(" ").first
125
+ end
133
126
 
127
+ end
134
128
  end
135
129
  end
@@ -42,12 +42,25 @@ class Pry
42
42
  end
43
43
  end
44
44
 
45
+ def set_file_and_dir_locals(file_name, _pry_=_pry_(), target=target())
46
+ return if !target or !file_name
47
+ _pry_.last_file = File.expand_path(file_name)
48
+ _pry_.inject_local("_file_", _pry_.last_file, target)
49
+
50
+ _pry_.last_dir = File.dirname(_pry_.last_file)
51
+ _pry_.inject_local("_dir_", _pry_.last_dir, target)
52
+ end
53
+
45
54
  def use_ansi_codes?
46
55
  windows_ansi? || ENV['TERM'] && ENV['TERM'] != "dumb"
47
56
  end
48
57
 
49
58
  def colorize_code(code)
50
- CodeRay.scan(code, :ruby).term
59
+ if Pry.color
60
+ CodeRay.scan(code, :ruby).term
61
+ else
62
+ code
63
+ end
51
64
  end
52
65
 
53
66
  def highlight(string, regexp, highlight_color=:bright_yellow)
@@ -57,7 +70,7 @@ class Pry
57
70
  # formatting
58
71
  def heading(text)
59
72
  text = "#{text}\n--"
60
- "\e[1m#{text}\e[0m"
73
+ Pry.color ? "\e[1m#{text}\e[0m": text
61
74
  end
62
75
 
63
76
  # have fun on the Windows platform.
@@ -67,7 +80,7 @@ class Pry
67
80
 
68
81
  # are we able to use ansi on windows?
69
82
  def windows_ansi?
70
- defined?(Win32::Console) || ENV['ANSICON'] || (windows? && mri_2?)
83
+ defined?(Win32::Console) || ENV['ANSICON']
71
84
  end
72
85
 
73
86
  def jruby?
@@ -75,39 +88,113 @@ class Pry
75
88
  end
76
89
 
77
90
  def jruby_19?
78
- jruby? && RbConfig::CONFIG['ruby_version'] == '1.9'
91
+ RbConfig::CONFIG['ruby_install_name'] == 'jruby' &&
92
+ RbConfig::CONFIG['ruby_version'] == '1.9'
79
93
  end
80
94
 
81
95
  def rbx?
82
96
  RbConfig::CONFIG['ruby_install_name'] == 'rbx'
83
97
  end
84
98
 
85
- def mri?
86
- RbConfig::CONFIG['ruby_install_name'] == 'ruby'
99
+ def mri_18?
100
+ RUBY_VERSION =~ /1.8/ && RbConfig::CONFIG['ruby_install_name'] == 'ruby'
87
101
  end
88
102
 
89
103
  def mri_19?
90
- mri? && RUBY_VERSION =~ /^1\.9/
104
+ RUBY_VERSION =~ /1.9/ && RbConfig::CONFIG['ruby_install_name'] == 'ruby'
91
105
  end
92
106
 
93
- def mri_2?
94
- mri? && RUBY_VERSION =~ /^2/
95
- end
96
-
97
- def mri_20?
98
- mri? && RUBY_VERSION =~ /^2\.0/
99
- end
107
+ # Try to use `less` for paging, if it fails then use
108
+ # simple_pager. Also do not page if Pry.pager is falsey
109
+ def stagger_output(text, out = nil)
110
+ out ||= case
111
+ when respond_to?(:output)
112
+ # Mixin.
113
+ output
114
+ when Pry.respond_to?(:output)
115
+ # Parent.
116
+ Pry.output
117
+ else
118
+ # Sys.
119
+ $stdout
120
+ end
121
+
122
+ if text.lines.count < Pry::Pager.page_size || !Pry.pager
123
+ out.puts text
124
+ else
125
+ Pry::Pager.page(text)
126
+ end
127
+ rescue Errno::ENOENT
128
+ Pry::Pager.page(text, :simple)
129
+ rescue Errno::EPIPE
130
+ end
131
+
132
+ # @param [String] arg_string The object path expressed as a string.
133
+ # @param [Pry] _pry_ The relevant Pry instance.
134
+ # @param [Array<Binding>] old_stack The state of the old binding stack
135
+ # @return [Array<Array<Binding>, Array<Binding>>] An array
136
+ # containing two elements: The new `binding_stack` and the old `binding_stack`.
137
+ def context_from_object_path(arg_string, _pry_=nil, old_stack=[])
138
+
139
+ # Extract command arguments. Delete blank arguments like " ", but
140
+ # don't delete empty strings like "".
141
+ path = arg_string.split(/\//).delete_if { |a| a =~ /\A\s+\z/ }
142
+ stack = _pry_.binding_stack.dup
143
+ state_old_stack = old_stack
144
+
145
+ # Special case when we only get a single "/", return to root.
146
+ if path.empty?
147
+ state_old_stack = stack.dup unless old_stack.empty?
148
+ stack = [stack.first]
149
+ end
100
150
 
101
- def mri_21?
102
- mri? && RUBY_VERSION =~ /^2\.1/
151
+ path.each_with_index do |context, i|
152
+ begin
153
+ case context.chomp
154
+ when ""
155
+ state_old_stack = stack.dup
156
+ stack = [stack.first]
157
+ when "::"
158
+ state_old_stack = stack.dup
159
+ stack.push(TOPLEVEL_BINDING)
160
+ when "."
161
+ next
162
+ when ".."
163
+ unless stack.size == 1
164
+ # Don't rewrite old_stack if we're in complex expression
165
+ # (e.g.: `cd 1/2/3/../4).
166
+ state_old_stack = stack.dup if path.first == ".."
167
+ stack.pop
168
+ end
169
+ when "-"
170
+ unless old_stack.empty?
171
+ # Interchange current stack and old stack with each other.
172
+ stack, state_old_stack = state_old_stack, stack
173
+ end
174
+ else
175
+ state_old_stack = stack.dup if i == 0
176
+ stack.push(Pry.binding_for(stack.last.eval(context)))
177
+ end
178
+
179
+ rescue RescuableException => e
180
+ # Restore old stack to its initial values.
181
+ state_old_stack = old_stack
182
+
183
+ msg = [
184
+ "Bad object path: #{arg_string}.",
185
+ "Failed trying to resolve: #{context}.",
186
+ e.inspect
187
+ ].join(' ')
188
+
189
+ CommandError.new(msg).tap do |err|
190
+ err.set_backtrace e.backtrace
191
+ raise err
192
+ end
193
+ end
194
+ end
195
+ return stack, state_old_stack
103
196
  end
104
197
 
105
- # Send the given text through the best available pager (if Pry.config.pager is
106
- # enabled). Infers where to send the output if used as a mixin.
107
- # DEPRECATED.
108
- def stagger_output(text, out = nil)
109
- Pry.new.pager.page text
110
- end
111
198
  end
112
199
  end
113
200
  end