pry 0.9.10pre1-java → 0.9.11-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (194) hide show
  1. data/.travis.yml +3 -1
  2. data/CHANGELOG +63 -2
  3. data/CONTRIBUTORS +43 -25
  4. data/Gemfile +7 -0
  5. data/Guardfile +62 -0
  6. data/README.markdown +4 -4
  7. data/Rakefile +34 -35
  8. data/lib/pry.rb +107 -54
  9. data/lib/pry/cli.rb +34 -11
  10. data/lib/pry/code.rb +165 -182
  11. data/lib/pry/code/code_range.rb +70 -0
  12. data/lib/pry/code/loc.rb +92 -0
  13. data/lib/pry/code_object.rb +153 -0
  14. data/lib/pry/command.rb +160 -22
  15. data/lib/pry/command_set.rb +37 -26
  16. data/lib/pry/commands.rb +4 -27
  17. data/lib/pry/commands/amend_line.rb +99 -0
  18. data/lib/pry/commands/bang.rb +20 -0
  19. data/lib/pry/commands/bang_pry.rb +17 -0
  20. data/lib/pry/commands/cat.rb +53 -0
  21. data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
  22. data/lib/pry/commands/cat/exception_formatter.rb +78 -0
  23. data/lib/pry/commands/cat/file_formatter.rb +84 -0
  24. data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
  25. data/lib/pry/commands/cd.rb +30 -0
  26. data/lib/pry/commands/code_collector.rb +165 -0
  27. data/lib/pry/commands/deprecated_commands.rb +2 -0
  28. data/lib/pry/commands/disable_pry.rb +27 -0
  29. data/lib/pry/commands/easter_eggs.rb +112 -0
  30. data/lib/pry/commands/edit.rb +206 -0
  31. data/lib/pry/commands/edit/exception_patcher.rb +25 -0
  32. data/lib/pry/commands/edit/file_and_line_locator.rb +38 -0
  33. data/lib/pry/commands/edit/method_patcher.rb +122 -0
  34. data/lib/pry/commands/exit.rb +42 -0
  35. data/lib/pry/commands/exit_all.rb +29 -0
  36. data/lib/pry/commands/exit_program.rb +24 -0
  37. data/lib/pry/commands/find_method.rb +199 -0
  38. data/lib/pry/commands/fix_indent.rb +19 -0
  39. data/lib/pry/commands/gem_cd.rb +26 -0
  40. data/lib/pry/commands/gem_install.rb +29 -0
  41. data/lib/pry/commands/gem_list.rb +33 -0
  42. data/lib/pry/commands/gem_open.rb +29 -0
  43. data/lib/pry/commands/gist.rb +95 -0
  44. data/lib/pry/commands/help.rb +164 -0
  45. data/lib/pry/commands/hist.rb +161 -0
  46. data/lib/pry/commands/import_set.rb +22 -0
  47. data/lib/pry/commands/install_command.rb +51 -0
  48. data/lib/pry/commands/jump_to.rb +29 -0
  49. data/lib/pry/commands/ls.rb +339 -0
  50. data/lib/pry/commands/nesting.rb +25 -0
  51. data/lib/pry/commands/play.rb +69 -0
  52. data/lib/pry/commands/pry_backtrace.rb +26 -0
  53. data/lib/pry/commands/pry_version.rb +17 -0
  54. data/lib/pry/commands/raise_up.rb +32 -0
  55. data/lib/pry/commands/reload_code.rb +39 -0
  56. data/lib/pry/commands/reset.rb +18 -0
  57. data/lib/pry/commands/ri.rb +56 -0
  58. data/lib/pry/commands/save_file.rb +61 -0
  59. data/lib/pry/commands/shell_command.rb +43 -0
  60. data/lib/pry/commands/shell_mode.rb +27 -0
  61. data/lib/pry/commands/show_doc.rb +78 -0
  62. data/lib/pry/commands/show_info.rb +139 -0
  63. data/lib/pry/commands/show_input.rb +17 -0
  64. data/lib/pry/commands/show_source.rb +37 -0
  65. data/lib/pry/commands/simple_prompt.rb +22 -0
  66. data/lib/pry/commands/stat.rb +40 -0
  67. data/lib/pry/commands/switch_to.rb +23 -0
  68. data/lib/pry/commands/toggle_color.rb +20 -0
  69. data/lib/pry/commands/whereami.rb +114 -0
  70. data/lib/pry/commands/wtf.rb +57 -0
  71. data/lib/pry/completion.rb +120 -46
  72. data/lib/pry/config.rb +11 -0
  73. data/lib/pry/core_extensions.rb +30 -19
  74. data/lib/pry/editor.rb +129 -0
  75. data/lib/pry/helpers.rb +1 -0
  76. data/lib/pry/helpers/base_helpers.rb +89 -119
  77. data/lib/pry/helpers/command_helpers.rb +7 -122
  78. data/lib/pry/helpers/table.rb +100 -0
  79. data/lib/pry/helpers/text.rb +4 -4
  80. data/lib/pry/history_array.rb +5 -0
  81. data/lib/pry/hooks.rb +1 -3
  82. data/lib/pry/indent.rb +104 -30
  83. data/lib/pry/method.rb +66 -22
  84. data/lib/pry/module_candidate.rb +26 -15
  85. data/lib/pry/pager.rb +70 -0
  86. data/lib/pry/plugins.rb +1 -2
  87. data/lib/pry/pry_class.rb +63 -22
  88. data/lib/pry/pry_instance.rb +58 -37
  89. data/lib/pry/rubygem.rb +74 -0
  90. data/lib/pry/terminal_info.rb +43 -0
  91. data/lib/pry/test/helper.rb +185 -0
  92. data/lib/pry/version.rb +1 -1
  93. data/lib/pry/wrapped_module.rb +58 -24
  94. data/pry.gemspec +21 -37
  95. data/{test/test_cli.rb → spec/cli_spec.rb} +0 -0
  96. data/spec/code_object_spec.rb +277 -0
  97. data/{test/test_code.rb → spec/code_spec.rb} +19 -1
  98. data/{test/test_command_helpers.rb → spec/command_helpers_spec.rb} +0 -0
  99. data/{test/test_command_integration.rb → spec/command_integration_spec.rb} +38 -46
  100. data/{test/test_command_set.rb → spec/command_set_spec.rb} +18 -1
  101. data/{test/test_command.rb → spec/command_spec.rb} +250 -149
  102. data/spec/commands/amend_line_spec.rb +247 -0
  103. data/spec/commands/bang_spec.rb +19 -0
  104. data/spec/commands/cat_spec.rb +164 -0
  105. data/spec/commands/cd_spec.rb +250 -0
  106. data/spec/commands/disable_pry_spec.rb +25 -0
  107. data/spec/commands/edit_spec.rb +727 -0
  108. data/spec/commands/exit_all_spec.rb +34 -0
  109. data/spec/commands/exit_program_spec.rb +19 -0
  110. data/spec/commands/exit_spec.rb +34 -0
  111. data/{test/test_default_commands/test_find_method.rb → spec/commands/find_method_spec.rb} +27 -7
  112. data/spec/commands/gem_list_spec.rb +26 -0
  113. data/spec/commands/gist_spec.rb +75 -0
  114. data/{test/test_default_commands/test_help.rb → spec/commands/help_spec.rb} +8 -9
  115. data/spec/commands/hist_spec.rb +181 -0
  116. data/spec/commands/jump_to_spec.rb +15 -0
  117. data/spec/commands/ls_spec.rb +177 -0
  118. data/spec/commands/play_spec.rb +140 -0
  119. data/spec/commands/raise_up_spec.rb +56 -0
  120. data/spec/commands/save_file_spec.rb +177 -0
  121. data/spec/commands/show_doc_spec.rb +378 -0
  122. data/spec/commands/show_input_spec.rb +17 -0
  123. data/spec/commands/show_source_spec.rb +597 -0
  124. data/spec/commands/whereami_spec.rb +154 -0
  125. data/spec/completion_spec.rb +233 -0
  126. data/spec/control_d_handler_spec.rb +58 -0
  127. data/spec/editor_spec.rb +79 -0
  128. data/{test/test_exception_whitelist.rb → spec/exception_whitelist_spec.rb} +0 -0
  129. data/{test → spec/fixtures}/candidate_helper1.rb +0 -0
  130. data/{test → spec/fixtures}/candidate_helper2.rb +0 -0
  131. data/{test/test_default_commands → spec/fixtures}/example.erb +0 -0
  132. data/spec/fixtures/example_nesting.rb +33 -0
  133. data/spec/fixtures/show_source_doc_examples.rb +15 -0
  134. data/{test → spec/fixtures}/testrc +0 -0
  135. data/{test → spec/fixtures}/testrcbad +0 -0
  136. data/spec/helper.rb +34 -0
  137. data/spec/helpers/bacon.rb +86 -0
  138. data/spec/helpers/mock_pry.rb +43 -0
  139. data/spec/helpers/table_spec.rb +83 -0
  140. data/{test/test_history_array.rb → spec/history_array_spec.rb} +21 -19
  141. data/{test/test_hooks.rb → spec/hooks_spec.rb} +0 -0
  142. data/{test/test_indent.rb → spec/indent_spec.rb} +24 -0
  143. data/{test/test_input_stack.rb → spec/input_stack_spec.rb} +4 -0
  144. data/{test/test_method.rb → spec/method_spec.rb} +65 -1
  145. data/{test/test_prompt.rb → spec/prompt_spec.rb} +0 -0
  146. data/{test/test_pry_defaults.rb → spec/pry_defaults_spec.rb} +14 -14
  147. data/{test/test_pry_history.rb → spec/pry_history_spec.rb} +15 -0
  148. data/spec/pry_output_spec.rb +95 -0
  149. data/{test/test_pry.rb → spec/pry_spec.rb} +74 -32
  150. data/{test/test_sticky_locals.rb → spec/sticky_locals_spec.rb} +27 -25
  151. data/{test/test_syntax_checking.rb → spec/syntax_checking_spec.rb} +17 -1
  152. data/{test/test_wrapped_module.rb → spec/wrapped_module_spec.rb} +92 -5
  153. metadata +239 -115
  154. data/examples/example_basic.rb +0 -15
  155. data/examples/example_command_override.rb +0 -32
  156. data/examples/example_commands.rb +0 -36
  157. data/examples/example_hooks.rb +0 -9
  158. data/examples/example_image_edit.rb +0 -67
  159. data/examples/example_input.rb +0 -7
  160. data/examples/example_input2.rb +0 -29
  161. data/examples/example_output.rb +0 -11
  162. data/examples/example_print.rb +0 -6
  163. data/examples/example_prompt.rb +0 -9
  164. data/examples/helper.rb +0 -6
  165. data/lib/pry/default_commands/cd.rb +0 -81
  166. data/lib/pry/default_commands/commands.rb +0 -62
  167. data/lib/pry/default_commands/context.rb +0 -98
  168. data/lib/pry/default_commands/easter_eggs.rb +0 -95
  169. data/lib/pry/default_commands/editing.rb +0 -420
  170. data/lib/pry/default_commands/find_method.rb +0 -169
  171. data/lib/pry/default_commands/gems.rb +0 -84
  172. data/lib/pry/default_commands/gist.rb +0 -187
  173. data/lib/pry/default_commands/help.rb +0 -127
  174. data/lib/pry/default_commands/hist.rb +0 -120
  175. data/lib/pry/default_commands/input_and_output.rb +0 -306
  176. data/lib/pry/default_commands/introspection.rb +0 -410
  177. data/lib/pry/default_commands/ls.rb +0 -272
  178. data/lib/pry/default_commands/misc.rb +0 -38
  179. data/lib/pry/default_commands/navigating_pry.rb +0 -110
  180. data/lib/pry/default_commands/whereami.rb +0 -92
  181. data/lib/pry/extended_commands/experimental.rb +0 -7
  182. data/test/helper.rb +0 -223
  183. data/test/test_completion.rb +0 -62
  184. data/test/test_control_d_handler.rb +0 -45
  185. data/test/test_default_commands/test_cd.rb +0 -321
  186. data/test/test_default_commands/test_context.rb +0 -288
  187. data/test/test_default_commands/test_documentation.rb +0 -315
  188. data/test/test_default_commands/test_gems.rb +0 -18
  189. data/test/test_default_commands/test_input.rb +0 -428
  190. data/test/test_default_commands/test_introspection.rb +0 -511
  191. data/test/test_default_commands/test_ls.rb +0 -151
  192. data/test/test_default_commands/test_shell.rb +0 -343
  193. data/test/test_default_commands/test_show_source.rb +0 -432
  194. data/test/test_pry_output.rb +0 -41
@@ -1,272 +0,0 @@
1
- class Pry
2
- module DefaultCommands
3
-
4
- Ls = Pry::CommandSet.new do
5
-
6
- create_command "ls","Show the list of vars and methods in the current scope.",
7
- :shellwords => false, :interpolate => false do
8
-
9
- group "Context"
10
-
11
- def options(opt)
12
- opt.banner unindent <<-USAGE
13
- Usage: ls [-m|-M|-p|-pM] [-q|-v] [-c|-i] [Object]
14
- ls [-g] [-l]
15
-
16
- ls shows you which methods, constants and variables are accessible to Pry. By default it shows you the local variables defined in the current shell, and any public methods or instance variables defined on the current object.
17
-
18
- The colours used are configurable using Pry.config.ls.*_color, and the separator is Pry.config.ls.separator.
19
-
20
- Pry.config.ls.ceiling is used to hide methods defined higher up in the inheritance chain, this is by default set to [Object, Module, Class] so that methods defined on all Objects are omitted. The -v flag can be used to ignore this setting and show all methods, while the -q can be used to set the ceiling much lower and show only methods defined on the object or its direct class.
21
- USAGE
22
-
23
- opt.on :m, "methods", "Show public methods defined on the Object (default)"
24
- opt.on :M, "instance-methods", "Show methods defined in a Module or Class"
25
-
26
- opt.on :p, "ppp", "Show public, protected (in yellow) and private (in green) methods"
27
- opt.on :q, "quiet", "Show only methods defined on object.singleton_class and object.class"
28
- opt.on :v, "verbose", "Show methods and constants on all super-classes (ignores Pry.config.ls.ceiling)"
29
-
30
- opt.on :g, "globals", "Show global variables, including those builtin to Ruby (in cyan)"
31
- opt.on :l, "locals", "Show locals, including those provided by Pry (in red)"
32
-
33
- opt.on :c, "constants", "Show constants, highlighting classes (in blue), and exceptions (in purple).\n" +
34
- " " * 32 + "Constants that are pending autoload? are also shown (in yellow)."
35
-
36
- opt.on :i, "ivars", "Show instance variables (in blue) and class variables (in bright blue)"
37
-
38
- opt.on :G, "grep", "Filter output by regular expression", :argument => true
39
- if jruby?
40
- opt.on :J, "all-java", "Show all the aliases for methods from java (default is to show only prettiest)"
41
- end
42
- end
43
-
44
- def process
45
- obj = args.empty? ? target_self : target.eval(args.join(" "))
46
-
47
- # exclude -q, -v and --grep because they don't specify what the user wants to see.
48
- has_opts = (opts.present?(:methods) || opts.present?(:'instance-methods') || opts.present?(:ppp) ||
49
- opts.present?(:globals) || opts.present?(:locals) || opts.present?(:constants) ||
50
- opts.present?(:ivars))
51
-
52
- show_methods = opts.present?(:methods) || opts.present?(:'instance-methods') || opts.present?(:ppp) || !has_opts
53
- show_self_methods = (!has_opts && Module === obj)
54
- show_constants = opts.present?(:constants) || (!has_opts && Module === obj)
55
- show_ivars = opts.present?(:ivars) || !has_opts
56
- show_locals = opts.present?(:locals) || (!has_opts && args.empty?)
57
-
58
- grep_regex, grep = [Regexp.new(opts[:G] || "."), lambda{ |x| x.grep(grep_regex) }]
59
-
60
- raise Pry::CommandError, "-l does not make sense with a specified Object" if opts.present?(:locals) && !args.empty?
61
- raise Pry::CommandError, "-g does not make sense with a specified Object" if opts.present?(:globals) && !args.empty?
62
- raise Pry::CommandError, "-q does not make sense with -v" if opts.present?(:quiet) && opts.present?(:verbose)
63
- raise Pry::CommandError, "-M only makes sense with a Module or a Class" if opts.present?(:'instance-methods') && !(Module === obj)
64
- raise Pry::CommandError, "-c only makes sense with a Module or a Class" if opts.present?(:constants) && !args.empty? && !(Module === obj)
65
-
66
-
67
- if opts.present?(:globals)
68
- output_section("global variables", grep[format_globals(target.eval("global_variables"))])
69
- end
70
-
71
- if show_constants
72
- mod = Module === obj ? obj : Object
73
- constants = mod.constants
74
- constants -= (mod.ancestors - [mod]).map(&:constants).flatten unless opts.present?(:verbose)
75
- output_section("constants", grep[format_constants(mod, constants)])
76
- end
77
-
78
- if show_methods
79
- # methods is a hash {Module/Class => [Pry::Methods]}
80
- methods = all_methods(obj).group_by(&:owner)
81
-
82
- # reverse the resolution order so that the most useful information appears right by the prompt
83
- resolution_order(obj).take_while(&below_ceiling(obj)).reverse.each do |klass|
84
- methods_here = format_methods((methods[klass] || []).select{ |m| m.name =~ grep_regex })
85
- output_section "#{Pry::WrappedModule.new(klass).method_prefix}methods", methods_here
86
- end
87
- end
88
-
89
- if show_self_methods
90
- methods = all_methods(obj, true).select{ |m| m.owner == obj && m.name =~ grep_regex }
91
- output_section "#{Pry::WrappedModule.new(obj).method_prefix}methods", format_methods(methods)
92
- end
93
-
94
- if show_ivars
95
- klass = (Module === obj ? obj : obj.class)
96
- ivars = Pry::Method.safe_send(obj, :instance_variables)
97
- kvars = Pry::Method.safe_send(klass, :class_variables)
98
- output_section("instance variables", format_variables(:instance_var, ivars))
99
- output_section("class variables", format_variables(:class_var, kvars))
100
- end
101
-
102
- if show_locals
103
- output_section("locals", format_locals(grep[target.eval("local_variables")]))
104
- end
105
- end
106
-
107
- private
108
-
109
- # http://ruby.runpaint.org/globals, and running "puts global_variables.inspect".
110
- BUILTIN_GLOBALS = %w($" $$ $* $, $-0 $-F $-I $-K $-W $-a $-d $-i $-l $-p $-v $-w $. $/ $\\
111
- $: $; $< $= $> $0 $ARGV $CONSOLE $DEBUG $DEFAULT_INPUT $DEFAULT_OUTPUT
112
- $FIELD_SEPARATOR $FILENAME $FS $IGNORECASE $INPUT_LINE_NUMBER
113
- $INPUT_RECORD_SEPARATOR $KCODE $LOADED_FEATURES $LOAD_PATH $NR $OFS
114
- $ORS $OUTPUT_FIELD_SEPARATOR $OUTPUT_RECORD_SEPARATOR $PID $PROCESS_ID
115
- $PROGRAM_NAME $RS $VERBOSE $deferr $defout $stderr $stdin $stdout)
116
-
117
- # $SAFE and $? are thread-local, the exception stuff only works in a rescue clause,
118
- # everything else is basically a local variable with a $ in its name.
119
- PSEUDO_GLOBALS = %w($! $' $& $` $@ $? $+ $_ $~ $1 $2 $3 $4 $5 $6 $7 $8 $9
120
- $CHILD_STATUS $SAFE $ERROR_INFO $ERROR_POSITION $LAST_MATCH_INFO
121
- $LAST_PAREN_MATCH $LAST_READ_LINE $MATCH $POSTMATCH $PREMATCH)
122
-
123
- # Get all the methods that we'll want to output
124
- def all_methods(obj, instance_methods=false)
125
- methods = if instance_methods || opts.present?(:'instance-methods')
126
- Pry::Method.all_from_class(obj)
127
- else
128
- Pry::Method.all_from_obj(obj)
129
- end
130
-
131
- if jruby? && !opts.present?(:J)
132
- methods = trim_jruby_aliases(methods)
133
- end
134
-
135
- methods.select{ |method| opts.present?(:ppp) || method.visibility == :public }
136
- end
137
-
138
- # JRuby creates lots of aliases for methods imported from java in an attempt to
139
- # make life easier for ruby programmers.
140
- # (e.g. getFooBar becomes get_foo_bar and foo_bar, and maybe foo_bar? if it
141
- # returns a Boolean).
142
- # The full transformations are in the assignAliases method of:
143
- # https://github.com/jruby/jruby/blob/master/src/org/jruby/javasupport/JavaClass.java
144
- #
145
- # This has the unfortunate side-effect of making the output of ls even more
146
- # incredibly verbose than it normally would be for these objects; and so we filter
147
- # out all but the nicest of these aliases here.
148
- #
149
- # TODO: This is a little bit vague, better heuristics could be used.
150
- # JRuby also has a lot of scala-specific logic, which we don't copy.
151
- #
152
- def trim_jruby_aliases(methods)
153
- grouped = methods.group_by do |m|
154
- m.name.sub(/\A(is|get|set)(?=[A-Z_])/, '').gsub(/[_?=]/, '').downcase
155
- end
156
-
157
- grouped.map do |key, values|
158
- values = values.sort_by do |m|
159
- rubbishness(m.name)
160
- end
161
-
162
- found = []
163
- values.select do |x|
164
- (!found.any?{ |y| x == y }) && found << x
165
- end
166
- end.flatten(1)
167
- end
168
-
169
- # When removing jruby aliases, we want to keep the alias that is "least rubbish"
170
- # according to this metric.
171
- def rubbishness(name)
172
- name.each_char.map{ |x|
173
- case x
174
- when /[A-Z]/
175
- 1
176
- when '?', '=', '!'
177
- -2
178
- else
179
- 0
180
- end
181
- }.inject(&:+) + (name.size / 100.0)
182
- end
183
-
184
- def resolution_order(obj)
185
- opts.present?(:'instance-methods') ? Pry::Method.instance_resolution_order(obj) : Pry::Method.resolution_order(obj)
186
- end
187
-
188
- # Get a lambda that can be used with .take_while to prevent over-eager
189
- # traversal of the Object's ancestry graph.
190
- def below_ceiling(obj)
191
- ceiling = if opts.present?(:quiet)
192
- [opts.present?(:'instance-methods') ? obj.ancestors[1] : obj.class.ancestors[1]] + Pry.config.ls.ceiling
193
- elsif opts.present?(:verbose)
194
- []
195
- else
196
- Pry.config.ls.ceiling.dup
197
- end
198
-
199
- lambda { |klass| !ceiling.include?(klass) }
200
- end
201
-
202
- # Format and colourise a list of methods.
203
- def format_methods(methods)
204
- methods.sort_by(&:name).map do |method|
205
- if method.name == 'method_missing'
206
- color(:method_missing, 'method_missing')
207
- elsif method.visibility == :private
208
- color(:private_method, method.name)
209
- elsif method.visibility == :protected
210
- color(:protected_method, method.name)
211
- else
212
- color(:public_method, method.name)
213
- end
214
- end
215
- end
216
-
217
- def format_variables(type, vars)
218
- vars.sort_by(&:downcase).map{ |var| color(type, var) }
219
- end
220
-
221
- def format_constants(mod, constants)
222
- constants.sort_by(&:downcase).map do |name|
223
- if const = (!mod.autoload?(name) && (mod.const_get(name) || true) rescue nil)
224
- if (const < Exception rescue false)
225
- color(:exception_constant, name)
226
- elsif (Module === mod.const_get(name) rescue false)
227
- color(:class_constant, name)
228
- else
229
- color(:constant, name)
230
- end
231
- else
232
- color(:unloaded_constant, name)
233
- end
234
- end
235
- end
236
-
237
- def format_globals(globals)
238
- globals.sort_by(&:downcase).map do |name|
239
- if PSEUDO_GLOBALS.include?(name)
240
- color(:pseudo_global, name)
241
- elsif BUILTIN_GLOBALS.include?(name)
242
- color(:builtin_global, name)
243
- else
244
- color(:global_var, name)
245
- end
246
- end
247
- end
248
-
249
- def format_locals(locals)
250
- locals.sort_by(&:downcase).map do |name|
251
- if _pry_.sticky_locals.include?(name.to_sym)
252
- color(:pry_var, name)
253
- else
254
- color(:local_var, name)
255
- end
256
- end
257
- end
258
-
259
- # Add a new section to the output. Outputs nothing if the section would be empty.
260
- def output_section(heading, body)
261
- return if body.compact.empty?
262
- output.puts "#{text.bold(color(:heading, heading))}: #{body.compact.join(Pry.config.ls.separator)}"
263
- end
264
-
265
- # Color output based on config.ls.*_color
266
- def color(type, str)
267
- text.send(Pry.config.ls.send(:"#{type}_color"), str)
268
- end
269
- end
270
- end
271
- end
272
- end
@@ -1,38 +0,0 @@
1
- class Pry
2
- module DefaultCommands
3
- Misc = Pry::CommandSet.new do
4
-
5
- command "toggle-color", "Toggle syntax highlighting." do
6
- Pry.color = !Pry.color
7
- output.puts "Syntax highlighting #{Pry.color ? "on" : "off"}"
8
- end
9
-
10
- command "simple-prompt", "Toggle the simple prompt." do
11
- case _pry_.prompt
12
- when Pry::SIMPLE_PROMPT
13
- _pry_.pop_prompt
14
- else
15
- _pry_.push_prompt Pry::SIMPLE_PROMPT
16
- end
17
- end
18
-
19
- command "pry-version", "Show Pry version." do
20
- output.puts "Pry version: #{Pry::VERSION} on Ruby #{RUBY_VERSION}."
21
- end
22
-
23
- command "reload-method", "Reload the source file that contains the specified method" do |meth_name|
24
- meth = get_method_or_raise(meth_name, target, {}, :omit_help)
25
-
26
- if meth.source_type == :c
27
- raise CommandError, "Can't reload a C method."
28
- elsif meth.dynamically_defined?
29
- raise CommandError, "Can't reload an eval method."
30
- else
31
- file_name = meth.source_file
32
- load file_name
33
- output.puts "Reloaded #{file_name}."
34
- end
35
- end
36
- end
37
- end
38
- end
@@ -1,110 +0,0 @@
1
- class Pry
2
- module DefaultCommands
3
-
4
- NavigatingPry = Pry::CommandSet.new do
5
- command "switch-to", "Start a new sub-session on a binding in the current stack (numbered by nesting)." do |selection|
6
- selection = selection.to_i
7
-
8
- if selection < 0 || selection > _pry_.binding_stack.size - 1
9
- raise CommandError, "Invalid binding index #{selection} - use `nesting` command to view valid indices."
10
- else
11
- Pry.start(_pry_.binding_stack[selection])
12
- end
13
- end
14
-
15
- command "nesting", "Show nesting information." do
16
- output.puts "Nesting status:"
17
- output.puts "--"
18
- _pry_.binding_stack.each_with_index do |obj, level|
19
- if level == 0
20
- output.puts "#{level}. #{Pry.view_clip(obj.eval('self'))} (Pry top level)"
21
- else
22
- output.puts "#{level}. #{Pry.view_clip(obj.eval('self'))}"
23
- end
24
- end
25
- end
26
-
27
- command "jump-to", "Jump to a binding further up the stack, popping all bindings below." do |break_level|
28
- break_level = break_level.to_i
29
- nesting_level = _pry_.binding_stack.size - 1
30
-
31
- case break_level
32
- when nesting_level
33
- output.puts "Already at nesting level #{nesting_level}"
34
- when (0...nesting_level)
35
- _pry_.binding_stack.slice!(break_level + 1, _pry_.binding_stack.size)
36
-
37
- else
38
- max_nest_level = nesting_level - 1
39
- output.puts "Invalid nest level. Must be between 0 and #{max_nest_level}. Got #{break_level}."
40
- end
41
- end
42
-
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
-
47
- # clear the binding stack
48
- _pry_.binding_stack.clear
49
-
50
- # break out of the repl loop
51
- throw(:breakout, exit_value)
52
- end
53
-
54
- alias_command "!!@", "exit-all"
55
-
56
- create_command "exit" do
57
- description "Pop the previous binding (does NOT exit program). Aliases: quit"
58
-
59
- banner <<-BANNER
60
- Usage: exit [OPTIONS] [--help]
61
- Aliases: quit
62
-
63
- It can be useful to exit a context with a user-provided value. For
64
- instance an exit value can be used to determine program flow.
65
-
66
- e.g: `exit "pry this"`
67
- e.g: `exit`
68
-
69
- https://github.com/pry/pry/wiki/State-navigation#wiki-Exit_with_value
70
- BANNER
71
-
72
- command_options(
73
- :keep_retval => true
74
- )
75
-
76
- def process
77
- if _pry_.binding_stack.one?
78
- _pry_.run_command "exit-all #{arg_string}"
79
- else
80
- # otherwise just pop a binding and return user supplied value
81
- process_pop_and_return
82
- end
83
- end
84
-
85
- def process_pop_and_return
86
- popped_object = _pry_.binding_stack.pop.eval('self')
87
-
88
- # return a user-specified value if given otherwise return the object
89
- return target.eval(arg_string) unless arg_string.empty?
90
- popped_object
91
- end
92
- end
93
-
94
- alias_command "quit", "exit"
95
-
96
- command "exit-program", "End the current program. Aliases: quit-program, !!!" do
97
- Pry.save_history if Pry.config.history.should_save
98
- Kernel.exit target.eval(arg_string).to_i
99
- end
100
-
101
- alias_command "quit-program", "exit-program"
102
- alias_command "!!!", "exit-program"
103
-
104
- command "!pry", "Start a Pry session on current self; this even works mid multi-line expression." do
105
- target.pry
106
- end
107
-
108
- end
109
- end
110
- end
@@ -1,92 +0,0 @@
1
-
2
- class Pry
3
- module DefaultCommands
4
- Whereami = Pry::CommandSet.new do
5
- create_command "whereami" do
6
- description "Show code surrounding the current context."
7
- group 'Context'
8
- banner <<-BANNER
9
- Usage: whereami [-q] [N]
10
-
11
- Describe the current location. If you use `binding.pry` inside a
12
- method then whereami will print out the source for that method.
13
-
14
- If a number is passed, then N lines before and after the current line
15
- will be shown instead of the method itself.
16
-
17
- The `-q` flag can be used to suppress error messages in the case that
18
- there's no code to show. This is used by pry in the default
19
- before_session hook to show you when you arrive at a `binding.pry`.
20
-
21
- When pry was started on an Object and there is no associated method,
22
- whereami will instead output a brief description of the current
23
- object.
24
- BANNER
25
-
26
- def setup
27
- @method = Pry::Method.from_binding(target)
28
- @file = target.eval('__FILE__')
29
- @line = target.eval('__LINE__')
30
- end
31
-
32
- def options(opt)
33
- opt.on :q, :quiet, "Don't display anything in case of an error"
34
- end
35
-
36
- def code
37
- @code ||= if show_method?
38
- Pry::Code.from_method(@method)
39
- else
40
- Pry::Code.from_file(@file).around(@line, window_size)
41
- end
42
- end
43
-
44
- def location
45
- "#{@file} @ line #{show_method? ? @method.source_line : @line} #{@method && @method.name_with_owner}"
46
- end
47
-
48
- def process
49
- if opts.quiet? && (internal_binding?(target) || !code?)
50
- return
51
- elsif internal_binding?(target)
52
- if target_self == TOPLEVEL_BINDING.eval("self")
53
- output.puts "At the top level."
54
- else
55
- output.puts "Inside #{Pry.view_clip(target_self)}."
56
- end
57
- return
58
- end
59
-
60
- set_file_and_dir_locals(@file)
61
-
62
- output.puts "\n#{text.bold('From:')} #{location}:\n\n"
63
- output.puts code.with_line_numbers.with_marker(@line)
64
- output.puts
65
- end
66
-
67
- private
68
-
69
- def show_method?
70
- args.empty? && @method && @method.source? && @method.source_range.count < 20 &&
71
- # These checks are needed in case of an eval with a binding and file/line
72
- # numbers set to outside the function. As in rails' use of ERB.
73
- @method.source_file == @file && @method.source_range.include?(@line)
74
- end
75
-
76
- def code?
77
- !!code
78
- rescue MethodSource::SourceNotFoundError
79
- false
80
- end
81
-
82
- def window_size
83
- if args.empty?
84
- Pry.config.default_window_size
85
- else
86
- args.first.to_i
87
- end
88
- end
89
- end
90
- end
91
- end
92
- end