pry 0.9.12.2 → 0.14.2

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.
Files changed (237) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +1141 -0
  3. data/LICENSE +2 -2
  4. data/README.md +466 -0
  5. data/bin/pry +4 -7
  6. data/lib/pry/basic_object.rb +10 -0
  7. data/lib/pry/block_command.rb +22 -0
  8. data/lib/pry/class_command.rb +194 -0
  9. data/lib/pry/cli.rb +97 -92
  10. data/lib/pry/code/code_file.rb +114 -0
  11. data/lib/pry/code/code_range.rb +7 -4
  12. data/lib/pry/code/loc.rb +27 -14
  13. data/lib/pry/code.rb +62 -90
  14. data/lib/pry/code_object.rb +83 -39
  15. data/lib/pry/color_printer.rb +66 -0
  16. data/lib/pry/command.rb +202 -371
  17. data/lib/pry/command_set.rb +151 -133
  18. data/lib/pry/command_state.rb +31 -0
  19. data/lib/pry/commands/amend_line.rb +86 -82
  20. data/lib/pry/commands/bang.rb +18 -14
  21. data/lib/pry/commands/bang_pry.rb +15 -11
  22. data/lib/pry/commands/cat/abstract_formatter.rb +23 -18
  23. data/lib/pry/commands/cat/exception_formatter.rb +85 -73
  24. data/lib/pry/commands/cat/file_formatter.rb +56 -63
  25. data/lib/pry/commands/cat/input_expression_formatter.rb +35 -30
  26. data/lib/pry/commands/cat.rb +64 -47
  27. data/lib/pry/commands/cd.rb +42 -26
  28. data/lib/pry/commands/change_inspector.rb +34 -0
  29. data/lib/pry/commands/change_prompt.rb +51 -0
  30. data/lib/pry/commands/clear_screen.rb +20 -0
  31. data/lib/pry/commands/code_collector.rb +148 -131
  32. data/lib/pry/commands/disable_pry.rb +23 -19
  33. data/lib/pry/commands/easter_eggs.rb +23 -34
  34. data/lib/pry/commands/edit/exception_patcher.rb +21 -17
  35. data/lib/pry/commands/edit/file_and_line_locator.rb +33 -24
  36. data/lib/pry/commands/edit.rb +183 -167
  37. data/lib/pry/commands/exit.rb +40 -35
  38. data/lib/pry/commands/exit_all.rb +24 -20
  39. data/lib/pry/commands/exit_program.rb +20 -17
  40. data/lib/pry/commands/find_method.rb +167 -167
  41. data/lib/pry/commands/fix_indent.rb +16 -12
  42. data/lib/pry/commands/help.rb +140 -133
  43. data/lib/pry/commands/hist.rb +153 -132
  44. data/lib/pry/commands/import_set.rb +20 -15
  45. data/lib/pry/commands/jump_to.rb +25 -21
  46. data/lib/pry/commands/list_inspectors.rb +42 -0
  47. data/lib/pry/commands/ls/constants.rb +75 -0
  48. data/lib/pry/commands/ls/formatter.rb +55 -0
  49. data/lib/pry/commands/ls/globals.rb +50 -0
  50. data/lib/pry/commands/ls/grep.rb +23 -0
  51. data/lib/pry/commands/ls/instance_vars.rb +40 -0
  52. data/lib/pry/commands/ls/interrogatable.rb +24 -0
  53. data/lib/pry/commands/ls/jruby_hacks.rb +55 -0
  54. data/lib/pry/commands/ls/local_names.rb +37 -0
  55. data/lib/pry/commands/ls/local_vars.rb +47 -0
  56. data/lib/pry/commands/ls/ls_entity.rb +65 -0
  57. data/lib/pry/commands/ls/methods.rb +55 -0
  58. data/lib/pry/commands/ls/methods_helper.rb +50 -0
  59. data/lib/pry/commands/ls/self_methods.rb +34 -0
  60. data/lib/pry/commands/ls.rb +100 -303
  61. data/lib/pry/commands/nesting.rb +21 -17
  62. data/lib/pry/commands/play.rb +93 -49
  63. data/lib/pry/commands/pry_backtrace.rb +22 -18
  64. data/lib/pry/commands/pry_version.rb +15 -11
  65. data/lib/pry/commands/raise_up.rb +33 -27
  66. data/lib/pry/commands/reload_code.rb +57 -48
  67. data/lib/pry/commands/reset.rb +16 -12
  68. data/lib/pry/commands/ri.rb +57 -38
  69. data/lib/pry/commands/save_file.rb +45 -43
  70. data/lib/pry/commands/shell_command.rb +66 -34
  71. data/lib/pry/commands/shell_mode.rb +22 -20
  72. data/lib/pry/commands/show_doc.rb +80 -65
  73. data/lib/pry/commands/show_info.rb +193 -159
  74. data/lib/pry/commands/show_input.rb +16 -11
  75. data/lib/pry/commands/show_source.rb +113 -33
  76. data/lib/pry/commands/stat.rb +35 -31
  77. data/lib/pry/commands/switch_to.rb +21 -15
  78. data/lib/pry/commands/toggle_color.rb +21 -13
  79. data/lib/pry/commands/watch_expression/expression.rb +43 -0
  80. data/lib/pry/commands/watch_expression.rb +110 -0
  81. data/lib/pry/commands/whereami.rb +157 -134
  82. data/lib/pry/commands/wtf.rb +78 -40
  83. data/lib/pry/config/attributable.rb +22 -0
  84. data/lib/pry/config/lazy_value.rb +29 -0
  85. data/lib/pry/config/memoized_value.rb +34 -0
  86. data/lib/pry/config/value.rb +24 -0
  87. data/lib/pry/config.rb +290 -220
  88. data/lib/pry/control_d_handler.rb +28 -0
  89. data/lib/pry/core_extensions.rb +50 -27
  90. data/lib/pry/editor.rb +130 -102
  91. data/lib/pry/env.rb +18 -0
  92. data/lib/pry/exception_handler.rb +43 -0
  93. data/lib/pry/exceptions.rb +73 -0
  94. data/lib/pry/forwardable.rb +27 -0
  95. data/lib/pry/helpers/base_helpers.rb +22 -151
  96. data/lib/pry/helpers/command_helpers.rb +55 -63
  97. data/lib/pry/helpers/documentation_helpers.rb +21 -13
  98. data/lib/pry/helpers/options_helpers.rb +15 -8
  99. data/lib/pry/helpers/platform.rb +55 -0
  100. data/lib/pry/helpers/table.rb +44 -32
  101. data/lib/pry/helpers/text.rb +96 -86
  102. data/lib/pry/helpers.rb +3 -0
  103. data/lib/pry/history.rb +101 -70
  104. data/lib/pry/hooks.rb +67 -137
  105. data/lib/pry/indent.rb +79 -73
  106. data/lib/pry/input_completer.rb +283 -0
  107. data/lib/pry/input_lock.rb +129 -0
  108. data/lib/pry/inspector.rb +39 -0
  109. data/lib/pry/last_exception.rb +61 -0
  110. data/lib/pry/method/disowned.rb +19 -5
  111. data/lib/pry/{commands/edit/method_patcher.rb → method/patcher.rb} +51 -42
  112. data/lib/pry/method/weird_method_locator.rb +80 -44
  113. data/lib/pry/method.rb +225 -176
  114. data/lib/pry/object_path.rb +91 -0
  115. data/lib/pry/output.rb +136 -0
  116. data/lib/pry/pager.rb +227 -68
  117. data/lib/pry/prompt.rb +214 -0
  118. data/lib/pry/pry_class.rb +216 -289
  119. data/lib/pry/pry_instance.rb +438 -500
  120. data/lib/pry/repl.rb +256 -0
  121. data/lib/pry/repl_file_loader.rb +34 -35
  122. data/lib/pry/ring.rb +89 -0
  123. data/lib/pry/slop/LICENSE +20 -0
  124. data/lib/pry/slop/commands.rb +190 -0
  125. data/lib/pry/slop/option.rb +210 -0
  126. data/lib/pry/slop.rb +672 -0
  127. data/lib/pry/syntax_highlighter.rb +26 -0
  128. data/lib/pry/system_command_handler.rb +17 -0
  129. data/lib/pry/testable/evalable.rb +24 -0
  130. data/lib/pry/testable/mockable.rb +22 -0
  131. data/lib/pry/testable/pry_tester.rb +88 -0
  132. data/lib/pry/testable/utility.rb +34 -0
  133. data/lib/pry/testable/variables.rb +52 -0
  134. data/lib/pry/testable.rb +68 -0
  135. data/lib/pry/version.rb +3 -1
  136. data/lib/pry/warning.rb +20 -0
  137. data/lib/pry/{module_candidate.rb → wrapped_module/candidate.rb} +36 -43
  138. data/lib/pry/wrapped_module.rb +102 -103
  139. data/lib/pry.rb +135 -261
  140. metadata +94 -283
  141. data/.document +0 -2
  142. data/.gitignore +0 -16
  143. data/.travis.yml +0 -21
  144. data/.yardopts +0 -1
  145. data/CHANGELOG +0 -534
  146. data/CONTRIBUTORS +0 -55
  147. data/Gemfile +0 -9
  148. data/Guardfile +0 -62
  149. data/README.markdown +0 -400
  150. data/Rakefile +0 -140
  151. data/TODO +0 -117
  152. data/lib/pry/commands/disabled_commands.rb +0 -2
  153. data/lib/pry/commands/gem_cd.rb +0 -26
  154. data/lib/pry/commands/gem_install.rb +0 -29
  155. data/lib/pry/commands/gem_list.rb +0 -33
  156. data/lib/pry/commands/gem_open.rb +0 -29
  157. data/lib/pry/commands/gist.rb +0 -102
  158. data/lib/pry/commands/install_command.rb +0 -51
  159. data/lib/pry/commands/simple_prompt.rb +0 -22
  160. data/lib/pry/commands.rb +0 -6
  161. data/lib/pry/completion.rb +0 -304
  162. data/lib/pry/custom_completions.rb +0 -6
  163. data/lib/pry/history_array.rb +0 -116
  164. data/lib/pry/plugins.rb +0 -103
  165. data/lib/pry/rbx_method.rb +0 -13
  166. data/lib/pry/rbx_path.rb +0 -22
  167. data/lib/pry/rubygem.rb +0 -74
  168. data/lib/pry/terminal.rb +0 -78
  169. data/lib/pry/test/helper.rb +0 -185
  170. data/man/pry.1 +0 -195
  171. data/man/pry.1.html +0 -204
  172. data/man/pry.1.ronn +0 -141
  173. data/pry.gemspec +0 -30
  174. data/spec/Procfile +0 -3
  175. data/spec/cli_spec.rb +0 -78
  176. data/spec/code_object_spec.rb +0 -277
  177. data/spec/code_spec.rb +0 -219
  178. data/spec/command_helpers_spec.rb +0 -29
  179. data/spec/command_integration_spec.rb +0 -644
  180. data/spec/command_set_spec.rb +0 -627
  181. data/spec/command_spec.rb +0 -821
  182. data/spec/commands/amend_line_spec.rb +0 -247
  183. data/spec/commands/bang_spec.rb +0 -19
  184. data/spec/commands/cat_spec.rb +0 -164
  185. data/spec/commands/cd_spec.rb +0 -250
  186. data/spec/commands/disable_pry_spec.rb +0 -25
  187. data/spec/commands/edit_spec.rb +0 -727
  188. data/spec/commands/exit_all_spec.rb +0 -34
  189. data/spec/commands/exit_program_spec.rb +0 -19
  190. data/spec/commands/exit_spec.rb +0 -34
  191. data/spec/commands/find_method_spec.rb +0 -70
  192. data/spec/commands/gem_list_spec.rb +0 -26
  193. data/spec/commands/gist_spec.rb +0 -79
  194. data/spec/commands/help_spec.rb +0 -56
  195. data/spec/commands/hist_spec.rb +0 -181
  196. data/spec/commands/jump_to_spec.rb +0 -15
  197. data/spec/commands/ls_spec.rb +0 -181
  198. data/spec/commands/play_spec.rb +0 -140
  199. data/spec/commands/raise_up_spec.rb +0 -56
  200. data/spec/commands/save_file_spec.rb +0 -177
  201. data/spec/commands/show_doc_spec.rb +0 -510
  202. data/spec/commands/show_input_spec.rb +0 -17
  203. data/spec/commands/show_source_spec.rb +0 -782
  204. data/spec/commands/whereami_spec.rb +0 -203
  205. data/spec/completion_spec.rb +0 -239
  206. data/spec/control_d_handler_spec.rb +0 -58
  207. data/spec/documentation_helper_spec.rb +0 -73
  208. data/spec/editor_spec.rb +0 -79
  209. data/spec/exception_whitelist_spec.rb +0 -21
  210. data/spec/fixtures/candidate_helper1.rb +0 -11
  211. data/spec/fixtures/candidate_helper2.rb +0 -8
  212. data/spec/fixtures/example.erb +0 -5
  213. data/spec/fixtures/example_nesting.rb +0 -33
  214. data/spec/fixtures/show_source_doc_examples.rb +0 -15
  215. data/spec/fixtures/testrc +0 -2
  216. data/spec/fixtures/testrcbad +0 -2
  217. data/spec/fixtures/whereami_helper.rb +0 -6
  218. data/spec/helper.rb +0 -34
  219. data/spec/helpers/bacon.rb +0 -86
  220. data/spec/helpers/mock_pry.rb +0 -43
  221. data/spec/helpers/table_spec.rb +0 -105
  222. data/spec/history_array_spec.rb +0 -67
  223. data/spec/hooks_spec.rb +0 -522
  224. data/spec/indent_spec.rb +0 -301
  225. data/spec/input_stack_spec.rb +0 -90
  226. data/spec/method_spec.rb +0 -482
  227. data/spec/prompt_spec.rb +0 -60
  228. data/spec/pry_defaults_spec.rb +0 -419
  229. data/spec/pry_history_spec.rb +0 -99
  230. data/spec/pry_output_spec.rb +0 -95
  231. data/spec/pry_spec.rb +0 -504
  232. data/spec/run_command_spec.rb +0 -25
  233. data/spec/sticky_locals_spec.rb +0 -157
  234. data/spec/syntax_checking_spec.rb +0 -81
  235. data/spec/wrapped_module_spec.rb +0 -261
  236. data/wiki/Customizing-pry.md +0 -397
  237. data/wiki/Home.md +0 -4
data/lib/pry/config.rb CHANGED
@@ -1,244 +1,314 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ostruct'
2
4
 
3
5
  class Pry
4
- class Config < OpenStruct
5
-
6
- # Get/Set the object to use for input by default by all Pry instances.
7
- # Pry.config.input is an option determining the input object - the object from
8
- # which Pry retrieves its lines of input. Pry accepts any object that implements the readline method.
9
- # This includes IO objects, StringIO, Readline, File and custom objects.
10
- # @return [#readline] The object to use for input by default by all
11
- # Pry instances.
12
- # @example
13
- # Pry.config.input = StringIO.new("@x = 10\nexit")
14
- attr_accessor :input
15
-
16
- # Get/Set the object to use for output by default by all Pry instances.
17
- # Pry.config.output is an option determining the output object - the object to which
18
- # Pry writes its output. Pry accepts any object that implements the puts method. This
19
- # includes IO objects, StringIO, File and custom objects.
20
- # @return [#puts] The object to use for output by default by all
21
- # Pry instances.
22
- # @example
23
- # Pry.config.output = StringIO.new
24
- attr_accessor :output
25
-
26
- # Get/Set the object to use for commands by default by all Pry instances.
27
- # @return [Pry::CommandBase] The object to use for commands by default by all
28
- # Pry instances.
29
- # @example
30
- # Pry.config.commands = Pry::CommandSet.new do
31
- # import_from Pry::Commands, "ls"
32
- #
33
- # command "greet" do |name|
34
- # output.puts "hello #{name}"
35
- # end
36
- # end
37
- attr_accessor :commands
38
-
39
- # Get/Set the Proc to use for printing by default by all Pry
40
- # instances.
41
- # Two parameters are passed to the print Proc: these are (1) the
42
- # output object for the current session and (2) the expression value to print. It is important
43
- # that you write to the output object instead of just stdout so that all Pry output can be redirected if necessary.
44
- # This is the 'print' component of the REPL.
45
- # @return [Proc] The Proc to use for printing by default by all
46
- # Pry instances.
47
- # @example
48
- # Pry.config.print = proc { |output, value| output.puts "=> #{value.inspect}" }
49
- attr_accessor :print
50
-
51
- # Pry.config.exception_handler is an option determining the exception handler object - the
52
- # Proc responsible for dealing with exceptions raised by user input to the REPL.
53
- # Three parameters are passed to the exception handler Proc: these
54
- # are (1) the output object for the current session, (2) the
55
- # exception object that was raised inside the Pry session, and (3)
56
- # a reference to the associated Pry instance.
57
- # @return [Proc] The Proc to use for printing exceptions by default by all
58
- # Pry instances.
59
- # @example
60
- # Pry.config.exception_handler = proc do |output, exception, _|
61
- # output.puts "#{exception.class}: #{exception.message}"
62
- # output.puts "from #{exception.backtrace.first}"
63
- # end
64
- attr_accessor :exception_handler
65
-
66
- # @return [Array] The classes of exception that will not be caught by Pry.
67
- # @example
68
- # Pry.config.exception_whitelist = [SystemExit, SignalException]
69
- attr_accessor :exception_whitelist
70
-
71
- # @return [Fixnum] The number of lines of context to show before and after
72
- # exceptions, etc.
73
- # @example
74
- # Pry.config.default_window_size = 10
75
- attr_accessor :default_window_size
76
-
77
- # Get/Set the `Pry::Hooks` instance that defines Pry hooks used by default by all Pry
78
- # instances.
79
- # @return [Pry::Hooks] The hooks used by default by all Pry instances.
80
- # @example
81
- # Pry.config.hooks = Pry::Hooks.new.add_hook(:before_session,
82
- # :default) { |output, target, _pry_| output.puts "Good morning!" }
83
- attr_reader :hooks
84
-
85
- # FIXME:
86
- # This is a hack to alert people of the new API.
87
- # @param [Pry::Hooks] v Only accept `Pry::Hooks` now!
88
- def hooks=(v)
89
- if v.is_a?(Hash)
90
- warn "Hash-based hooks are now deprecated! Use a `Pry::Hooks` object instead! http://rubydoc.info/github/pry/pry/master/Pry/Hooks"
91
- @hooks = Pry::Hooks.from_hash(v)
92
- else
93
- @hooks = v
94
- end
95
- end
6
+ # @api private
7
+ class Config
8
+ extend Attributable
96
9
 
97
- # Get/Set the stack of input objects that a Pry instance switches
98
- # to when its current input object encounters EOF.
99
- # @return [Array] The array of input objects.
100
- # @example
101
- # Pry.config.input_stack = [StringIO.new("puts 'hello world'\nexit")]
102
- attr_accessor :input_stack
103
-
104
- # Get the array of Procs (or single Proc) to be used for the prompts by default by
105
- # all Pry instances.
106
- # Three parameters are passed into the prompt procs, (1) the
107
- # object that is the target of the session, (2) the current
108
- # nesting level, and (3) a reference to the associated Pry instance. These objects can be used in the prompt, if desired.
109
- # @return [Array<Proc>, Proc] The array of Procs to be used for the
110
- # prompts by default by all Pry instances.
111
- # @example
112
- # Pry.config.prompt = proc { |obj, nest_level, _pry_| "#{obj}:#{nest_level}> " }
113
- attr_accessor :prompt
114
-
115
- # The display name that is part of the prompt. Default is 'pry'.
116
- # You can set your own name so you can identify which project your current pry session
117
- # is using. This is useful if you have a local pryrc file in a Rails project for example.
118
- # @return [String]
119
- # @example
120
- # Pry.config.prompt_name = 'my_rails_project'
121
- attr_accessor :prompt_name
122
-
123
- # The default editor to use. Defaults to $VISUAL, $EDITOR, or a sensible fallback
124
- # for the platform.
125
- # If `editor` is a String then that string is used as the shell
126
- # command to invoke the editor. If `editor` is callable (e.g a
127
- # Proc) then `file`, `line`, and `reloading` are passed in as parameters and the
128
- # return value of that callable invocation is used as the exact
129
- # shell command to invoke the editor. `reloading` indicates whether Pry will be
130
- # reloading code after the shell command returns. Any or all of these parameters
131
- # can be omitted from the callable's signature.
132
- # @example String
133
- # Pry.config.editor = "emacsclient"
134
- # @example Callable
135
- # Pry.config.editor = proc { |file, line| "emacsclient #{file} +#{line}" }
136
- # @example Callable waiting only if reloading
137
- # Pry.config.editor = proc { |file, line, reloading| "subl #{'--wait' if reloading} #{file}:#{line}" }
10
+ # @return [IO, #readline] he object from which Pry retrieves its lines of
11
+ # input
12
+ attribute :input
13
+
14
+ # @return [IO, #puts] where Pry should output results provided by {input}
15
+ attribute :output
16
+
17
+ # @return [Pry::CommandSet]
18
+ attribute :commands
19
+
20
+ # @return [Proc] the printer for Ruby expressions (not commands)
21
+ attribute :print
22
+
23
+ # @return [Proc] the printer for exceptions
24
+ attribute :exception_handler
25
+
26
+ # @return [Array] Exception that Pry shouldn't rescue
27
+ attribute :unrescued_exceptions
28
+
29
+ # @deprecated
30
+ # @return [Array] Exception that Pry shouldn't rescue
31
+ attribute :exception_whitelist
32
+
33
+ # @return [Integer] The number of lines of context to show before and after
34
+ # exceptions
35
+ attribute :default_window_size
36
+
37
+ # @return [Pry::Hooks]
38
+ attribute :hooks
39
+
40
+ # @return [Pry::Prompt]
41
+ attribute :prompt
42
+
43
+ # @return [String] The display name that is part of the prompt
44
+ attribute :prompt_name
45
+
46
+ # @return [Array<Object>] the list of objects that are known to have a
47
+ # 1-line #inspect output suitable for prompt
48
+ attribute :prompt_safe_contexts
49
+
50
+ # If it is a String, then that String is used as the shell
51
+ # command to invoke the editor.
52
+ #
53
+ # If it responds to #call is callable then `file`, `line`, and `reloading`
54
+ # are passed to it. `reloading` indicates whether Pry will be reloading code
55
+ # after the shell command returns. All parameters are optional.
138
56
  # @return [String, #call]
139
- attr_accessor :editor
57
+ attribute :editor
140
58
 
141
- # A string that must precede all Pry commands (e.g., if command_prefix is
59
+ # A string that must precede all commands. For example, if is is
142
60
  # set to "%", the "cd" command must be invoked as "%cd").
143
61
  # @return [String]
144
- attr_accessor :command_prefix
62
+ attribute :command_prefix
145
63
 
146
- # @return [Boolean] Toggle Pry color on and off.
147
- attr_accessor :color
148
-
149
- # @return [Boolean] Toggle paging on and off.
150
- attr_accessor :pager
64
+ # @return [Boolean]
65
+ attribute :color
151
66
 
152
- # Determines whether the rc file (~/.pryrc) should be loaded.
153
67
  # @return [Boolean]
154
- attr_accessor :should_load_rc
68
+ attribute :pager
69
+
70
+ # @return [Boolean] whether the global ~/.pryrc should be loaded
71
+ attribute :should_load_rc
72
+
73
+ # @return [Boolean] whether the local ./.pryrc should be loaded
74
+ attribute :should_load_local_rc
75
+
76
+ # @return [Boolean] whether to load files specified with the -r flag
77
+ attribute :should_load_requires
155
78
 
156
- # Determines whether the local rc file (./.pryrc) should be loaded.
79
+ # @return [Boolean] whether to disable edit-method's auto-reloading behavior
80
+ attribute :disable_auto_reload
81
+
82
+ # Whether Pry should trap SIGINT and cause it to raise an Interrupt
83
+ # exception. This is only useful on JRuby, MRI does this for us.
157
84
  # @return [Boolean]
158
- attr_accessor :should_load_local_rc
85
+ attribute :should_trap_interrupts
86
+
87
+ # @return [Pry::History]
88
+ attribute :history
159
89
 
160
- # Determines whether plugins should be loaded.
161
90
  # @return [Boolean]
162
- attr_accessor :should_load_plugins
91
+ attribute :history_save
163
92
 
164
- # Determines whether to load files specified with the -r flag.
165
93
  # @return [Boolean]
166
- attr_accessor :should_load_requires
94
+ attribute :history_load
95
+
96
+ # @return [String]
97
+ attribute :history_file
98
+
99
+ # @return [Array<String,Regexp>]
100
+ attribute :history_ignorelist
101
+
102
+ # @return [Array<String>] Ruby files to be required
103
+ attribute :requires
104
+
105
+ # @return [Integer] how many input/output lines to keep in memory
106
+ attribute :memory_size
107
+
108
+ # @return [Proc] The proc that runs system commands
109
+ attribute :system
167
110
 
168
- # Determines whether to disable edit-method's auto-reloading behavior.
169
111
  # @return [Boolean]
170
- attr_accessor :disable_auto_reload
112
+ attribute :auto_indent
171
113
 
172
- # Determines whether Pry should trap SIGINT and cause it to raise an
173
- # Interrupt exception. This is only useful on jruby, MRI does this
174
- # for us.
175
114
  # @return [Boolean]
176
- attr_accessor :should_trap_interrupts
177
-
178
- # Config option for history.
179
- # sub-options include history.file, history.load, and history.save
180
- # history.file is the file to save/load history to, e.g
181
- # Pry.config.history.file = "~/.pry_history".
182
- # history.should_load is a boolean that determines whether history will be
183
- # loaded from history.file at session start.
184
- # history.should_save is a boolean that determines whether history will be
185
- # saved to history.file at session end.
186
- # @return [OpenStruct]
187
- attr_accessor :history
188
-
189
- # Config option for plugins:
190
- # sub-options include:
191
- # `plugins.strict_loading` (Boolean) which toggles whether referring to a non-existent plugin should raise an exception (defaults to `false`)
192
- # @return [OpenStruct]
193
- attr_accessor :plugins
194
-
195
- # @return [Array<String>] Ruby files to be required after loading any plugins.
196
- attr_accessor :requires
197
-
198
- # @return [Integer] Amount of results that will be stored into out
199
- attr_accessor :memory_size
200
-
201
- # @return [Proc] The proc that manages ^D presses in the REPL.
202
- # The proc is passed the current eval_string and the current pry instance.
203
- attr_accessor :control_d_handler
115
+ attribute :correct_indent
204
116
 
205
- # @return [Proc] The proc that runs system commands
206
- # The proc is passed the pry output object, the command string
207
- # to eval, and a reference to the pry instance
208
- attr_accessor :system
209
-
210
- # @return [Boolean] Whether or not code should be indented
211
- # using Pry::Indent.
212
- attr_accessor :auto_indent
213
-
214
- # @return [Boolean] Whether or not indentation should be corrected
215
- # after hitting enter. This feature is not supported by all terminals.
216
- attr_accessor :correct_indent
217
-
218
- # @return [Boolean] Whether or not a warning will be displayed when
219
- # a command name collides with a method/local in the current context.
220
- attr_accessor :collision_warning
221
-
222
-
223
- # Config option for gist.
224
- # sub-options include `gist.inspecter`,
225
- # `gist.inspecter` is a callable that defines how the expression output
226
- # will be displayed when using the `gist -i` command.
227
- # @example Pretty inspect output
228
- # Pry.config.gist.inspecter = proc { |v| v.pretty_inspect }
229
- # @example Regular inspect
230
- # Pry.config.gist.inspecter = proc &:inspect
231
- # @return [OpenStruct]
232
- attr_accessor :gist
233
-
234
- # @return [Hash] Additional sticky locals (to the standard ones) to use in Pry sessions.
235
- # @example Inject `random_number` sticky local into Pry session
236
- # Pry.config.extra_sticky_locals = { :random_number => proc {
237
- # rand(10) } }
238
- attr_accessor :extra_sticky_locals
239
-
240
- # @return [#build_completion_proc] A completer to use.
241
- attr_accessor :completer
117
+ # @return [Boolean] whether or not display a warning when a command name
118
+ # collides with a method/local in the current context.
119
+ attribute :collision_warning
120
+
121
+ # @return [Hash{Symbol=>Proc}]
122
+ attribute :extra_sticky_locals
123
+
124
+ # @return [#build_completion_proc] a completer to use
125
+ attribute :completer
126
+
127
+ # @return [Boolean] suppresses whereami output on `binding.pry`
128
+ attribute :quiet
129
+
130
+ # @return [Boolean] displays a warning about experience improvement on
131
+ # Windows
132
+ attribute :windows_console_warning
133
+
134
+ # @return [Proc]
135
+ attribute :command_completions
136
+
137
+ # @return [Proc]
138
+ attribute :file_completions
139
+
140
+ # @return [Hash]
141
+ attribute :ls
142
+
143
+ # @return [String] a line of code to execute in context before the session
144
+ # starts
145
+ attribute :exec_string
146
+
147
+ # @return [String]
148
+ attribute :output_prefix
149
+
150
+ # @return [String]
151
+ # @since v0.13.0
152
+ attribute :rc_file
153
+
154
+ def initialize
155
+ merge!(
156
+ input: MemoizedValue.new { lazy_readline },
157
+ output: $stdout.tap { |out| out.sync = true },
158
+ commands: Pry::Commands,
159
+ prompt_name: 'pry',
160
+ prompt: Pry::Prompt[:default],
161
+ prompt_safe_contexts: [String, Numeric, Symbol, nil, true, false],
162
+ print: Pry::ColorPrinter.method(:default),
163
+ quiet: false,
164
+ exception_handler: Pry::ExceptionHandler.method(:handle_exception),
165
+
166
+ unrescued_exceptions: [
167
+ ::SystemExit, ::SignalException, Pry::TooSafeException
168
+ ],
169
+
170
+ exception_whitelist: MemoizedValue.new do
171
+ output.puts(
172
+ '[warning] Pry.config.exception_whitelist is deprecated, ' \
173
+ 'please use Pry.config.unrescued_exceptions instead.'
174
+ )
175
+ unrescued_exceptions
176
+ end,
177
+
178
+ hooks: Pry::Hooks.default,
179
+ pager: true,
180
+ system: Pry::SystemCommandHandler.method(:default),
181
+ color: Pry::Helpers::BaseHelpers.use_ansi_codes?,
182
+ default_window_size: 5,
183
+ editor: Pry::Editor.default,
184
+ rc_file: default_rc_file,
185
+ should_load_rc: true,
186
+ should_load_local_rc: true,
187
+ should_trap_interrupts: Pry::Helpers::Platform.jruby?,
188
+ disable_auto_reload: false,
189
+ command_prefix: '',
190
+ auto_indent: Pry::Helpers::BaseHelpers.use_ansi_codes?,
191
+ correct_indent: true,
192
+ collision_warning: false,
193
+ output_prefix: '=> ',
194
+ requires: [],
195
+ should_load_requires: true,
196
+ windows_console_warning: true,
197
+ control_d_handler: Pry::ControlDHandler.method(:default),
198
+ memory_size: 100,
199
+ extra_sticky_locals: {},
200
+ command_completions: proc { commands.keys },
201
+ file_completions: proc { Dir['.'] },
202
+ ls: OpenStruct.new(Pry::Command::Ls::DEFAULT_OPTIONS),
203
+ completer: Pry::InputCompleter,
204
+ history_save: true,
205
+ history_load: true,
206
+ history_file: Pry::History.default_file,
207
+ history_ignorelist: [],
208
+ history: MemoizedValue.new do
209
+ if defined?(input::HISTORY)
210
+ Pry::History.new(history: input::HISTORY)
211
+ else
212
+ Pry::History.new
213
+ end
214
+ end,
215
+ exec_string: ''
216
+ )
217
+
218
+ @custom_attrs = {}
219
+ end
220
+
221
+ def merge!(config_hash)
222
+ config_hash.each_pair { |attr, value| __send__("#{attr}=", value) }
223
+ self
224
+ end
225
+
226
+ def merge(config_hash)
227
+ dup.merge!(config_hash)
228
+ end
229
+
230
+ def []=(attr, value)
231
+ @custom_attrs[attr.to_s] = Config::Value.new(value)
232
+ end
233
+
234
+ def [](attr)
235
+ @custom_attrs[attr.to_s].call
236
+ end
237
+
238
+ # rubocop:disable Style/MethodMissingSuper
239
+ def method_missing(method_name, *args, &_block)
240
+ name = method_name.to_s
241
+
242
+ if name.end_with?('=')
243
+ self[name[0..-2]] = args.first
244
+ elsif @custom_attrs.key?(name)
245
+ self[name]
246
+ end
247
+ end
248
+ # rubocop:enable Style/MethodMissingSuper
249
+
250
+ def respond_to_missing?(method_name, include_all = false)
251
+ @custom_attrs.key?(method_name.to_s.tr('=', '')) || super
252
+ end
253
+
254
+ def initialize_dup(other)
255
+ super
256
+ @custom_attrs = @custom_attrs.dup
257
+ end
258
+
259
+ attr_reader :control_d_handler
260
+ def control_d_handler=(value)
261
+ proxy_proc =
262
+ if value.arity == 2
263
+ Pry::Warning.warn(
264
+ "control_d_handler's arity of 2 parameters was deprecated " \
265
+ '(eval_string, pry_instance). Now it gets passed just 1 ' \
266
+ 'parameter (pry_instance)'
267
+ )
268
+ proc do |*args|
269
+ if args.size == 2
270
+ value.call(args.first, args[1])
271
+ else
272
+ value.call(args.first.eval_string, args.first)
273
+ end
274
+ end
275
+ else
276
+ proc do |*args|
277
+ if args.size == 2
278
+ value.call(args[1])
279
+ else
280
+ value.call(args.first)
281
+ end
282
+ end
283
+ end
284
+ @control_d_handler = proxy_proc
285
+ end
286
+
287
+ private
288
+
289
+ def lazy_readline
290
+ require 'readline'
291
+ ::Readline
292
+ rescue LoadError
293
+ output.puts(
294
+ "Sorry, you can't use Pry without Readline or a compatible library. \n" \
295
+ "Possible solutions: \n" \
296
+ " * Rebuild Ruby with Readline support using `--with-readline` \n" \
297
+ " * Use the rb-readline gem, which is a pure-Ruby port of Readline \n" \
298
+ " * Use the pry-coolline gem, a pure-ruby alternative to Readline"
299
+ )
300
+ raise
301
+ end
302
+
303
+ def default_rc_file
304
+ [Pry::Env['PRYRC'],
305
+ # See XDG Base Directory Specification at
306
+ # https://specifications.freedesktop.org/basedir-spec/latest/
307
+ "#{Pry::Env['XDG_CONFIG_HOME']}/pry/pryrc",
308
+ File.expand_path('~/.pryrc'),
309
+ File.expand_path('~/.config/pry/pryrc')]
310
+ .compact
311
+ .find { |file| File.exist?(file) }
312
+ end
242
313
  end
243
314
  end
244
-
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ # @api private
5
+ # @since v0.13.0
6
+ module ControlDHandler
7
+ # Deal with the ^D key being pressed. Different behaviour in different
8
+ # cases:
9
+ # 1. In an expression behave like `!` command.
10
+ # 2. At top-level session behave like `exit` command.
11
+ # 3. In a nested session behave like `cd ..`.
12
+ def self.default(pry_instance)
13
+ if !pry_instance.eval_string.empty?
14
+ # Clear input buffer.
15
+ pry_instance.eval_string = ''
16
+ elsif pry_instance.binding_stack.one?
17
+ pry_instance.binding_stack.clear
18
+ throw(:breakout)
19
+ else
20
+ # Otherwise, saves current binding stack as old stack and pops last
21
+ # binding out of binding stack (the old stack still has that binding).
22
+ cd_state = Pry::CommandState.default.state_for('cd')
23
+ cd_state.old_stack = pry_instance.binding_stack.dup
24
+ pry_instance.binding_stack.pop
25
+ end
26
+ end
27
+ end
28
+ end