pry 0.9.12.6-java → 0.10.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +702 -0
  3. data/LICENSE +2 -2
  4. data/{README.markdown → README.md} +37 -31
  5. data/lib/pry.rb +38 -151
  6. data/lib/pry/cli.rb +35 -17
  7. data/lib/pry/code.rb +19 -63
  8. data/lib/pry/code/code_file.rb +103 -0
  9. data/lib/pry/code/code_range.rb +2 -1
  10. data/lib/pry/code/loc.rb +2 -2
  11. data/lib/pry/code_object.rb +40 -21
  12. data/lib/pry/color_printer.rb +55 -0
  13. data/lib/pry/command.rb +12 -9
  14. data/lib/pry/command_set.rb +81 -38
  15. data/lib/pry/commands.rb +1 -1
  16. data/lib/pry/commands/amend_line.rb +2 -2
  17. data/lib/pry/commands/bang.rb +1 -1
  18. data/lib/pry/commands/cat.rb +11 -2
  19. data/lib/pry/commands/cat/exception_formatter.rb +6 -7
  20. data/lib/pry/commands/cat/file_formatter.rb +15 -32
  21. data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
  22. data/lib/pry/commands/cd.rb +14 -3
  23. data/lib/pry/commands/change_inspector.rb +27 -0
  24. data/lib/pry/commands/change_prompt.rb +26 -0
  25. data/lib/pry/commands/code_collector.rb +4 -4
  26. data/lib/pry/commands/easter_eggs.rb +3 -3
  27. data/lib/pry/commands/edit.rb +10 -22
  28. data/lib/pry/commands/edit/exception_patcher.rb +2 -2
  29. data/lib/pry/commands/edit/file_and_line_locator.rb +0 -2
  30. data/lib/pry/commands/exit_program.rb +0 -1
  31. data/lib/pry/commands/find_method.rb +16 -22
  32. data/lib/pry/commands/gem_install.rb +5 -2
  33. data/lib/pry/commands/gem_open.rb +1 -1
  34. data/lib/pry/commands/gist.rb +10 -11
  35. data/lib/pry/commands/help.rb +14 -14
  36. data/lib/pry/commands/hist.rb +27 -8
  37. data/lib/pry/commands/install_command.rb +14 -12
  38. data/lib/pry/commands/list_inspectors.rb +35 -0
  39. data/lib/pry/commands/list_prompts.rb +35 -0
  40. data/lib/pry/commands/ls.rb +72 -296
  41. data/lib/pry/commands/ls/constants.rb +47 -0
  42. data/lib/pry/commands/ls/formatter.rb +49 -0
  43. data/lib/pry/commands/ls/globals.rb +48 -0
  44. data/lib/pry/commands/ls/grep.rb +21 -0
  45. data/lib/pry/commands/ls/instance_vars.rb +39 -0
  46. data/lib/pry/commands/ls/interrogatable.rb +18 -0
  47. data/lib/pry/commands/ls/jruby_hacks.rb +49 -0
  48. data/lib/pry/commands/ls/local_names.rb +35 -0
  49. data/lib/pry/commands/ls/local_vars.rb +39 -0
  50. data/lib/pry/commands/ls/ls_entity.rb +70 -0
  51. data/lib/pry/commands/ls/methods.rb +57 -0
  52. data/lib/pry/commands/ls/methods_helper.rb +46 -0
  53. data/lib/pry/commands/ls/self_methods.rb +32 -0
  54. data/lib/pry/commands/play.rb +44 -10
  55. data/lib/pry/commands/pry_backtrace.rb +1 -2
  56. data/lib/pry/commands/raise_up.rb +2 -2
  57. data/lib/pry/commands/reload_code.rb +16 -19
  58. data/lib/pry/commands/ri.rb +7 -3
  59. data/lib/pry/commands/shell_command.rb +18 -13
  60. data/lib/pry/commands/shell_mode.rb +2 -4
  61. data/lib/pry/commands/show_doc.rb +5 -0
  62. data/lib/pry/commands/show_info.rb +8 -13
  63. data/lib/pry/commands/show_source.rb +15 -3
  64. data/lib/pry/commands/simple_prompt.rb +1 -1
  65. data/lib/pry/commands/toggle_color.rb +8 -4
  66. data/lib/pry/commands/watch_expression.rb +105 -0
  67. data/lib/pry/commands/watch_expression/expression.rb +38 -0
  68. data/lib/pry/commands/whereami.rb +18 -10
  69. data/lib/pry/commands/wtf.rb +3 -3
  70. data/lib/pry/config.rb +20 -254
  71. data/lib/pry/config/behavior.rb +139 -0
  72. data/lib/pry/config/convenience.rb +26 -0
  73. data/lib/pry/config/default.rb +165 -0
  74. data/lib/pry/core_extensions.rb +31 -21
  75. data/lib/pry/editor.rb +107 -103
  76. data/lib/pry/exceptions.rb +77 -0
  77. data/lib/pry/helpers/base_helpers.rb +22 -109
  78. data/lib/pry/helpers/command_helpers.rb +10 -8
  79. data/lib/pry/helpers/documentation_helpers.rb +1 -2
  80. data/lib/pry/helpers/text.rb +4 -5
  81. data/lib/pry/history.rb +46 -45
  82. data/lib/pry/history_array.rb +6 -1
  83. data/lib/pry/hooks.rb +9 -29
  84. data/lib/pry/indent.rb +6 -6
  85. data/lib/pry/input_completer.rb +242 -0
  86. data/lib/pry/input_lock.rb +132 -0
  87. data/lib/pry/inspector.rb +27 -0
  88. data/lib/pry/last_exception.rb +61 -0
  89. data/lib/pry/method.rb +82 -87
  90. data/lib/pry/{commands/edit/method_patcher.rb → method/patcher.rb} +41 -38
  91. data/lib/pry/module_candidate.rb +4 -14
  92. data/lib/pry/object_path.rb +82 -0
  93. data/lib/pry/output.rb +50 -0
  94. data/lib/pry/pager.rb +193 -48
  95. data/lib/pry/plugins.rb +1 -1
  96. data/lib/pry/prompt.rb +26 -0
  97. data/lib/pry/pry_class.rb +149 -230
  98. data/lib/pry/pry_instance.rb +302 -413
  99. data/lib/pry/rbx_path.rb +1 -1
  100. data/lib/pry/repl.rb +202 -0
  101. data/lib/pry/repl_file_loader.rb +20 -26
  102. data/lib/pry/rubygem.rb +13 -5
  103. data/lib/pry/terminal.rb +2 -1
  104. data/lib/pry/test/helper.rb +26 -41
  105. data/lib/pry/version.rb +1 -1
  106. data/lib/pry/wrapped_module.rb +45 -59
  107. metadata +62 -225
  108. data/.document +0 -2
  109. data/.gitignore +0 -16
  110. data/.travis.yml +0 -25
  111. data/.yardopts +0 -1
  112. data/CHANGELOG +0 -534
  113. data/CONTRIBUTORS +0 -55
  114. data/Gemfile +0 -12
  115. data/Rakefile +0 -140
  116. data/TODO +0 -117
  117. data/lib/pry/completion.rb +0 -321
  118. data/lib/pry/custom_completions.rb +0 -6
  119. data/lib/pry/rbx_method.rb +0 -13
  120. data/man/pry.1 +0 -195
  121. data/man/pry.1.html +0 -204
  122. data/man/pry.1.ronn +0 -141
  123. data/pry.gemspec +0 -29
  124. data/spec/Procfile +0 -3
  125. data/spec/cli_spec.rb +0 -78
  126. data/spec/code_object_spec.rb +0 -277
  127. data/spec/code_spec.rb +0 -219
  128. data/spec/command_helpers_spec.rb +0 -29
  129. data/spec/command_integration_spec.rb +0 -644
  130. data/spec/command_set_spec.rb +0 -627
  131. data/spec/command_spec.rb +0 -821
  132. data/spec/commands/amend_line_spec.rb +0 -247
  133. data/spec/commands/bang_spec.rb +0 -19
  134. data/spec/commands/cat_spec.rb +0 -164
  135. data/spec/commands/cd_spec.rb +0 -250
  136. data/spec/commands/disable_pry_spec.rb +0 -25
  137. data/spec/commands/edit_spec.rb +0 -727
  138. data/spec/commands/exit_all_spec.rb +0 -34
  139. data/spec/commands/exit_program_spec.rb +0 -19
  140. data/spec/commands/exit_spec.rb +0 -34
  141. data/spec/commands/find_method_spec.rb +0 -70
  142. data/spec/commands/gem_list_spec.rb +0 -26
  143. data/spec/commands/gist_spec.rb +0 -79
  144. data/spec/commands/help_spec.rb +0 -56
  145. data/spec/commands/hist_spec.rb +0 -181
  146. data/spec/commands/jump_to_spec.rb +0 -15
  147. data/spec/commands/ls_spec.rb +0 -181
  148. data/spec/commands/play_spec.rb +0 -140
  149. data/spec/commands/raise_up_spec.rb +0 -56
  150. data/spec/commands/save_file_spec.rb +0 -177
  151. data/spec/commands/show_doc_spec.rb +0 -510
  152. data/spec/commands/show_input_spec.rb +0 -17
  153. data/spec/commands/show_source_spec.rb +0 -782
  154. data/spec/commands/whereami_spec.rb +0 -203
  155. data/spec/completion_spec.rb +0 -241
  156. data/spec/control_d_handler_spec.rb +0 -58
  157. data/spec/documentation_helper_spec.rb +0 -73
  158. data/spec/editor_spec.rb +0 -79
  159. data/spec/exception_whitelist_spec.rb +0 -21
  160. data/spec/fixtures/candidate_helper1.rb +0 -11
  161. data/spec/fixtures/candidate_helper2.rb +0 -8
  162. data/spec/fixtures/example.erb +0 -5
  163. data/spec/fixtures/example_nesting.rb +0 -33
  164. data/spec/fixtures/show_source_doc_examples.rb +0 -15
  165. data/spec/fixtures/testrc +0 -2
  166. data/spec/fixtures/testrcbad +0 -2
  167. data/spec/fixtures/whereami_helper.rb +0 -6
  168. data/spec/helper.rb +0 -34
  169. data/spec/helpers/bacon.rb +0 -86
  170. data/spec/helpers/mock_pry.rb +0 -43
  171. data/spec/helpers/table_spec.rb +0 -105
  172. data/spec/history_array_spec.rb +0 -67
  173. data/spec/hooks_spec.rb +0 -522
  174. data/spec/indent_spec.rb +0 -301
  175. data/spec/input_stack_spec.rb +0 -90
  176. data/spec/method_spec.rb +0 -482
  177. data/spec/prompt_spec.rb +0 -60
  178. data/spec/pry_defaults_spec.rb +0 -419
  179. data/spec/pry_history_spec.rb +0 -99
  180. data/spec/pry_output_spec.rb +0 -95
  181. data/spec/pry_spec.rb +0 -515
  182. data/spec/run_command_spec.rb +0 -25
  183. data/spec/sticky_locals_spec.rb +0 -157
  184. data/spec/syntax_checking_spec.rb +0 -81
  185. data/spec/wrapped_module_spec.rb +0 -261
  186. data/wiki/Customizing-pry.md +0 -397
  187. data/wiki/Home.md +0 -4
@@ -43,7 +43,7 @@ class Pry
43
43
  # Does not reload plugin if it's already active.
44
44
  def activate!
45
45
  # Create the configuration object for the plugin.
46
- Pry.config.send("#{gem_name.gsub('-', '_')}=", OpenStruct.new)
46
+ Pry.config.send("#{gem_name.gsub('-', '_')}=", Pry::Config.from_hash({}))
47
47
 
48
48
  begin
49
49
  require gem_name if !active?
@@ -0,0 +1,26 @@
1
+ class Pry::Prompt
2
+ MAP = {
3
+ "default" => {
4
+ value: Pry::DEFAULT_PROMPT,
5
+ description: "The default Pry prompt. Includes information about the\n" \
6
+ "current expression number, evaluation context, and nesting\n" \
7
+ "level, plus a reminder that you're using Pry."
8
+ },
9
+
10
+ "simple" => {
11
+ value: Pry::SIMPLE_PROMPT,
12
+ description: "A simple '>>'."
13
+ },
14
+
15
+ "nav" => {
16
+ value: Pry::NAV_PROMPT,
17
+ description: "A prompt that displays the binding stack as a path and\n" \
18
+ "includes information about _in_ and _out_."
19
+ },
20
+
21
+ "none" => {
22
+ value: Pry::NO_PROMPT,
23
+ description: "Wave goodbye to the Pry prompt."
24
+ }
25
+ }
26
+ end
@@ -1,93 +1,88 @@
1
- require 'ostruct'
2
- require 'forwardable'
3
1
  require 'pry/config'
4
-
5
2
  class Pry
6
3
 
7
- # The RC Files to load.
8
- HOME_RC_FILE = "~/.pryrc"
4
+ HOME_RC_FILE = ENV["PRYRC"] || "~/.pryrc"
9
5
  LOCAL_RC_FILE = "./.pryrc"
10
6
 
11
- # @return [Hash] Pry's `Thread.current` hash
12
- def self.current
13
- Thread.current[:__pry__] ||= {}
14
- end
15
-
16
- # class accessors
17
7
  class << self
18
8
  extend Forwardable
19
-
20
- # convenience method
21
- def self.delegate_accessors(delagatee, *names)
22
- def_delegators delagatee, *names
23
- def_delegators delagatee, *names.map { |v| "#{v}=" }
24
- end
25
-
26
- # Get/Set the Proc that defines extra Readline completions (on top
27
- # of the ones defined for IRB).
28
- # @return [Proc] The Proc that defines extra Readline completions (on top
29
- # @example Add file names to completion list
30
- # Pry.custom_completions = proc { Dir.entries('.') }
31
9
  attr_accessor :custom_completions
32
-
33
- # @return [Fixnum] The current input line.
34
10
  attr_accessor :current_line
35
-
36
- # @return [Array] The Array of evaluated expressions.
37
11
  attr_accessor :line_buffer
38
-
39
- # @return [String] The __FILE__ for the `eval()`. Should be "(pry)"
40
- # by default.
41
12
  attr_accessor :eval_path
42
-
43
- # @return [OpenStruct] Return Pry's config object.
13
+ attr_accessor :cli
14
+ attr_accessor :quiet
15
+ attr_accessor :last_internal_error
44
16
  attr_accessor :config
17
+ attr_writer :history
45
18
 
46
- # @return [History] Return Pry's line history object.
47
- attr_accessor :history
19
+ def_delegators :@plugin_manager, :plugins, :load_plugins, :locate_plugins
48
20
 
49
- # @return [Boolean] Whether Pry was activated from the command line.
50
- attr_accessor :cli
21
+ extend Pry::Config::Convenience
22
+ config_shortcut *Pry::Config.shortcuts
51
23
 
52
- # @return [Boolean] Whether Pry sessions are quiet by default.
53
- attr_accessor :quiet
24
+ def prompt=(value)
25
+ config.prompt = value
26
+ end
54
27
 
55
- # @return [Binding] A top level binding with no local variables
56
- attr_accessor :toplevel_binding
28
+ def prompt
29
+ config.prompt
30
+ end
57
31
 
58
- # @return [Exception, nil] The last pry internal error.
59
- # (a CommandError in most cases)
60
- attr_accessor :last_internal_error
32
+ def history
33
+ @history ||= History.new
34
+ end
35
+ end
61
36
 
62
- # plugin forwardables
63
- def_delegators :@plugin_manager, :plugins, :load_plugins, :locate_plugins
37
+ #
38
+ # @return [main]
39
+ # returns the special instance of Object, "main".
40
+ #
41
+ def self.main
42
+ @main ||= TOPLEVEL_BINDING.eval "self"
43
+ end
64
44
 
65
- delegate_accessors :@config, :input, :output, :commands, :prompt, :print, :exception_handler,
66
- :hooks, :color, :pager, :editor, :memory_size, :input_stack, :extra_sticky_locals
45
+ #
46
+ # @return [Pry::Config]
47
+ # Returns a value store for an instance of Pry running on the current thread.
48
+ #
49
+ def self.current
50
+ Thread.current[:__pry__] ||= Pry::Config.from_hash({}, nil)
67
51
  end
68
52
 
69
53
  # Load the given file in the context of `Pry.toplevel_binding`
70
- # @param [String] file_name The unexpanded file path.
71
- def self.load_file_at_toplevel(file_name)
72
- full_name = File.expand_path(file_name)
73
- begin
74
- toplevel_binding.eval(File.read(full_name), full_name) if File.exists?(full_name)
75
- rescue RescuableException => e
76
- puts "Error loading #{file_name}: #{e}\n#{e.backtrace.first}"
77
- end
54
+ # @param [String] file The unexpanded file path.
55
+ def self.load_file_at_toplevel(file)
56
+ toplevel_binding.eval(File.read(file), file)
57
+ rescue RescuableException => e
58
+ puts "Error loading #{file}: #{e}\n#{e.backtrace.first}"
78
59
  end
79
60
 
80
- # Load the rc files given in the `Pry::RC_FILES` array.
61
+ # Load HOME_RC_FILE and LOCAL_RC_FILE if appropriate
81
62
  # This method can also be used to reload the files if they have changed.
82
- def self.load_rc
83
- load_file_at_toplevel(HOME_RC_FILE)
63
+ def self.load_rc_files
64
+ rc_files_to_load.each do |file|
65
+ critical_section do
66
+ load_file_at_toplevel(file)
67
+ end
68
+ end
84
69
  end
85
70
 
86
71
  # Load the local RC file (./.pryrc)
87
- def self.load_local_rc
88
- unless File.expand_path(HOME_RC_FILE) == File.expand_path(LOCAL_RC_FILE)
89
- load_file_at_toplevel(LOCAL_RC_FILE)
90
- end
72
+ def self.rc_files_to_load
73
+ files = []
74
+ files << HOME_RC_FILE if Pry.config.should_load_rc
75
+ files << LOCAL_RC_FILE if Pry.config.should_load_local_rc
76
+ files.map { |file| real_path_to(file) }.compact.uniq
77
+ end
78
+
79
+ # Expand a file to its canonical name (following symlinks as appropriate)
80
+ def self.real_path_to(file)
81
+ expanded = Pathname.new(File.expand_path(file)).realpath.to_s
82
+ # For rbx 1.9 mode [see rubinius issue #2165]
83
+ File.exist?(expanded) ? expanded : nil
84
+ rescue Errno::ENOENT
85
+ nil
91
86
  end
92
87
 
93
88
  # Load any Ruby files specified with the -r flag on the command line.
@@ -103,26 +98,41 @@ class Pry
103
98
  trap('INT'){ raise Interrupt }
104
99
  end
105
100
 
101
+ def self.load_win32console
102
+ begin
103
+ require 'win32console'
104
+ # The mswin and mingw versions of pry require win32console, so this should
105
+ # only fail on jruby (where win32console doesn't work).
106
+ # Instead we'll recommend ansicon, which does.
107
+ rescue LoadError
108
+ warn <<-WARNING if Pry.config.windows_console_warning
109
+ For a better Pry experience on Windows, please use ansicon:
110
+ https://github.com/adoxa/ansicon
111
+ If you use an alternative to ansicon and don't want to see this warning again,
112
+ you can add "Pry.config.windows_console_warning = false" to your .pryrc.
113
+ WARNING
114
+ end
115
+ end
116
+
106
117
  # Do basic setup for initial session.
107
118
  # Including: loading .pryrc, loading plugins, loading requires, and
108
119
  # loading history.
109
120
  def self.initial_session_setup
110
121
  return unless initial_session?
122
+ @initial_session = false
111
123
 
112
124
  # note these have to be loaded here rather than in pry_instance as
113
125
  # we only want them loaded once per entire Pry lifetime.
114
- load_rc if Pry.config.should_load_rc
115
- load_local_rc if Pry.config.should_load_local_rc
126
+ load_rc_files
116
127
  load_plugins if Pry.config.should_load_plugins
117
128
  load_requires if Pry.config.should_load_requires
118
129
  load_history if Pry.config.history.should_load
119
130
  load_traps if Pry.config.should_trap_interrupts
120
-
121
- @initial_session = false
131
+ load_win32console if Pry::Helpers::BaseHelpers.windows? && !Pry::Helpers::BaseHelpers.windows_ansi?
122
132
  end
123
133
 
124
134
  # Start a Pry REPL.
125
- # This method also loads the ~/.pryrc and ./.pryrc as necessary
135
+ # This method also loads `~/.pryrc` and `./.pryrc` as necessary the
126
136
  # first time it is invoked.
127
137
  # @param [Object, Binding] target The receiver of the Pry session
128
138
  # @param [Hash] options
@@ -131,6 +141,7 @@ class Pry
131
141
  # Pry.start(Object.new, :input => MyInput.new)
132
142
  def self.start(target=nil, options={})
133
143
  return if ENV['DISABLE_PRY']
144
+ options = options.to_hash
134
145
 
135
146
  if in_critical_section?
136
147
  output.puts "ERROR: Pry started inside Pry."
@@ -138,35 +149,24 @@ class Pry
138
149
  return
139
150
  end
140
151
 
141
- target = Pry.binding_for(target || toplevel_binding)
152
+ options[:target] = Pry.binding_for(target || toplevel_binding)
153
+ options[:hooks] = Pry::Hooks.from_hash options.delete(:hooks) if options.key?(:hooks)
142
154
  initial_session_setup
143
155
 
144
- # create the Pry instance to manage the session
145
- pry_instance = new(options)
146
-
147
- # save backtrace
148
- pry_instance.backtrace = caller
156
+ # Unless we were given a backtrace, save the current one
157
+ if options[:backtrace].nil?
158
+ options[:backtrace] = caller
149
159
 
150
- # if Pry was started via binding.pry, elide that from the backtrace.
151
- pry_instance.backtrace.shift if pry_instance.backtrace.first =~ /pry.*core_extensions.*pry/
152
-
153
- # yield the binding_stack to the hook for modification
154
- pry_instance.exec_hook(:when_started, target, options, pry_instance)
155
-
156
- if !pry_instance.binding_stack.empty?
157
- head = pry_instance.binding_stack.pop
158
- else
159
- head = target
160
+ # If Pry was started via `binding.pry`, elide that from the backtrace
161
+ if options[:backtrace].first =~ /pry.*core_extensions.*pry/
162
+ options[:backtrace].shift
163
+ end
160
164
  end
161
165
 
162
- # Clear the line before starting Pry. This fixes the issue discussed here:
163
- # https://github.com/pry/pry/issues/566
164
- if Pry.config.auto_indent
165
- Kernel.print Pry::Helpers::BaseHelpers.windows_ansi? ? "\e[0F" : "\e[0G"
166
- end
166
+ driver = options[:driver] || Pry::REPL
167
167
 
168
168
  # Enter the matrix
169
- pry_instance.repl(head)
169
+ driver.start(options)
170
170
  rescue Pry::TooSafeException
171
171
  puts "ERROR: Pry cannot work with $SAFE > 0"
172
172
  raise
@@ -179,23 +179,40 @@ class Pry
179
179
  REPLFileLoader.new(file_name).load
180
180
  end
181
181
 
182
+ #
182
183
  # An inspector that clips the output to `max_length` chars.
183
184
  # In case of > `max_length` chars the `#<Object...> notation is used.
184
- # @param obj The object to view.
185
- # @param max_length The maximum number of chars before clipping occurs.
186
- # @return [String] The string representation of `obj`.
187
- def self.view_clip(obj, max_length = 60)
188
- if obj.kind_of?(Module) && obj.name.to_s != "" && obj.name.to_s.length <= max_length
185
+ #
186
+ # @param [Object] obj
187
+ # The object to view.
188
+ #
189
+ # @param [Hash] options
190
+ # @option options [Integer] :max_length (60)
191
+ # The maximum number of chars before clipping occurs.
192
+ #
193
+ # @option options [Boolean] :id (false)
194
+ # Boolean to indicate whether or not a hex reprsentation of the object ID
195
+ # is attached to the return value when the length of inspect is greater than
196
+ # value of `:max_length`.
197
+ #
198
+ # @return [String]
199
+ # The string representation of `obj`.
200
+ #
201
+ def self.view_clip(obj, options = {})
202
+ max = options.fetch :max_length, 60
203
+ id = options.fetch :id, false
204
+ if obj.kind_of?(Module) && obj.name.to_s != "" && obj.name.to_s.length <= max
189
205
  obj.name.to_s
190
- elsif TOPLEVEL_BINDING.eval('self') == obj
191
- # special case for 'main' object :)
206
+ elsif Pry.main == obj
207
+ # special-case to support jruby.
208
+ # fixed as of https://github.com/jruby/jruby/commit/d365ebd309cf9df3dde28f5eb36ea97056e0c039
209
+ # we can drop in the future.
192
210
  obj.to_s
193
- elsif [String, Numeric, Symbol, nil, true, false].any? { |v| v === obj } && obj.inspect.length <= max_length
211
+ elsif Pry.config.prompt_safe_objects.any? { |v| v === obj } && obj.inspect.length <= max
194
212
  obj.inspect
195
213
  else
196
- "#<#{obj.class}>"#:%x>"# % (obj.object_id << 1)
214
+ id == true ? "#<#{obj.class}:0x%x>" % (obj.object_id << 1) : "#<#{obj.class}>"
197
215
  end
198
-
199
216
  rescue RescuableException
200
217
  "unknown"
201
218
  end
@@ -205,11 +222,6 @@ class Pry
205
222
  Pry.history.load
206
223
  end
207
224
 
208
- # Save new lines of Readline history if required.
209
- def self.save_history
210
- Pry.history.save
211
- end
212
-
213
225
  # @return [Boolean] Whether this is the first time a Pry session has
214
226
  # been started since loading the Pry class.
215
227
  def self.initial_session?
@@ -217,40 +229,40 @@ class Pry
217
229
  end
218
230
 
219
231
  # Run a Pry command from outside a session. The commands available are
220
- # those referenced by `Pry.commands` (the default command set).
232
+ # those referenced by `Pry.config.commands` (the default command set).
221
233
  # @param [String] command_string The Pry command (including arguments,
222
234
  # if any).
223
235
  # @param [Hash] options Optional named parameters.
224
236
  # @return [Object] The return value of the Pry command.
225
- # @option options [Object, Binding] :context The object context to run the
237
+ # @option options [Object, Binding] :target The object to run the
226
238
  # command under. Defaults to `TOPLEVEL_BINDING` (main).
227
239
  # @option options [Boolean] :show_output Whether to show command
228
240
  # output. Defaults to true.
229
241
  # @example Run at top-level with no output.
230
242
  # Pry.run_command "ls"
231
243
  # @example Run under Pry class, returning only public methods.
232
- # Pry.run_command "ls -m", :context => Pry
244
+ # Pry.run_command "ls -m", :target => Pry
233
245
  # @example Display command output.
234
246
  # Pry.run_command "ls -av", :show_output => true
235
247
  def self.run_command(command_string, options={})
236
248
  options = {
237
- :context => TOPLEVEL_BINDING,
249
+ :target => TOPLEVEL_BINDING,
238
250
  :show_output => true,
239
- :output => Pry.output,
240
- :commands => Pry.commands
251
+ :output => Pry.config.output,
252
+ :commands => Pry.config.commands
241
253
  }.merge!(options)
242
254
 
255
+ # :context for compatibility with <= 0.9.11.4
256
+ target = options[:context] || options[:target]
243
257
  output = options[:show_output] ? options[:output] : StringIO.new
244
258
 
245
- Pry.new(:output => output, :input => StringIO.new("#{command_string}\nexit-all\n"),
246
- :commands => options[:commands],
247
- :prompt => proc {""}, :hooks => Pry::Hooks.new).repl(options[:context])
259
+ pry = Pry.new(:output => output, :target => target, :commands => options[:commands])
260
+ pry.eval command_string
248
261
  end
249
262
 
250
263
  def self.default_editor_for_platform
251
264
  return ENV['VISUAL'] if ENV['VISUAL'] and not ENV['VISUAL'].empty?
252
265
  return ENV['EDITOR'] if ENV['EDITOR'] and not ENV['EDITOR'].empty?
253
-
254
266
  if Helpers::BaseHelpers.windows?
255
267
  'notepad'
256
268
  else
@@ -261,19 +273,25 @@ class Pry
261
273
  end
262
274
 
263
275
  def self.auto_resize!
264
- Pry.require_readline
265
- ver = Readline::VERSION
266
- if ver[/edit/i]
276
+ Pry.config.input # by default, load Readline
277
+
278
+ if !defined?(Readline) || Pry.config.input != Readline
279
+ warn "Sorry, you must be using Readline for Pry.auto_resize! to work."
280
+ return
281
+ end
282
+
283
+ if Readline::VERSION =~ /edit/i
267
284
  warn <<-EOT
268
- Readline version #{ver} detected - will not auto_resize! correctly.
285
+ Readline version #{Readline::VERSION} detected - will not auto_resize! correctly.
269
286
  For the fix, use GNU Readline instead:
270
287
  https://github.com/guard/guard/wiki/Add-proper-Readline-support-to-Ruby-on-Mac-OS-X
271
288
  EOT
272
289
  return
273
290
  end
291
+
274
292
  trap :WINCH do
275
293
  begin
276
- Readline.set_screen_size *Terminal.size!
294
+ Readline.set_screen_size(*Terminal.size!)
277
295
  rescue => e
278
296
  warn "\nPry.auto_resize!'s Readline.set_screen_size failed: #{e}"
279
297
  end
@@ -285,124 +303,19 @@ Readline version #{ver} detected - will not auto_resize! correctly.
285
303
  end
286
304
  end
287
305
 
288
- def self.set_config_defaults
289
- config.input = proc { Pry.require_readline; Readline }
290
- config.output = $stdout
291
- config.commands = Pry::Commands
292
- config.prompt_name = DEFAULT_PROMPT_NAME
293
- config.prompt = DEFAULT_PROMPT
294
- config.print = DEFAULT_PRINT
295
- config.exception_handler = DEFAULT_EXCEPTION_HANDLER
296
- config.exception_whitelist = DEFAULT_EXCEPTION_WHITELIST
297
- config.default_window_size = 5
298
- config.hooks = DEFAULT_HOOKS
299
- config.input_stack = []
300
- config.color = Helpers::BaseHelpers.use_ansi_codes?
301
- config.pager = true
302
- config.system = DEFAULT_SYSTEM
303
- config.editor = default_editor_for_platform
304
- config.should_load_rc = true
305
- config.should_load_local_rc = true
306
- config.should_trap_interrupts = Helpers::BaseHelpers.jruby?
307
- config.disable_auto_reload = false
308
- config.command_prefix = ""
309
- config.auto_indent = Helpers::BaseHelpers.use_ansi_codes?
310
- config.correct_indent = true
311
- config.collision_warning = false
312
- config.output_prefix = "=> "
313
- config.completer = Pry::BondCompleter
314
-
315
- config.gist ||= OpenStruct.new
316
- config.gist.inspecter = proc(&:pretty_inspect)
317
-
318
- config.should_load_plugins = true
319
-
320
- config.requires ||= []
321
- config.should_load_requires = true
322
-
323
- config.history ||= OpenStruct.new
324
- config.history.should_save = true
325
- config.history.should_load = true
326
- config.history.file = File.expand_path("~/.pry_history") rescue nil
327
-
328
- if config.history.file.nil?
329
- config.should_load_rc = false
330
- config.history.should_save = false
331
- config.history.should_load = false
332
- end
333
-
334
- config.control_d_handler = DEFAULT_CONTROL_D_HANDLER
335
-
336
- config.memory_size = 100
337
-
338
- config.extra_sticky_locals = {}
339
-
340
- config.ls ||= OpenStruct.new({
341
- :heading_color => :bright_blue,
342
-
343
- :public_method_color => :default,
344
- :private_method_color => :blue,
345
- :protected_method_color => :blue,
346
- :method_missing_color => :bright_red,
347
-
348
- :local_var_color => :yellow,
349
- :pry_var_color => :default, # e.g. _, _pry_, _file_
350
-
351
- :instance_var_color => :blue, # e.g. @foo
352
- :class_var_color => :bright_blue, # e.g. @@foo
353
-
354
- :global_var_color => :default, # e.g. $CODERAY_DEBUG, $eventmachine_library
355
- :builtin_global_color => :cyan, # e.g. $stdin, $-w, $PID
356
- :pseudo_global_color => :cyan, # e.g. $~, $1..$9, $LAST_MATCH_INFO
357
-
358
- :constant_color => :default, # e.g. VERSION, ARGF
359
- :class_constant_color => :blue, # e.g. Object, Kernel
360
- :exception_constant_color => :magenta, # e.g. Exception, RuntimeError
361
- :unloaded_constant_color => :yellow, # Any constant that is still in .autoload? state
362
-
363
- # What should separate items listed by ls? (TODO: we should allow a columnar layout)
364
- :separator => " ",
365
-
366
- # Any methods defined on these classes, or modules included into these classes, will not
367
- # be shown by ls unless the -v flag is used.
368
- # A user of Rails may wih to add ActiveRecord::Base to the list.
369
- # add the following to your .pryrc:
370
- # Pry.config.ls.ceiling << ActiveRecord::Base if defined? ActiveRecordBase
371
- :ceiling => [Object, Module, Class]
372
- })
373
- end
374
-
375
306
  # Set all the configurable options back to their default values
376
307
  def self.reset_defaults
377
- set_config_defaults
378
-
379
308
  @initial_session = true
380
-
381
- self.custom_completions = DEFAULT_CUSTOM_COMPLETIONS
309
+ self.config = Pry::Config.new Pry::Config::Default.new
382
310
  self.cli = false
383
311
  self.current_line = 1
384
312
  self.line_buffer = [""]
385
313
  self.eval_path = "(pry)"
386
-
387
- fix_coderay_colors
388
- end
389
-
390
- # To avoid mass-confusion, we change the default colour of "white" to
391
- # "blue" enabling global legibility
392
- def self.fix_coderay_colors
393
- colors = CodeRay::Encoders::Terminal::TOKEN_COLORS
394
-
395
- if colors[:comment].is_a?(String)
396
- colors[:comment] = "0;34"
397
- end
398
314
  end
399
315
 
400
316
  # Basic initialization.
401
317
  def self.init
402
318
  @plugin_manager ||= PluginManager.new
403
- self.config ||= Config.new
404
- self.history ||= History.new
405
-
406
319
  reset_defaults
407
320
  locate_plugins
408
321
  end
@@ -416,7 +329,7 @@ Readline version #{ver} detected - will not auto_resize! correctly.
416
329
  if Binding === target
417
330
  target
418
331
  else
419
- if TOPLEVEL_BINDING.eval('self') == target
332
+ if Pry.main == target
420
333
  TOPLEVEL_BINDING
421
334
  else
422
335
  target.__binding__
@@ -425,7 +338,7 @@ Readline version #{ver} detected - will not auto_resize! correctly.
425
338
  end
426
339
 
427
340
  def self.toplevel_binding
428
- unless @toplevel_binding
341
+ unless defined?(@toplevel_binding) && @toplevel_binding
429
342
  # Grab a copy of the TOPLEVEL_BINDING without any local variables.
430
343
  # This binding has a default definee of Object, and new methods are
431
344
  # private (just as in TOPLEVEL_BINDING).
@@ -441,15 +354,21 @@ Readline version #{ver} detected - will not auto_resize! correctly.
441
354
  @toplevel_binding
442
355
  end
443
356
 
357
+ def self.toplevel_binding=(binding)
358
+ @toplevel_binding = binding
359
+ end
360
+
444
361
  def self.in_critical_section?
445
- @critical_section.to_i > 0
362
+ Thread.current[:pry_critical_section] ||= 0
363
+ Thread.current[:pry_critical_section] > 0
446
364
  end
447
365
 
448
366
  def self.critical_section(&block)
449
- @critical_section = @critical_section.to_i + 1
367
+ Thread.current[:pry_critical_section] ||= 0
368
+ Thread.current[:pry_critical_section] += 1
450
369
  yield
451
370
  ensure
452
- @critical_section -= 1
371
+ Thread.current[:pry_critical_section] -= 1
453
372
  end
454
373
  end
455
374