pry 0.10.pre.1-i386-mswin32 → 0.10.0.pre3-i386-mswin32

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 (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 +122 -183
  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,29 +1,6 @@
1
- require "pry/default_commands/misc"
2
- require "pry/default_commands/help"
3
- require "pry/default_commands/gems"
4
- require "pry/default_commands/context"
5
- require "pry/default_commands/commands"
6
- require "pry/default_commands/input_and_output"
7
- require "pry/default_commands/introspection"
8
- require "pry/default_commands/editing"
9
- require "pry/default_commands/navigating_pry"
10
- require "pry/default_commands/easter_eggs"
1
+ # Default commands used by Pry.
2
+ Pry::Commands = Pry::CommandSet.new
11
3
 
12
- require "pry/extended_commands/experimental"
13
-
14
- class Pry
15
-
16
- # Default commands used by Pry.
17
- Commands = Pry::CommandSet.new do
18
- import DefaultCommands::Misc
19
- import DefaultCommands::Help
20
- import DefaultCommands::Gems
21
- import DefaultCommands::Context
22
- import DefaultCommands::NavigatingPry
23
- import DefaultCommands::Editing
24
- import DefaultCommands::InputAndOutput
25
- import DefaultCommands::Introspection
26
- import DefaultCommands::EasterEggs
27
- import DefaultCommands::Commands
28
- end
4
+ Dir[File.expand_path('../commands', __FILE__) << '/*.rb'].each do |file|
5
+ require file
29
6
  end
@@ -0,0 +1,99 @@
1
+ class Pry
2
+ class Command::AmendLine < Pry::ClassCommand
3
+ match(/amend-line(?: (-?\d+)(?:\.\.(-?\d+))?)?/)
4
+ group 'Editing'
5
+ description 'Amend a line of input in multi-line mode.'
6
+ command_options :interpolate => false, :listing => 'amend-line'
7
+
8
+ banner <<-'BANNER'
9
+ Amend a line of input in multi-line mode. `amend-line N`, where the N represents
10
+ line to replace. Can also specify a range of lines using `amend-line N..M`
11
+ syntax. Passing "!" as replacement content deletes the line(s) instead.
12
+
13
+ amend-line 1 puts 'new' # replace line 1
14
+ amend-line 1..4 ! # delete lines 1..4
15
+ amend-line 3 >puts 'bye' # insert before line 3
16
+ amend-line puts 'appended' # no line number modifies immediately preceding line
17
+ BANNER
18
+
19
+ def process
20
+ raise CommandError, "No input to amend." if eval_string.empty?
21
+
22
+ eval_string.replace amended_input(eval_string)
23
+ run "fix-indent"
24
+ run "show-input"
25
+ end
26
+
27
+ private
28
+
29
+ # @param [String] string The string to amend.
30
+ # @return [String] A new string with the amendments applied to it.
31
+ def amended_input(string)
32
+ input_array = eval_string.each_line.to_a
33
+
34
+ if arg_string == "!"
35
+ delete_from_array(input_array, line_range)
36
+ elsif arg_string.start_with?(">")
37
+ insert_into_array(input_array, line_range)
38
+ else
39
+ replace_in_array(input_array, line_range)
40
+ end
41
+
42
+ input_array.join
43
+ end
44
+
45
+ def delete_from_array(array, range)
46
+ array.slice!(range)
47
+ end
48
+
49
+ def insert_into_array(array, range)
50
+ insert_slot = Array(range).first
51
+ array.insert(insert_slot, arg_string[1..-1] << "\n")
52
+ end
53
+
54
+ def replace_in_array(array, range)
55
+ array[range] = arg_string + "\n"
56
+ end
57
+
58
+ # @return [Fixnum] The number of lines currently in `eval_string` (the input buffer).
59
+ def line_count
60
+ eval_string.lines.count
61
+ end
62
+
63
+ # Returns the (one-indexed) start and end lines given by the user.
64
+ # The lines in this range will be affected by the `amend-line`.
65
+ # Returns `nil` if no lines were specified by the user.
66
+ # @return [Array<Fixnum>, nil]
67
+ def start_and_end_line_number
68
+ start_line_number, end_line_number = args
69
+ end_line_number ||= start_line_number.to_i
70
+
71
+ [start_line_number.to_i, end_line_number.to_i] if start_line_number
72
+ end
73
+
74
+ # Takes two numbers that are 1-indexed, and returns a range (or
75
+ # number) that is 0-indexed. 1-indexed means the first element is
76
+ # indentified by 1 rather than by 0 (as is the case for Ruby arrays).
77
+ # @param [Fixnum] start_line_number One-indexed number.
78
+ # @param [Fixnum] end_line_number One-indexed number.
79
+ # @return [Range] The zero-indexed range.
80
+ def zero_indexed_range_from_one_indexed_numbers(start_line_number, end_line_number)
81
+ # FIXME: one_index_number is a horrible name for this method
82
+ one_index_number(start_line_number)..one_index_number(end_line_number)
83
+ end
84
+
85
+ # The lines (or line) that will be modified by the `amend-line`.
86
+ # @return [Range, Fixnum] The lines or line.
87
+ def line_range
88
+ start_line_number, end_line_number = start_and_end_line_number
89
+ if start_line_number
90
+ zero_indexed_range_from_one_indexed_numbers(start_line_number,
91
+ end_line_number)
92
+ else
93
+ line_count - 1
94
+ end
95
+ end
96
+ end
97
+
98
+ Pry::Commands.add_command(Pry::Command::AmendLine)
99
+ end
@@ -0,0 +1,20 @@
1
+ class Pry
2
+ class Command::Bang < Pry::ClassCommand
3
+ match /^\s*!\s*$/
4
+ group 'Editing'
5
+ description 'Clear the input buffer.'
6
+ command_options :use_prefix => false
7
+
8
+ banner <<-'BANNER'
9
+ Clear the input buffer. Useful if the parsing process goes wrong and you get
10
+ stuck in the read loop.
11
+ BANNER
12
+
13
+ def process
14
+ output.puts 'Input buffer cleared!'
15
+ eval_string.replace('')
16
+ end
17
+ end
18
+
19
+ Pry::Commands.add_command(Pry::Command::Bang)
20
+ end
@@ -0,0 +1,17 @@
1
+ class Pry
2
+ class Command::BangPry < Pry::ClassCommand
3
+ match '!pry'
4
+ group 'Navigating Pry'
5
+ description 'Start a Pry session on current self.'
6
+
7
+ banner <<-'BANNER'
8
+ Start a Pry session on current self. Also works mid multi-line expression.
9
+ BANNER
10
+
11
+ def process
12
+ target.pry
13
+ end
14
+ end
15
+
16
+ Pry::Commands.add_command(Pry::Command::BangPry)
17
+ end
@@ -0,0 +1,62 @@
1
+ class Pry
2
+ class Command::Cat < Pry::ClassCommand
3
+ require 'pry/commands/cat/abstract_formatter.rb'
4
+ require 'pry/commands/cat/input_expression_formatter.rb'
5
+ require 'pry/commands/cat/exception_formatter.rb'
6
+ require 'pry/commands/cat/file_formatter.rb'
7
+
8
+ match 'cat'
9
+ group 'Input and Output'
10
+ description "Show code from a file, Pry's input buffer, or the last exception."
11
+
12
+ banner <<-'BANNER'
13
+ Usage: cat FILE
14
+ cat --ex [STACK_INDEX]
15
+ cat --in [INPUT_INDEX_OR_RANGE]
16
+
17
+ `cat` is capable of showing part or all of a source file, the context of the
18
+ last exception, or an expression from Pry's input history.
19
+
20
+ `cat --ex` defaults to showing the lines surrounding the location of the last
21
+ exception. Invoking it more than once travels up the exception's backtrace, and
22
+ providing a number shows the context of the given index of the backtrace.
23
+ BANNER
24
+
25
+ def options(opt)
26
+ opt.on :ex, "Show the context of the last exception", :optional_argument => true, :as => Integer
27
+ opt.on :i, :in, "Show one or more entries from Pry's expression history", :optional_argument => true, :as => Range, :default => -5..-1
28
+ opt.on :s, :start, "Starting line (defaults to the first line)", :optional_argument => true, :as => Integer
29
+ opt.on :e, :end, "Ending line (defaults to the last line)", :optional_argument => true, :as => Integer
30
+ opt.on :l, :'line-numbers', "Show line numbers"
31
+ opt.on :t, :type, "The file type for syntax highlighting (e.g., 'ruby' or 'python')", :argument => true, :as => Symbol
32
+ end
33
+
34
+ def process
35
+ output = case
36
+ when opts.present?(:ex)
37
+ ExceptionFormatter.new(_pry_.last_exception, _pry_, opts).format
38
+ when opts.present?(:in)
39
+ InputExpressionFormatter.new(_pry_.input_array, opts).format
40
+ else
41
+ FileFormatter.new(args.first, _pry_, opts).format
42
+ end
43
+
44
+ _pry_.pager.page output
45
+ end
46
+
47
+ def complete(search)
48
+ super | load_path_completions
49
+ end
50
+
51
+ def load_path_completions
52
+ $LOAD_PATH.flat_map do |path|
53
+ Dir[path + '/**/*'].map { |f|
54
+ next if File.directory?(f)
55
+ f.sub!(path + '/', '')
56
+ }
57
+ end
58
+ end
59
+ end
60
+
61
+ Pry::Commands.add_command(Pry::Command::Cat)
62
+ end
@@ -0,0 +1,27 @@
1
+ class Pry
2
+ class Command::Cat
3
+ class AbstractFormatter
4
+ include Pry::Helpers::CommandHelpers
5
+ include Pry::Helpers::BaseHelpers
6
+
7
+ private
8
+ def decorate(content)
9
+ content.code_type = code_type
10
+ content.between(*between_lines).
11
+ with_line_numbers(use_line_numbers?)
12
+ end
13
+
14
+ def code_type
15
+ opts[:type] || :ruby
16
+ end
17
+
18
+ def use_line_numbers?
19
+ opts.present?(:'line-numbers') || opts.present?(:ex)
20
+ end
21
+
22
+ def between_lines
23
+ [opts[:start] || 1, opts[:end] || -1]
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,77 @@
1
+ class Pry
2
+ class Command::Cat
3
+ class ExceptionFormatter < AbstractFormatter
4
+ attr_reader :ex
5
+ attr_reader :opts
6
+ attr_reader :_pry_
7
+
8
+ def initialize(exception, _pry_, opts)
9
+ @ex = exception
10
+ @opts = opts
11
+ @_pry_ = _pry_
12
+ end
13
+
14
+ def format
15
+ check_for_errors
16
+ set_file_and_dir_locals(backtrace_file, _pry_, _pry_.current_context)
17
+ code = decorate(Pry::Code.from_file(backtrace_file).
18
+ between(*start_and_end_line_for_code_window).
19
+ with_marker(backtrace_line))
20
+ "#{header}#{code}"
21
+ end
22
+
23
+ private
24
+
25
+ def code_window_size
26
+ _pry_.config.default_window_size || 5
27
+ end
28
+
29
+ def backtrace_level
30
+ return @backtrace_level if @backtrace_level
31
+
32
+ bl = if opts[:ex].nil?
33
+ ex.bt_index
34
+ else
35
+ ex.bt_index = absolute_index_number(opts[:ex], ex.backtrace.size)
36
+ end
37
+
38
+ increment_backtrace_level
39
+ @backtrace_level = bl
40
+ end
41
+
42
+ def increment_backtrace_level
43
+ ex.inc_bt_index
44
+ end
45
+
46
+ def backtrace_file
47
+ Array(ex.bt_source_location_for(backtrace_level)).first
48
+ end
49
+
50
+ def backtrace_line
51
+ Array(ex.bt_source_location_for(backtrace_level)).last
52
+ end
53
+
54
+ def check_for_errors
55
+ raise CommandError, "No exception found." unless ex
56
+ raise CommandError, "The given backtrace level is out of bounds." unless backtrace_file
57
+ end
58
+
59
+ def start_and_end_line_for_code_window
60
+ start_line = backtrace_line - code_window_size
61
+ start_line = 1 if start_line < 1
62
+
63
+ [start_line, backtrace_line + code_window_size]
64
+ end
65
+
66
+ def header
67
+ unindent %{
68
+ #{Helpers::Text.bold 'Exception:'} #{ex.class}: #{ex.message}
69
+ --
70
+ #{Helpers::Text.bold('From:')} #{backtrace_file} @ line #{backtrace_line} @ #{Helpers::Text.bold("level: #{backtrace_level}")} of backtrace (of #{ex.backtrace.size - 1}).
71
+
72
+ }
73
+ end
74
+
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,67 @@
1
+ class Pry
2
+ class Command::Cat
3
+ class FileFormatter < AbstractFormatter
4
+ attr_reader :file_with_embedded_line
5
+ attr_reader :opts
6
+ attr_reader :_pry_
7
+
8
+ def initialize(file_with_embedded_line, _pry_, opts)
9
+ @file_with_embedded_line = file_with_embedded_line
10
+ @opts = opts
11
+ @_pry_ = _pry_
12
+ @code_from_file = Pry::Code.from_file(file_name)
13
+ end
14
+
15
+ def format
16
+ raise CommandError, "Must provide a filename, --in, or --ex." if !file_with_embedded_line
17
+
18
+ set_file_and_dir_locals(file_name, _pry_, _pry_.current_context)
19
+ decorate(@code_from_file)
20
+ end
21
+
22
+ def file_and_line
23
+ file_name, line_num = file_with_embedded_line.split(/:(?!\/|\\)/)
24
+
25
+ [file_name, line_num ? line_num.to_i : nil]
26
+ end
27
+
28
+ private
29
+
30
+ def file_name
31
+ file_and_line.first
32
+ end
33
+
34
+ def line_number
35
+ file_and_line.last
36
+ end
37
+
38
+ def code_window_size
39
+ _pry_.config.default_window_size || 7
40
+ end
41
+
42
+ def decorate(content)
43
+ line_number ? super.around(line_number, code_window_size) : super
44
+ end
45
+
46
+ def code_type
47
+ opts[:type] || detect_code_type_from_file(file_name)
48
+ end
49
+
50
+ def detect_code_type_from_file(file_name)
51
+ code_type = @code_from_file.code_type
52
+
53
+ if code_type == :unknown
54
+ name, ext = File.basename(file_name).split('.', 2)
55
+ case name
56
+ when "Rakefile", "Gemfile"
57
+ :ruby
58
+ else
59
+ :text
60
+ end
61
+ else
62
+ code_type
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,43 @@
1
+ class Pry
2
+ class Command::Cat
3
+ class InputExpressionFormatter < AbstractFormatter
4
+ attr_accessor :input_expressions
5
+ attr_accessor :opts
6
+
7
+ def initialize(input_expressions, opts)
8
+ @input_expressions = input_expressions
9
+ @opts = opts
10
+ end
11
+
12
+ def format
13
+ raise CommandError, "No input expressions!" if numbered_input_items.length < 1
14
+
15
+ if numbered_input_items.length > 1
16
+ content = ""
17
+ numbered_input_items.each do |i, s|
18
+ content << "#{Helpers::Text.bold(i.to_s)}:\n" << decorate(Pry::Code(s).with_indentation(2)).to_s
19
+ end
20
+
21
+ content
22
+ else
23
+ decorate(Pry::Code(selected_input_items.first))
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def selected_input_items
30
+ input_expressions[normalized_expression_range] || []
31
+ end
32
+
33
+ def numbered_input_items
34
+ @numbered_input_items ||= normalized_expression_range.zip(selected_input_items).
35
+ reject { |_, s| s.nil? || s == "" }
36
+ end
37
+
38
+ def normalized_expression_range
39
+ absolute_index_range(opts[:i], input_expressions.length)
40
+ end
41
+ end
42
+ end
43
+ end