pry 0.9.10pre1-i386-mingw32 → 0.9.11-i386-mingw32

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 (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
@@ -2,3 +2,4 @@ require "pry/helpers/base_helpers"
2
2
  require "pry/helpers/options_helpers"
3
3
  require "pry/helpers/command_helpers"
4
4
  require "pry/helpers/text"
5
+ require "pry/helpers/table"
@@ -15,16 +15,20 @@ class Pry
15
15
  end
16
16
  end
17
17
 
18
- def find_command(name)
19
- command_match = commands.find { |_, command| command.options[:listing] == name }
20
-
21
- return command_match.last if command_match
22
- nil
23
- end
24
-
25
- def gem_installed?(gem_name)
26
- require 'rubygems'
27
- Gem::Specification.respond_to?(:find_all_by_name) ? !Gem::Specification.find_all_by_name(gem_name).empty? : Gem.source_index.find_name(gem_name).first
18
+ # Acts like send but ignores any methods defined below Object or Class in the
19
+ # inheritance hierarchy.
20
+ # This is required to introspect methods on objects like Net::HTTP::Get that
21
+ # have overridden the `method` method.
22
+ def safe_send(obj, method, *args, &block)
23
+ (Module === obj ? Module : Object).instance_method(method).bind(obj).call(*args, &block)
24
+ end
25
+ public :safe_send
26
+
27
+ def find_command(name, set = Pry::Commands)
28
+ command_match = set.find do |_, command|
29
+ (listing = command.options[:listing]) == name && listing != nil
30
+ end
31
+ command_match.last if command_match
28
32
  end
29
33
 
30
34
  def not_a_real_file?(file)
@@ -34,11 +38,11 @@ class Pry
34
38
  def command_dependencies_met?(options)
35
39
  return true if !options[:requires_gem]
36
40
  Array(options[:requires_gem]).all? do |g|
37
- gem_installed?(g)
41
+ Rubygem.installed?(g)
38
42
  end
39
43
  end
40
44
 
41
- def set_file_and_dir_locals(file_name)
45
+ def set_file_and_dir_locals(file_name, _pry_=_pry_(), target=target())
42
46
  return if !target or !file_name
43
47
  _pry_.last_file = File.expand_path(file_name)
44
48
  _pry_.inject_local("_file_", _pry_.last_file, target)
@@ -47,30 +51,8 @@ class Pry
47
51
  _pry_.inject_local("_dir_", _pry_.last_dir, target)
48
52
  end
49
53
 
50
- def stub_proc(name, options)
51
- gems_needed = Array(options[:requires_gem])
52
- gems_not_installed = gems_needed.select { |g| !gem_installed?(g) }
53
- proc do
54
- output.puts "\nThe command '#{name}' requires the following gems to be installed: #{(gems_needed.join(", "))}"
55
- output.puts "-"
56
- output.puts "Command not available due to dependency on gems: `#{gems_not_installed.join(", ")}` not being met."
57
- output.puts "-"
58
- output.puts "Type `install #{name}` to install the required gems and activate this command."
59
- end
60
- end
61
-
62
- def create_command_stub(names, description, options, block)
63
- Array(names).each do |name|
64
- commands[name] = {
65
- :description => "Not available. Execute #{(name)} command for more information.",
66
- :action => stub_proc(name, options),
67
- :stub_info => options
68
- }
69
- end
70
- end
71
-
72
54
  def use_ansi_codes?
73
- windows_ansi? || ENV['TERM'] && ENV['TERM'] != "dumb"
55
+ windows_ansi? || ENV['TERM'] && ENV['TERM'] != "dumb"
74
56
  end
75
57
 
76
58
  def colorize_code(code)
@@ -91,10 +73,6 @@ class Pry
91
73
  Pry.color ? "\e[1m#{text}\e[0m": text
92
74
  end
93
75
 
94
- def page_size
95
- 27
96
- end
97
-
98
76
  # have fun on the Windows platform.
99
77
  def windows?
100
78
  RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
@@ -123,103 +101,95 @@ class Pry
123
101
  RUBY_VERSION =~ /1.9/ && RbConfig::CONFIG['ruby_install_name'] == 'ruby'
124
102
  end
125
103
 
126
- # a simple pager for systems without `less`. A la windows.
127
- def simple_pager(text, output=output())
128
- text_array = text.lines.to_a
129
- text_array.each_slice(page_size) do |chunk|
130
- output.puts chunk.join
131
- break if chunk.size < page_size
132
- if text_array.size > page_size
133
- output.puts "\n<page break> --- Press enter to continue ( q<enter> to break ) --- <page break>"
134
- break if $stdin.gets.chomp == "q"
135
- end
136
- end
137
- end
138
-
139
104
  # Try to use `less` for paging, if it fails then use
140
105
  # simple_pager. Also do not page if Pry.pager is falsey
141
- # FIXME! Another JRuby hack
142
106
  def stagger_output(text, out = nil)
143
107
  out ||= case
144
- when respond_to?(:output)
145
- # Mixin.
146
- output
147
- when Pry.respond_to?(:output)
148
- # Parent.
149
- Pry.output
150
- else
151
- # Sys.
152
- $stdout
153
- end
154
-
155
- if text.lines.count < page_size || !Pry.pager
108
+ when respond_to?(:output)
109
+ # Mixin.
110
+ output
111
+ when Pry.respond_to?(:output)
112
+ # Parent.
113
+ Pry.output
114
+ else
115
+ # Sys.
116
+ $stdout
117
+ end
118
+
119
+ if text.lines.count < Pry::Pager.page_size || !Pry.pager
156
120
  out.puts text
157
- return
158
- end
159
-
160
- # FIXME! Another JRuby hack
161
- if jruby?
162
- simple_pager(text, out)
163
121
  else
164
- lesspipe { |less| less.puts text }
122
+ Pry::Pager.page(text)
165
123
  end
166
124
  rescue Errno::ENOENT
167
- simple_pager(text, out)
125
+ Pry::Pager.page(text, :simple)
168
126
  rescue Errno::EPIPE
169
127
  end
170
128
 
171
- #
172
- # Create scrollable output via less!
173
- #
174
- # This command runs `less` in a subprocess, and gives you the IO to its STDIN pipe
175
- # so that you can communicate with it.
176
- #
177
- # Example:
178
- #
179
- # lesspipe do |less|
180
- # 50.times { less.puts "Hi mom!" }
181
- # end
182
- #
183
- # The default less parameters are:
184
- # * Allow colour
185
- # * Don't wrap lines longer than the screen
186
- # * Quit immediately (without paging) if there's less than one screen of text.
187
- #
188
- # You can change these options by passing a hash to `lesspipe`, like so:
189
- #
190
- # lesspipe(:wrap=>false) { |less| less.puts essay.to_s }
191
- #
192
- # It accepts the following boolean options:
193
- # :color => Allow ANSI colour codes?
194
- # :wrap => Wrap long lines?
195
- # :always => Always page, even if there's less than one page of text?
196
- #
197
- def lesspipe(*args)
198
- if args.any? and args.last.is_a?(Hash)
199
- options = args.pop
200
- else
201
- options = {}
202
- end
129
+ # @param [String] arg_string The object path expressed as a string.
130
+ # @param [Pry] _pry_ The relevant Pry instance.
131
+ # @param [Array<Binding>] old_stack The state of the old binding stack
132
+ # @return [Array<Array<Binding>, Array<Binding>>] An array
133
+ # containing two elements: The new `binding_stack` and the old `binding_stack`.
134
+ def context_from_object_path(arg_string, _pry_=nil, old_stack=[])
203
135
 
204
- output = args.first if args.any?
136
+ # Extract command arguments. Delete blank arguments like " ", but
137
+ # don't delete empty strings like "".
138
+ path = arg_string.split(/\//).delete_if { |a| a =~ /\A\s+\z/ }
139
+ stack = _pry_.binding_stack.dup
140
+ state_old_stack = old_stack
205
141
 
206
- params = []
207
- params << "-R" unless options[:color] == false
208
- params << "-S" unless options[:wrap] == true
209
- params << "-F" unless options[:always] == true
210
- if options[:tail] == true
211
- params << "+\\>"
212
- $stderr.puts "Seeking to end of stream..."
142
+ # Special case when we only get a single "/", return to root.
143
+ if path.empty?
144
+ state_old_stack = stack.dup unless old_stack.empty?
145
+ stack = [stack.first]
213
146
  end
214
- params << "-X"
215
147
 
216
- IO.popen("less #{params * ' '}", "w") do |less|
217
- if output
218
- less.puts output
219
- else
220
- yield less
148
+ path.each_with_index do |context, i|
149
+ begin
150
+ case context.chomp
151
+ when ""
152
+ state_old_stack = stack.dup
153
+ stack = [stack.first]
154
+ when "::"
155
+ state_old_stack = stack.dup
156
+ stack.push(TOPLEVEL_BINDING)
157
+ when "."
158
+ next
159
+ when ".."
160
+ unless stack.size == 1
161
+ # Don't rewrite old_stack if we're in complex expression
162
+ # (e.g.: `cd 1/2/3/../4).
163
+ state_old_stack = stack.dup if path.first == ".."
164
+ stack.pop
165
+ end
166
+ when "-"
167
+ unless old_stack.empty?
168
+ # Interchange current stack and old stack with each other.
169
+ stack, state_old_stack = state_old_stack, stack
170
+ end
171
+ else
172
+ state_old_stack = stack.dup if i == 0
173
+ stack.push(Pry.binding_for(stack.last.eval(context)))
174
+ end
175
+
176
+ rescue RescuableException => e
177
+ # Restore old stack to its initial values.
178
+ state_old_stack = old_stack
179
+
180
+ msg = [
181
+ "Bad object path: #{arg_string}.",
182
+ "Failed trying to resolve: #{context}.",
183
+ e.inspect
184
+ ].join(' ')
185
+
186
+ CommandError.new(msg).tap do |err|
187
+ err.set_backtrace e.backtrace
188
+ raise err
189
+ end
221
190
  end
222
191
  end
192
+ return stack, state_old_stack
223
193
  end
224
194
 
225
195
  end
@@ -23,45 +23,29 @@ class Pry
23
23
  end
24
24
  end
25
25
 
26
- # Return the file and line for a Binding.
27
- # @param [Binding] target The binding
28
- # @return [Array] The file and line
29
- def file_and_line_from_binding(target)
30
- file = target.eval('__FILE__')
31
- line_num = target.eval('__LINE__')
32
- if rbx?
33
- if !target.instance_variable_defined?(:@__actual_file__)
34
- target.instance_variable_set(:@__actual_file__, RbxPath.convert_path_to_full(target.variables.method.file.to_s))
35
- end
36
- file = target.instance_variable_get(:@__actual_file__).to_s
37
- end
38
-
39
- [file, line_num]
40
- end
41
-
42
26
  def internal_binding?(target)
43
- m = target.eval("__method__").to_s
27
+ m = target.eval("::Kernel.__method__").to_s
44
28
  # class_eval is here because of http://jira.codehaus.org/browse/JRUBY-6753
45
- ["__binding__", "__binding_impl__", "class_eval"].include?(m)
29
+ ["__binding__", "__pry__", "class_eval"].include?(m)
46
30
  end
47
31
 
48
32
  def get_method_or_raise(name, target, opts={}, omit_help=false)
49
33
  meth = Pry::Method.from_str(name, target, opts)
50
34
 
51
35
  if name && !meth
52
- command_error("The method '#{name}' could not be found.", omit_help)
36
+ command_error("The method '#{name}' could not be found.", omit_help, MethodNotFound)
53
37
  end
54
38
 
55
39
  (opts[:super] || 0).times do
56
40
  if meth.super
57
41
  meth = meth.super
58
42
  else
59
- command_error("'#{meth.name_with_owner}' has no super method.", omit_help)
43
+ command_error("'#{meth.name_with_owner}' has no super method.", omit_help, MethodNotFound)
60
44
  end
61
45
  end
62
46
 
63
47
  if !meth || (!name && internal_binding?(target))
64
- command_error("No method name given, and context is not a method.", omit_help, NonMethodContextError)
48
+ command_error("No method name given, and context is not a method.", omit_help, MethodNotFound)
65
49
  end
66
50
 
67
51
  set_file_and_dir_locals(meth.source_file)
@@ -73,104 +57,6 @@ class Pry
73
57
  raise klass, message
74
58
  end
75
59
 
76
- def make_header(meth, content=meth.source)
77
- header = "\n#{Pry::Helpers::Text.bold('From:')} #{meth.source_file} "
78
-
79
- if meth.source_type == :c
80
- header << "(C Method):\n"
81
- else
82
- header << "@ line #{meth.source_line}:\n"
83
- end
84
-
85
- header << "#{Pry::Helpers::Text.bold("Number of lines:")} #{content.each_line.count.to_s}\n"
86
- end
87
-
88
- def invoke_editor(file, line, reloading)
89
- raise CommandError, "Please set Pry.config.editor or export $VISUAL or $EDITOR" unless Pry.config.editor
90
- if Pry.config.editor.respond_to?(:call)
91
- args = [file, line, reloading][0...(Pry.config.editor.arity)]
92
- editor_invocation = Pry.config.editor.call(*args)
93
- else
94
- editor_invocation = "#{Pry.config.editor} #{blocking_flag_for_editor(reloading)} #{start_line_syntax_for_editor(file, line)}"
95
- end
96
- return nil unless editor_invocation
97
-
98
- if jruby?
99
- begin
100
- require 'spoon'
101
- pid = Spoon.spawnp(*editor_invocation.split)
102
- Process.waitpid(pid)
103
- rescue FFI::NotFoundError
104
- system(editor_invocation)
105
- end
106
- else
107
- # Note we dont want to use Pry.config.system here as that
108
- # may be invoked non-interactively (i.e via Open4), whereas we want to
109
- # ensure the editor is always interactive
110
- system(editor_invocation) or raise CommandError, "`#{editor_invocation}` gave exit status: #{$?.exitstatus}"
111
- end
112
- end
113
-
114
- # Some editors that run outside the terminal allow you to control whether or
115
- # not to block the process from which they were launched (in this case, Pry).
116
- # For those editors, return the flag that produces the desired behavior.
117
- def blocking_flag_for_editor(block)
118
- case editor_name
119
- when /^emacsclient/
120
- '--no-wait' unless block
121
- when /^[gm]vim/
122
- '--nofork' if block
123
- when /^jedit/
124
- '-wait' if block
125
- when /^mate/, /^subl/
126
- '-w' if block
127
- end
128
- end
129
-
130
- # Return the syntax for a given editor for starting the editor
131
- # and moving to a particular line within that file
132
- def start_line_syntax_for_editor(file_name, line_number)
133
- if windows?
134
- file_name = file_name.gsub(/\//, '\\')
135
- end
136
-
137
- # special case for 1st line
138
- return file_name if line_number <= 1
139
-
140
- case editor_name
141
- when /^[gm]?vi/, /^emacs/, /^nano/, /^pico/, /^gedit/, /^kate/
142
- "+#{line_number} #{file_name}"
143
- when /^mate/, /^geany/
144
- "-l #{line_number} #{file_name}"
145
- when /^subl/
146
- "#{file_name}:#{line_number}"
147
- when /^uedit32/
148
- "#{file_name}/#{line_number}"
149
- when /^jedit/
150
- "#{file_name} +line:#{line_number}"
151
- else
152
- if windows?
153
- "#{file_name}"
154
- else
155
- "+#{line_number} #{file_name}"
156
- end
157
- end
158
- end
159
-
160
- # Get the name of the binary that Pry.config.editor points to.
161
- #
162
- # This is useful for deciding which flags we pass to the editor as
163
- # we can just use the program's name and ignore any absolute paths.
164
- #
165
- # @example
166
- # Pry.config.editor="/home/conrad/bin/textmate -w"
167
- # editor_name
168
- # # => textmate
169
- #
170
- def editor_name
171
- File.basename(Pry.config.editor).split(" ").first
172
- end
173
-
174
60
  # Remove any common leading whitespace from every line in `text`.
175
61
  #
176
62
  # This can be used to make a HEREDOC line up with the left margin, without
@@ -193,7 +79,7 @@ class Pry
193
79
  #
194
80
  # @param [String] text The text from which to remove indentation
195
81
  # @return [String] The text with indentation stripped.
196
- def unindent(text)
82
+ def unindent(text, left_padding = 0)
197
83
  # Empty blank lines
198
84
  text = text.sub(/^[ \t]+$/, '')
199
85
 
@@ -208,7 +94,7 @@ class Pry
208
94
  end
209
95
  end
210
96
 
211
- text.gsub(/^#{margin}/, '')
97
+ text.gsub(/^#{margin}/, ' ' * left_padding)
212
98
  end
213
99
 
214
100
  # Restrict a string to the given range of lines (1-indexed)
@@ -262,6 +148,5 @@ class Pry
262
148
  Range.new(a, b)
263
149
  end
264
150
  end
265
-
266
151
  end
267
152
  end
@@ -0,0 +1,100 @@
1
+ class Pry
2
+ module Helpers
3
+ def self.tablify_to_screen_width(things)
4
+ things = things.compact
5
+
6
+ if TerminalInfo.screen_size.nil?
7
+ return things.join(Pry.config.ls.separator)
8
+ end
9
+
10
+ screen_width = (TerminalInfo.screen_size || [25, 80])[1]
11
+ tablify(things, screen_width)
12
+ end
13
+
14
+ def self.tablify(things, line_length)
15
+ table = Table.new(things, :column_count => things.size)
16
+ table.column_count -= 1 until 0 == table.column_count or
17
+ table.fits_on_line?(line_length)
18
+ table
19
+ end
20
+
21
+ class Table
22
+ attr_reader :items, :column_count
23
+ def initialize items, args = {}
24
+ @column_count = args[:column_count]
25
+ self.items = items
26
+ end
27
+
28
+ def to_s
29
+ rows_to_s.join("\n")
30
+ end
31
+
32
+ def rows_to_s style = :color_on
33
+ widths = columns.map{|e| _max_width(e)}
34
+ @rows_without_colors.map do |r|
35
+ padded = []
36
+ r.each_with_index do |e,i|
37
+ next unless e
38
+ item = e.ljust(widths[i])
39
+ item.sub! e, _recall_color_for(e) if :color_on == style
40
+ padded << item
41
+ end
42
+ padded.join(Pry.config.ls.separator)
43
+ end
44
+ end
45
+
46
+ def items= items
47
+ @items = items
48
+ _rebuild_colorless_cache
49
+ _recolumn
50
+ items
51
+ end
52
+
53
+ def column_count= n
54
+ @column_count = n
55
+ _recolumn
56
+ end
57
+
58
+ def fits_on_line? line_length
59
+ _max_width(rows_to_s :no_color) <= line_length
60
+ end
61
+
62
+ def columns
63
+ @rows_without_colors.transpose
64
+ end
65
+
66
+ def ==(other); items == other.to_a end
67
+ def to_a; items.to_a end
68
+
69
+ private
70
+ def _max_width(things)
71
+ things.compact.map(&:size).max || 0
72
+ end
73
+
74
+ def _rebuild_colorless_cache
75
+ @colorless_cache = {}
76
+ @plain_items = []
77
+ items.map do |e|
78
+ plain = Pry::Helpers::Text.strip_color(e)
79
+ @colorless_cache[plain] = e
80
+ @plain_items << plain
81
+ end
82
+ end
83
+
84
+ def _recolumn
85
+ @rows_without_colors = []
86
+ return if items.size.zero?
87
+ row_count = (items.size.to_f/column_count).ceil
88
+ row_count.times do |i|
89
+ row_indices = (0...column_count).map{|e| row_count*e+i}
90
+ @rows_without_colors << row_indices.map{|e| @plain_items[e]}
91
+ end
92
+ end
93
+
94
+ def _recall_color_for thing
95
+ @colorless_cache[thing]
96
+ end
97
+ end
98
+
99
+ end
100
+ end