Skip to content

Commit

Permalink
No longer touching the the input. It's a global lock for now (:all)
Browse files Browse the repository at this point in the history
  • Loading branch information
nviennot committed Jun 26, 2013
1 parent 7d592fe commit ec2918d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
2 changes: 2 additions & 0 deletions lib/pry/input_lock.rb
Expand Up @@ -120,7 +120,9 @@ def interruptible_region(&block)
# Note that there can be some inefficiency, as we could immediately
# succeed in enter_interruptible_region(), even before the one requesting
# the ownership has the chance to register itself as an owner.
# To mitigate the issue, we sleep a little bit.
leave_interruptible_region
sleep 0.01
retry

ensure
Expand Down
38 changes: 12 additions & 26 deletions lib/pry/repl.rb
Expand Up @@ -22,7 +22,6 @@ def self.start(options)
def initialize(pry, options = {})
@pry = pry
@indent = Pry::Indent.new
@should_try_next_input = true

if options[:target]
@pry.push_binding options[:target]
Expand All @@ -36,30 +35,13 @@ def initialize(pry, options = {})
# thrown with it.
def start
prologue
while should_try_next_input?
use_next_input
Pry::InputLock.for(input).with_ownership { repl }
end
Pry::InputLock.for(:all).with_ownership { repl }
ensure
epilogue
end

private

# Should try next input?
# @return [bool]
def should_try_next_input?
@should_try_next_input
end

# Cycle through the inputs
# Currently just get the config default input, the first one being the
# command line one.
def use_next_input
pry.input = Pry.config.input
@should_try_next_input = false
end

# Set up the repl session.
# @return [void]
def prologue
Expand Down Expand Up @@ -88,11 +70,7 @@ def repl
output.puts ""
pry.reset_eval_string
when :no_more_input
unless should_try_next_input?
output.puts "Error: Pry ran out of things to read from! " \
"Attempting to break out of REPL."
output.puts "" if output.tty?
end
output.puts "" if output.tty?
break
else
output.puts "" if val.nil? && output.tty?
Expand Down Expand Up @@ -144,12 +122,20 @@ def read
# @return [Object] Whatever the given block returns.
# @return [:no_more_input] Indicates that no more input can be read.
def handle_read_errors
should_retry = true
exception_count = 0

begin
yield
rescue EOFError
return :no_more_input
pry.input = Pry.config.input
if !should_retry
output.puts "Error: Pry ran out of things to read from! " \
"Attempting to break out of REPL."
return :no_more_input
end
should_retry = false
retry

# Handle <Ctrl+C> like Bash: empty the current input buffer, but don't
# quit. This is only for MRI 1.9; other versions of Ruby don't let you
Expand Down Expand Up @@ -211,7 +197,7 @@ def read_line(current_prompt)
end

def input_readline(*args)
Pry::InputLock.for(input).interruptible_region do
Pry::InputLock.for(:all).interruptible_region do
input.readline(*args)
end
end
Expand Down

0 comments on commit ec2918d

Please sign in to comment.