pry 0.9.6.2-i386-mswin32 → 0.9.7-i386-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/.gitignore +6 -0
  2. data/CHANGELOG +19 -1
  3. data/CONTRIBUTORS +22 -16
  4. data/Rakefile +12 -6
  5. data/bin/pry +15 -12
  6. data/lib/pry.rb +39 -28
  7. data/lib/pry/command_context.rb +1 -0
  8. data/lib/pry/command_processor.rb +9 -2
  9. data/lib/pry/command_set.rb +7 -0
  10. data/lib/pry/config.rb +8 -0
  11. data/lib/pry/default_commands/basic.rb +7 -10
  12. data/lib/pry/default_commands/context.rb +36 -26
  13. data/lib/pry/default_commands/documentation.rb +31 -123
  14. data/lib/pry/default_commands/gems.rb +9 -4
  15. data/lib/pry/default_commands/input.rb +21 -11
  16. data/lib/pry/default_commands/introspection.rb +79 -88
  17. data/lib/pry/default_commands/ls.rb +165 -176
  18. data/lib/pry/default_commands/shell.rb +8 -8
  19. data/lib/pry/extended_commands/experimental.rb +1 -5
  20. data/lib/pry/extended_commands/user_command_api.rb +17 -5
  21. data/lib/pry/helpers.rb +1 -0
  22. data/lib/pry/helpers/base_helpers.rb +5 -1
  23. data/lib/pry/helpers/command_helpers.rb +22 -241
  24. data/lib/pry/helpers/options_helpers.rb +58 -0
  25. data/lib/pry/helpers/text.rb +10 -4
  26. data/lib/pry/history.rb +1 -1
  27. data/lib/pry/indent.rb +205 -0
  28. data/lib/pry/method.rb +412 -0
  29. data/lib/pry/pry_class.rb +56 -15
  30. data/lib/pry/pry_instance.rb +63 -16
  31. data/lib/pry/rbx_method.rb +20 -0
  32. data/lib/pry/rbx_path.rb +34 -0
  33. data/lib/pry/version.rb +1 -1
  34. data/pry.gemspec +16 -16
  35. data/test/helper.rb +8 -4
  36. data/test/test_command_helpers.rb +1 -69
  37. data/test/test_command_set.rb +29 -28
  38. data/test/test_default_commands/test_documentation.rb +23 -10
  39. data/test/test_default_commands/test_introspection.rb +58 -13
  40. data/test/test_default_commands/test_ls.rb +148 -0
  41. data/test/test_indent.rb +234 -0
  42. data/test/test_input_stack.rb +13 -0
  43. data/test/test_method.rb +291 -0
  44. data/test/test_pry.rb +10 -1
  45. metadata +88 -71
data/.gitignore CHANGED
@@ -8,3 +8,9 @@ pkg/
8
8
  coverage/
9
9
  .yardoc/
10
10
  /tags
11
+ *.gem
12
+
13
+ # Not sure if Pry devs use RVM or want the Gemfile.lock in the repo, thus I'm
14
+ # ignoring them for now.
15
+ .rvmrc
16
+ Gemfile.lock
data/CHANGELOG CHANGED
@@ -1,3 +1,21 @@
1
+ 25/10/2011 version 0.9.7
2
+
3
+ MAJOR NEW FEATURES:
4
+ - upgraded ls command to have a more intuitive interface
5
+ - added automatic indentation (thanks YorickPeterse!)
6
+ - added Pry::Method wrapper class to encapsulate method-related functionality
7
+
8
+ complete CHANGELOG:
9
+ * fixed syntax highlighting for object literals
10
+ * fixed ActiveSupport method-naming conflict with "in?"
11
+ * started using JRuby parser for input validation in JRuby (thanks pangloss!)
12
+ * fixed bug where ~/.pryrc could be loaded more than once (thanks kelseyjudson!)
13
+ * added parse_options! helper to pull option parsing out of commands
14
+ * Pry now respects the terminal's input encoding
15
+ * moved some requires out of the startup process for improved speed
16
+ * added input_array info to DEFAULT_PROMPT, e.g [1] pry(main)>
17
+ * added --no-history option to pry binary (prevent history being LOADED, history will still be saved)
18
+
1
19
  27/9/2011 version 0.9.6.2 HOTFIX release
2
20
  * downgrading to CodeRay 0.9.8 due to problems with 1.0 and rails (autoloading problem) see #280 on pry and #6 on CodeRay
3
21
  * also added (as a minor feature) cirwin's implementation of edit --in
@@ -77,7 +95,7 @@ complete CHANGELOG:
77
95
  * ls separator configurable via, e.g Pry.config.ls.separator = " "
78
96
  * Pry.view_clip() now only calls inspect on a few immediates, otherwise uses the #<> syntax, which has been truncated further to exclude teh mem address, again related to #245
79
97
 
80
- */7/2011 version 0.9.3
98
+ 27/7/2011 version 0.9.3
81
99
  * cat --ex (cats 5 lines above and below line in file where exception was raised)
82
100
  * edit --ex (edits line in file where exception was raised)
83
101
  * edit -t (opens a temporary file and evals it in current context when closed)
data/CONTRIBUTORS CHANGED
@@ -1,16 +1,22 @@
1
- 617 John Mair
2
- 76 Rob Gleeson
3
- 50 Lee Jarvis
4
- 47 Mon ouïe
5
- 18 David Palm
6
- 16 Conrad Irwin
7
- 14 Ryan Fitzgerald
8
- 13 epitron
9
- 2 Darrick Wiebe
10
- 2 robgleeson
11
- 2 Eric Christopherson
12
- 2 Xavier Shay
13
- 1 Tim Pope
14
- 1 Gosha Arinich
15
- 1 Josh Cheek
16
- 1 Eero Saynatkari
1
+ 687 John Mair <jrmair@gmail.com>
2
+ 82 Conrad Irwin <conrad.irwin@gmail.com>
3
+ 76 Rob Gleeson <rob@flowof.info>
4
+ 70 Ryan Fitzgerald <rwfitzge@gmail.com>
5
+ 50 Lee Jarvis <lee@jarvis.co>
6
+ 47 Mon ouïe <mon.ouie@gmail.com>
7
+ 18 David Palm <dpalm@elctech.com>
8
+ 13 epitron <chris@ill-logic.com>
9
+ 8 Eero Saynatkari <projects@kittensoft.org>
10
+ 6 Yorick Peterse <yorickpeterse@gmail.com>
11
+ 3 Darrick Wiebe <darrick@innatesoftware.com>
12
+ 2 robgleeson <rob@flowof.info>
13
+ 2 Eric Christopherson <echristopherson@gmail.com>
14
+ 2 Kelsey Judson <kelseyjudson@gmail.com>
15
+ 2 Xavier Shay <xavier@rhnh.net>
16
+ 1 Josh Cheek <josh.cheek@gmail.com>
17
+ 1 Tim Pope <code@tpope.net>
18
+ 1 Gosha Arinich <me@goshakkk.name>
19
+ 1 Shawn Anderson <shawn42@gmail.com>
20
+ 1 Jordan Running <jrunning@gmail.com>
21
+ 1 fowlmouth <phowl.mouth@gmail.com>
22
+ 1 Lars Haugseth <git@larshaugseth.com>
data/Rakefile CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'rake/clean'
2
- require "rubygems"
3
- require "rubygems/package_task"
2
+ require 'rake/gempackagetask'
4
3
 
5
4
  $:.unshift 'lib'
6
5
  require 'pry/version'
@@ -21,7 +20,7 @@ def apply_spec_defaults(s)
21
20
  s.executables = ["pry"]
22
21
  s.files = `git ls-files`.split("\n")
23
22
  s.test_files = `git ls-files -- test/*`.split("\n")
24
- s.add_dependency("ruby_parser","~>2.0.5")
23
+ s.add_dependency("ruby_parser","~>2.3.1")
25
24
  s.add_dependency("coderay","~>0.9.8")
26
25
  s.add_dependency("slop","~>2.1.0")
27
26
  s.add_dependency("method_source","~>0.6.5")
@@ -38,6 +37,13 @@ task :test do
38
37
  sh "bacon -Itest -rubygems -a -q"
39
38
  end
40
39
 
40
+ desc "profile pry's startup time"
41
+ task :profile do
42
+ require 'profile'
43
+ require 'pry'
44
+ Pry.start(TOPLEVEL_BINDING, :input => StringIO.new('exit'))
45
+ end
46
+
41
47
  desc "run pry"
42
48
  task :pry do
43
49
  load 'bin/pry'
@@ -54,7 +60,7 @@ namespace :ruby do
54
60
  s.platform = Gem::Platform::RUBY
55
61
  end
56
62
 
57
- Gem::PackageTask.new(spec) do |pkg|
63
+ Rake::GemPackageTask.new(spec) do |pkg|
58
64
  pkg.need_zip = false
59
65
  pkg.need_tar = false
60
66
  end
@@ -74,7 +80,7 @@ namespace :jruby do
74
80
  s.platform = "java"
75
81
  end
76
82
 
77
- Gem::PackageTask.new(spec) do |pkg|
83
+ Rake::GemPackageTask.new(spec) do |pkg|
78
84
  pkg.need_zip = false
79
85
  pkg.need_tar = false
80
86
  end
@@ -89,7 +95,7 @@ end
89
95
  s.platform = "i386-#{v}"
90
96
  end
91
97
 
92
- Gem::PackageTask.new(spec) do |pkg|
98
+ Rake::GemPackageTask.new(spec) do |pkg|
93
99
  pkg.need_zip = false
94
100
  pkg.need_tar = false
95
101
  end
data/bin/pry CHANGED
@@ -15,14 +15,19 @@ end
15
15
  opts = Slop.parse(:help => true, :multiple_switches => false) do
16
16
  banner %{Usage: pry [OPTIONS]
17
17
  Start a Pry session.
18
- See: `https://github.com/banister` for more information.
18
+ See: `https://github.com/pry` for more information.
19
+ Copyright (c) 2011 John Mair (banisterfiend)
19
20
  --
20
21
  }
21
22
 
22
23
  on :e, :exec, "A line of code to execute in context before the session starts", true
23
24
 
24
25
  on "no-pager", "Disable pager for long output" do
25
- Pry.pager = false
26
+ Pry.config.pager = false
27
+ end
28
+
29
+ on "no-history", "Disable history loading" do
30
+ Pry.config.history.should_load = false
26
31
  end
27
32
 
28
33
  on "no-color", "Disable syntax highlighting for session" do
@@ -39,7 +44,14 @@ See: `https://github.com/banister` for more information.
39
44
  Pry.config.plugins.enabled = false
40
45
  end
41
46
 
42
- on "installed-plugins", "List installed plugins."
47
+ on "installed-plugins", "List installed plugins." do
48
+ puts "Installed Plugins:"
49
+ puts "--"
50
+ Pry.locate_plugins.each do |plugin|
51
+ puts "#{plugin.name}".ljust(18) + plugin.spec.summary
52
+ end
53
+ exit
54
+ end
43
55
 
44
56
  on "simple-prompt", "Enable simple prompt mode" do
45
57
  Pry.prompt = Pry::SIMPLE_PROMPT
@@ -65,15 +77,6 @@ See: `https://github.com/banister` for more information.
65
77
  )
66
78
  end
67
79
 
68
- if opts["installed-plugins"]
69
- puts "Installed Plugins:"
70
- puts "--"
71
- Pry.locate_plugins.each do |plugin|
72
- puts "#{plugin.name}".ljust(18) + plugin.spec.summary
73
- end
74
- exit
75
- end
76
-
77
80
  # invoked via cli
78
81
  Pry.cli = true
79
82
 
data/lib/pry.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # (C) John Mair (banisterfiend) 2011
2
2
  # MIT License
3
+ #
3
4
 
4
5
  require 'pp'
5
6
  require 'pry/helpers/base_helpers'
@@ -11,7 +12,7 @@ class Pry
11
12
  file = target.eval('__FILE__')
12
13
 
13
14
  # /unknown/ for rbx
14
- if file !~ /(\(.*\))|<.*>/ && file !~ /__unknown__/ && file != "" && file != "-e"
15
+ if file == Pry.eval_path || (file !~ /(\(.*\))|<.*>/ && file !~ /__unknown__/ && file != "" && file != "-e")
15
16
  _pry_.process_line("whereami 5", "", target)
16
17
  end
17
18
  end
@@ -31,7 +32,11 @@ class Pry
31
32
  stringified = "#<#{klass}:0x#{value.__id__.to_s(16)}>"
32
33
  end
33
34
 
34
- Helpers::BaseHelpers.stagger_output("=> #{Helpers::BaseHelpers.colorize_code(stringified)}", output)
35
+ nonce = rand(0x100000000).to_s(16) # whatever
36
+
37
+ colorized = Helpers::BaseHelpers.colorize_code(stringified.gsub(/#</, "%<#{nonce}"))
38
+
39
+ Helpers::BaseHelpers.stagger_output("=> #{colorized.gsub(/%<(.*?)#{nonce}/, '#<\1')}", output)
35
40
  end
36
41
 
37
42
  # may be convenient when working with enormous objects and
@@ -60,42 +65,23 @@ class Pry
60
65
 
61
66
  # The default prompt; includes the target and nesting level
62
67
  DEFAULT_PROMPT = [
63
- proc { |target_self, nest_level, _|
68
+ proc { |target_self, nest_level, pry|
64
69
  if nest_level == 0
65
- "pry(#{Pry.view_clip(target_self)})> "
70
+ "[#{pry.input_array.size}] pry(#{Pry.view_clip(target_self)})> "
66
71
  else
67
- "pry(#{Pry.view_clip(target_self)}):#{nest_level}> "
72
+ "[#{pry.input_array.size}] pry(#{Pry.view_clip(target_self)}):#{nest_level}> "
68
73
  end
69
74
  },
70
75
 
71
- proc { |target_self, nest_level, _|
76
+ proc { |target_self, nest_level, pry|
72
77
  if nest_level == 0
73
- "pry(#{Pry.view_clip(target_self)})* "
78
+ "[#{pry.input_array.size}] pry(#{Pry.view_clip(target_self)})* "
74
79
  else
75
- "pry(#{Pry.view_clip(target_self)}):#{nest_level}* "
80
+ "[#{pry.input_array.size}] pry(#{Pry.view_clip(target_self)}):#{nest_level}* "
76
81
  end
77
82
  }
78
83
  ]
79
84
 
80
- # Deal with the ^D key being pressed, different behaviour in
81
- # different cases:
82
- # 1) In an expression - behave like `!` command (clear input buffer)
83
- # 2) At top-level session - behave like `exit command (break out of repl loop)
84
- # 3) In a nested session - behave like `cd ..` (pop a binding)
85
- DEFAULT_CONTROL_D_HANDLER = proc do |eval_string, _pry_|
86
- if !eval_string.empty?
87
- # clear input buffer
88
- eval_string.replace("")
89
- elsif _pry_.binding_stack.one?
90
- # ^D at top-level breaks out of loop
91
- _pry_.binding_stack.clear
92
- throw(:breakout)
93
- else
94
- # otherwise just pops a binding
95
- _pry_.binding_stack.pop
96
- end
97
- end
98
-
99
85
  # A simple prompt - doesn't display target or nesting level
100
86
  SIMPLE_PROMPT = [proc { ">> " }, proc { " | " }]
101
87
 
@@ -117,6 +103,25 @@ class Pry
117
103
  end,
118
104
  ]
119
105
 
106
+ # Deal with the ^D key being pressed, different behaviour in
107
+ # different cases:
108
+ # 1) In an expression - behave like `!` command (clear input buffer)
109
+ # 2) At top-level session - behave like `exit command (break out of repl loop)
110
+ # 3) In a nested session - behave like `cd ..` (pop a binding)
111
+ DEFAULT_CONTROL_D_HANDLER = proc do |eval_string, _pry_|
112
+ if !eval_string.empty?
113
+ # clear input buffer
114
+ eval_string.replace("")
115
+ elsif _pry_.binding_stack.one?
116
+ # ^D at top-level breaks out of loop
117
+ _pry_.binding_stack.clear
118
+ throw(:breakout)
119
+ else
120
+ # otherwise just pops a binding
121
+ _pry_.binding_stack.pop
122
+ end
123
+ end
124
+
120
125
  DEFAULT_SYSTEM = proc do |output, cmd, _|
121
126
  if !system(cmd)
122
127
  output.puts "Error: there was a problem executing system command: #{cmd}"
@@ -144,6 +149,10 @@ class Pry
144
149
  end
145
150
  end
146
151
 
152
+ # CommandErrors are caught by the REPL loop and displayed to the user. They
153
+ # indicate an exceptional condition that's fatal to the current command.
154
+ class CommandError < StandardError
155
+ end
147
156
  end
148
157
 
149
158
  require "method_source"
@@ -153,7 +162,6 @@ require "stringio"
153
162
  require "coderay"
154
163
  require "optparse"
155
164
  require "slop"
156
- require "rubygems/dependency_installer"
157
165
 
158
166
  if RUBY_PLATFORM =~ /jruby/
159
167
  begin
@@ -173,6 +181,9 @@ if RUBY_PLATFORM =~ /mswin/ || RUBY_PLATFORM =~ /mingw/
173
181
  end
174
182
 
175
183
  require "pry/version"
184
+ require "pry/rbx_method"
185
+ require "pry/rbx_path"
186
+ require "pry/method"
176
187
  require "pry/history_array"
177
188
  require "pry/helpers"
178
189
  require "pry/history"
@@ -9,6 +9,7 @@ class Pry
9
9
  # give it a nice inspect
10
10
  def VOID_VALUE.inspect() "void" end
11
11
 
12
+ attr_accessor :command_name
12
13
  attr_accessor :output
13
14
  attr_accessor :target
14
15
  attr_accessor :target_self
@@ -126,7 +126,11 @@ class Pry
126
126
  # remove the one leading space if it exists
127
127
  arg_string.slice!(0) if arg_string.start_with?(" ")
128
128
 
129
- args = arg_string ? Shellwords.shellwords(arg_string) : []
129
+ if arg_string
130
+ args = command.options[:shellwords] ? Shellwords.shellwords(arg_string) : arg_string.split(" ")
131
+ else
132
+ args = []
133
+ end
130
134
 
131
135
  options = {
132
136
  :val => val,
@@ -164,7 +168,10 @@ class Pry
164
168
 
165
169
  context.command_processor = self
166
170
 
167
- ret = commands.run_command(context, command, *args)
171
+ ret = nil
172
+ catch(:command_done) do
173
+ ret = commands.run_command(context, command, *args)
174
+ end
168
175
 
169
176
  options[:val].replace("")
170
177
 
@@ -11,6 +11,8 @@ class Pry
11
11
  class Command < Struct.new(:name, :description, :options, :block)
12
12
 
13
13
  def call(context, *args)
14
+ context.command_name = options[:listing]
15
+
14
16
  if stub_block = options[:stub_info]
15
17
  context.instance_eval(&stub_block)
16
18
  else
@@ -81,6 +83,9 @@ class Pry
81
83
  # @option options [Boolean] :use_prefix Whether the command uses
82
84
  # `Pry.config.command_prefix` prefix (if one is defined). Defaults
83
85
  # to true.
86
+ # @option options [Boolean] :shellwords Whether the command's arguments
87
+ # should be split using Shellwords instead of just split on spaces.
88
+ # Defaults to true.
84
89
  # @yield The action to perform. The parameters in the block
85
90
  # determines the parameters the command will receive. All
86
91
  # parameters passed into the block will be strings. Successive
@@ -118,6 +123,7 @@ class Pry
118
123
  :keep_retval => false,
119
124
  :argument_required => false,
120
125
  :interpolate => true,
126
+ :shellwords => true,
121
127
  :listing => name,
122
128
  :use_prefix => true
123
129
  }.merge!(options)
@@ -254,6 +260,7 @@ class Pry
254
260
  end
255
261
 
256
262
  command "install-command", "Install a disabled command." do |name|
263
+ require 'rubygems/dependency_installer' unless defined? Gem::DependencyInstaller
257
264
  command = find_command(name)
258
265
  stub_info = command.options[:stub_info]
259
266
 
data/lib/pry/config.rb CHANGED
@@ -32,6 +32,10 @@ class Pry
32
32
  # @return [Array] The classes of exception that will not be caught by Pry.
33
33
  attr_accessor :exception_whitelist
34
34
 
35
+ # @return [Fixnum] The number of lines of context to show before and after
36
+ # the exception when using cat --ex.
37
+ attr_accessor :exception_window_size
38
+
35
39
  # Get/Set the Hash that defines Pry hooks used by default by all Pry
36
40
  # instances.
37
41
  # @return [Hash] The hooks used by default by all Pry instances.
@@ -126,6 +130,10 @@ class Pry
126
130
  # The proc is passed the pry output object, the command string
127
131
  # to eval, and a reference to the pry instance
128
132
  attr_accessor :system
133
+
134
+ # @return [Boolean] Whether or not code should be indented
135
+ # using Pry::Indent.
136
+ attr_accessor :auto_indent
129
137
  end
130
138
  end
131
139
 
@@ -21,24 +21,21 @@ class Pry
21
21
  end
22
22
 
23
23
  command "import-set", "Import a command set" do |command_set_name|
24
- next output.puts "Provide a command set name" if command_set.nil?
24
+ raise CommandError, "Provide a command set name" if command_set.nil?
25
25
 
26
26
  set = target.eval(arg_string)
27
27
  _pry_.commands.import set
28
28
  end
29
29
 
30
30
  command "reload-method", "Reload the source file that contains the specified method" do |meth_name|
31
- if (meth = get_method_object(meth_name, target, {})).nil?
32
- output.puts "Invalid method name: #{meth_name}."
33
- next
34
- end
31
+ meth = get_method_or_raise(meth_name, target, {}, :omit_help)
35
32
 
36
- if is_a_c_method?(meth)
37
- output.puts "Error: Can't reload a C method."
38
- elsif is_a_dynamically_defined_method?(meth)
39
- output.puts "Error: Can't reload an eval method."
33
+ if meth.source_type == :c
34
+ raise CommandError, "Can't reload a C method."
35
+ elsif meth.dynamically_defined?
36
+ raise CommandError, "Can't reload an eval method."
40
37
  else
41
- file_name = meth.source_location.first
38
+ file_name = meth.source_file
42
39
  load file_name
43
40
  output.puts "Reloaded #{file_name}."
44
41
  end
@@ -50,7 +50,7 @@ class Pry
50
50
  selection = selection.to_i
51
51
 
52
52
  if selection < 0 || selection > _pry_.binding_stack.size - 1
53
- output.puts "Invalid binding index #{selection} - use `nesting` command to view valid indices."
53
+ raise CommandError, "Invalid binding index #{selection} - use `nesting` command to view valid indices."
54
54
  else
55
55
  Pry.start(_pry_.binding_stack[selection])
56
56
  end
@@ -137,42 +137,52 @@ class Pry
137
137
  i_num = 5
138
138
  end
139
139
 
140
- meth_name = meth_name_from_binding(target)
141
- meth_name = "N/A" if !meth_name
140
+ if (meth = Pry::Method.from_binding(target))
141
+ meth_name = meth.name
142
+ else
143
+ meth_name = "N/A"
144
+ end
142
145
 
143
- if file =~ /(\(.*\))|<.*>/ || file == "" || file == "-e"
144
- output.puts "Cannot find local context. Did you use `binding.pry` ?"
145
- next
146
+ if file != Pry.eval_path && (file =~ /(\(.*\))|<.*>/ || file == "" || file == "-e")
147
+ raise CommandError, "Cannot find local context. Did you use `binding.pry`?"
146
148
  end
147
149
 
148
150
  set_file_and_dir_locals(file)
149
151
  output.puts "\n#{text.bold('From:')} #{file} @ line #{line_num} in #{klass}##{meth_name}:\n\n"
150
152
 
151
- unless File.readable?(file)
152
- output.puts "Cannot open #{file.inspect} for reading."
153
- next
153
+ if file == Pry.eval_path
154
+ f = Pry.line_buffer[1..-1]
155
+ else
156
+ unless File.readable?(file)
157
+ raise CommandError, "Cannot open #{file.inspect} for reading."
158
+ end
159
+ f = File.open(file)
154
160
  end
155
161
 
156
162
  # This method inspired by http://rubygems.org/gems/ir_b
157
- File.open(file).each_with_index do |line, index|
158
- line_n = index + 1
159
- next unless line_n > (line_num - i_num - 1)
160
- break if line_n > (line_num + i_num)
161
- if line_n == line_num
162
- code =" =>#{line_n.to_s.rjust(3)}: #{line.chomp}"
163
- if Pry.color
164
- code = CodeRay.scan(code, :ruby).term
165
- end
166
- output.puts code
167
- code
168
- else
169
- code = "#{line_n.to_s.rjust(6)}: #{line.chomp}"
170
- if Pry.color
171
- code = CodeRay.scan(code, :ruby).term
163
+ begin
164
+ f.each_with_index do |line, index|
165
+ line_n = index + 1
166
+ next unless line_n > (line_num - i_num - 1)
167
+ break if line_n > (line_num + i_num)
168
+ if line_n == line_num
169
+ code =" =>#{line_n.to_s.rjust(3)}: #{line.chomp}"
170
+ if Pry.color
171
+ code = CodeRay.scan(code, :ruby).term
172
+ end
173
+ output.puts code
174
+ code
175
+ else
176
+ code = "#{line_n.to_s.rjust(6)}: #{line.chomp}"
177
+ if Pry.color
178
+ code = CodeRay.scan(code, :ruby).term
179
+ end
180
+ output.puts code
181
+ code
172
182
  end
173
- output.puts code
174
- code
175
183
  end
184
+ ensure
185
+ f.close if f.respond_to?(:close)
176
186
  end
177
187
  end
178
188