pry 0.10.pre.1-java → 0.10.0.pre2-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +702 -0
  3. data/LICENSE +2 -2
  4. data/{README.markdown → README.md} +41 -35
  5. data/lib/pry.rb +82 -139
  6. data/lib/pry/cli.rb +77 -30
  7. data/lib/pry/code.rb +126 -182
  8. data/lib/pry/code/code_file.rb +103 -0
  9. data/lib/pry/code/code_range.rb +71 -0
  10. data/lib/pry/code/loc.rb +92 -0
  11. data/lib/pry/code_object.rb +172 -0
  12. data/lib/pry/color_printer.rb +55 -0
  13. data/lib/pry/command.rb +184 -28
  14. data/lib/pry/command_set.rb +113 -59
  15. data/lib/pry/commands.rb +4 -27
  16. data/lib/pry/commands/amend_line.rb +99 -0
  17. data/lib/pry/commands/bang.rb +20 -0
  18. data/lib/pry/commands/bang_pry.rb +17 -0
  19. data/lib/pry/commands/cat.rb +62 -0
  20. data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
  21. data/lib/pry/commands/cat/exception_formatter.rb +77 -0
  22. data/lib/pry/commands/cat/file_formatter.rb +67 -0
  23. data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
  24. data/lib/pry/commands/cd.rb +41 -0
  25. data/lib/pry/commands/change_inspector.rb +27 -0
  26. data/lib/pry/commands/change_prompt.rb +26 -0
  27. data/lib/pry/commands/code_collector.rb +165 -0
  28. data/lib/pry/commands/disable_pry.rb +27 -0
  29. data/lib/pry/commands/disabled_commands.rb +2 -0
  30. data/lib/pry/commands/easter_eggs.rb +112 -0
  31. data/lib/pry/commands/edit.rb +195 -0
  32. data/lib/pry/commands/edit/exception_patcher.rb +25 -0
  33. data/lib/pry/commands/edit/file_and_line_locator.rb +36 -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 +23 -0
  37. data/lib/pry/commands/find_method.rb +193 -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 +32 -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 +101 -0
  44. data/lib/pry/commands/help.rb +164 -0
  45. data/lib/pry/commands/hist.rb +180 -0
  46. data/lib/pry/commands/import_set.rb +22 -0
  47. data/lib/pry/commands/install_command.rb +53 -0
  48. data/lib/pry/commands/jump_to.rb +29 -0
  49. data/lib/pry/commands/list_inspectors.rb +35 -0
  50. data/lib/pry/commands/list_prompts.rb +35 -0
  51. data/lib/pry/commands/ls.rb +114 -0
  52. data/lib/pry/commands/ls/constants.rb +47 -0
  53. data/lib/pry/commands/ls/formatter.rb +49 -0
  54. data/lib/pry/commands/ls/globals.rb +48 -0
  55. data/lib/pry/commands/ls/grep.rb +21 -0
  56. data/lib/pry/commands/ls/instance_vars.rb +39 -0
  57. data/lib/pry/commands/ls/interrogatable.rb +18 -0
  58. data/lib/pry/commands/ls/jruby_hacks.rb +49 -0
  59. data/lib/pry/commands/ls/local_names.rb +35 -0
  60. data/lib/pry/commands/ls/local_vars.rb +39 -0
  61. data/lib/pry/commands/ls/ls_entity.rb +70 -0
  62. data/lib/pry/commands/ls/methods.rb +57 -0
  63. data/lib/pry/commands/ls/methods_helper.rb +46 -0
  64. data/lib/pry/commands/ls/self_methods.rb +32 -0
  65. data/lib/pry/commands/nesting.rb +25 -0
  66. data/lib/pry/commands/play.rb +103 -0
  67. data/lib/pry/commands/pry_backtrace.rb +25 -0
  68. data/lib/pry/commands/pry_version.rb +17 -0
  69. data/lib/pry/commands/raise_up.rb +32 -0
  70. data/lib/pry/commands/reload_code.rb +62 -0
  71. data/lib/pry/commands/reset.rb +18 -0
  72. data/lib/pry/commands/ri.rb +60 -0
  73. data/lib/pry/commands/save_file.rb +61 -0
  74. data/lib/pry/commands/shell_command.rb +48 -0
  75. data/lib/pry/commands/shell_mode.rb +25 -0
  76. data/lib/pry/commands/show_doc.rb +83 -0
  77. data/lib/pry/commands/show_info.rb +195 -0
  78. data/lib/pry/commands/show_input.rb +17 -0
  79. data/lib/pry/commands/show_source.rb +50 -0
  80. data/lib/pry/commands/simple_prompt.rb +22 -0
  81. data/lib/pry/commands/stat.rb +40 -0
  82. data/lib/pry/commands/switch_to.rb +23 -0
  83. data/lib/pry/commands/toggle_color.rb +24 -0
  84. data/lib/pry/commands/watch_expression.rb +105 -0
  85. data/lib/pry/commands/watch_expression/expression.rb +38 -0
  86. data/lib/pry/commands/whereami.rb +190 -0
  87. data/lib/pry/commands/wtf.rb +57 -0
  88. data/lib/pry/config.rb +20 -229
  89. data/lib/pry/config/behavior.rb +139 -0
  90. data/lib/pry/config/convenience.rb +26 -0
  91. data/lib/pry/config/default.rb +165 -0
  92. data/lib/pry/core_extensions.rb +59 -38
  93. data/lib/pry/editor.rb +133 -0
  94. data/lib/pry/exceptions.rb +77 -0
  95. data/lib/pry/helpers.rb +1 -0
  96. data/lib/pry/helpers/base_helpers.rb +40 -154
  97. data/lib/pry/helpers/command_helpers.rb +19 -130
  98. data/lib/pry/helpers/documentation_helpers.rb +21 -11
  99. data/lib/pry/helpers/table.rb +109 -0
  100. data/lib/pry/helpers/text.rb +8 -9
  101. data/lib/pry/history.rb +61 -45
  102. data/lib/pry/history_array.rb +11 -1
  103. data/lib/pry/hooks.rb +10 -32
  104. data/lib/pry/indent.rb +110 -38
  105. data/lib/pry/input_completer.rb +242 -0
  106. data/lib/pry/input_lock.rb +132 -0
  107. data/lib/pry/inspector.rb +27 -0
  108. data/lib/pry/last_exception.rb +61 -0
  109. data/lib/pry/method.rb +199 -200
  110. data/lib/pry/method/disowned.rb +53 -0
  111. data/lib/pry/method/patcher.rb +125 -0
  112. data/lib/pry/method/weird_method_locator.rb +186 -0
  113. data/lib/pry/module_candidate.rb +39 -33
  114. data/lib/pry/object_path.rb +82 -0
  115. data/lib/pry/output.rb +50 -0
  116. data/lib/pry/pager.rb +234 -0
  117. data/lib/pry/plugins.rb +4 -3
  118. data/lib/pry/prompt.rb +26 -0
  119. data/lib/pry/pry_class.rb +199 -227
  120. data/lib/pry/pry_instance.rb +344 -403
  121. data/lib/pry/rbx_path.rb +1 -1
  122. data/lib/pry/repl.rb +202 -0
  123. data/lib/pry/repl_file_loader.rb +20 -26
  124. data/lib/pry/rubygem.rb +82 -0
  125. data/lib/pry/terminal.rb +79 -0
  126. data/lib/pry/test/helper.rb +170 -0
  127. data/lib/pry/version.rb +1 -1
  128. data/lib/pry/wrapped_module.rb +133 -48
  129. metadata +132 -197
  130. data/.document +0 -2
  131. data/.gemtest +0 -0
  132. data/.gitignore +0 -16
  133. data/.travis.yml +0 -17
  134. data/.yardopts +0 -1
  135. data/CHANGELOG +0 -387
  136. data/CONTRIBUTORS +0 -36
  137. data/Gemfile +0 -2
  138. data/Rakefile +0 -137
  139. data/TODO +0 -117
  140. data/examples/example_basic.rb +0 -15
  141. data/examples/example_command_override.rb +0 -32
  142. data/examples/example_commands.rb +0 -36
  143. data/examples/example_hooks.rb +0 -9
  144. data/examples/example_image_edit.rb +0 -67
  145. data/examples/example_input.rb +0 -7
  146. data/examples/example_input2.rb +0 -29
  147. data/examples/example_output.rb +0 -11
  148. data/examples/example_print.rb +0 -6
  149. data/examples/example_prompt.rb +0 -9
  150. data/examples/helper.rb +0 -6
  151. data/lib/pry/completion.rb +0 -221
  152. data/lib/pry/custom_completions.rb +0 -6
  153. data/lib/pry/default_commands/cd.rb +0 -81
  154. data/lib/pry/default_commands/commands.rb +0 -62
  155. data/lib/pry/default_commands/context.rb +0 -98
  156. data/lib/pry/default_commands/easter_eggs.rb +0 -95
  157. data/lib/pry/default_commands/editing.rb +0 -420
  158. data/lib/pry/default_commands/find_method.rb +0 -169
  159. data/lib/pry/default_commands/gems.rb +0 -84
  160. data/lib/pry/default_commands/gist.rb +0 -187
  161. data/lib/pry/default_commands/help.rb +0 -127
  162. data/lib/pry/default_commands/hist.rb +0 -120
  163. data/lib/pry/default_commands/input_and_output.rb +0 -306
  164. data/lib/pry/default_commands/introspection.rb +0 -410
  165. data/lib/pry/default_commands/ls.rb +0 -272
  166. data/lib/pry/default_commands/misc.rb +0 -38
  167. data/lib/pry/default_commands/navigating_pry.rb +0 -110
  168. data/lib/pry/default_commands/whereami.rb +0 -92
  169. data/lib/pry/extended_commands/experimental.rb +0 -7
  170. data/lib/pry/rbx_method.rb +0 -13
  171. data/man/pry.1 +0 -195
  172. data/man/pry.1.html +0 -204
  173. data/man/pry.1.ronn +0 -141
  174. data/pry.gemspec +0 -46
  175. data/test/candidate_helper1.rb +0 -11
  176. data/test/candidate_helper2.rb +0 -8
  177. data/test/helper.rb +0 -223
  178. data/test/test_cli.rb +0 -78
  179. data/test/test_code.rb +0 -201
  180. data/test/test_command.rb +0 -712
  181. data/test/test_command_helpers.rb +0 -9
  182. data/test/test_command_integration.rb +0 -668
  183. data/test/test_command_set.rb +0 -610
  184. data/test/test_completion.rb +0 -62
  185. data/test/test_control_d_handler.rb +0 -45
  186. data/test/test_default_commands/example.erb +0 -5
  187. data/test/test_default_commands/test_cd.rb +0 -318
  188. data/test/test_default_commands/test_context.rb +0 -280
  189. data/test/test_default_commands/test_documentation.rb +0 -314
  190. data/test/test_default_commands/test_find_method.rb +0 -50
  191. data/test/test_default_commands/test_gems.rb +0 -18
  192. data/test/test_default_commands/test_help.rb +0 -57
  193. data/test/test_default_commands/test_input.rb +0 -428
  194. data/test/test_default_commands/test_introspection.rb +0 -511
  195. data/test/test_default_commands/test_ls.rb +0 -151
  196. data/test/test_default_commands/test_shell.rb +0 -343
  197. data/test/test_default_commands/test_show_source.rb +0 -432
  198. data/test/test_exception_whitelist.rb +0 -21
  199. data/test/test_history_array.rb +0 -65
  200. data/test/test_hooks.rb +0 -521
  201. data/test/test_indent.rb +0 -277
  202. data/test/test_input_stack.rb +0 -86
  203. data/test/test_method.rb +0 -401
  204. data/test/test_pry.rb +0 -463
  205. data/test/test_pry_defaults.rb +0 -419
  206. data/test/test_pry_history.rb +0 -84
  207. data/test/test_pry_output.rb +0 -41
  208. data/test/test_sticky_locals.rb +0 -155
  209. data/test/test_syntax_checking.rb +0 -65
  210. data/test/test_wrapped_module.rb +0 -174
  211. data/test/testrc +0 -2
  212. data/test/testrcbad +0 -2
  213. data/wiki/Customizing-pry.md +0 -397
  214. data/wiki/Home.md +0 -4
@@ -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