Remove order dependency between :input and :completer procs

This required switching Config::Default to use instance_eval instead of
call so that config procs can reference each other. I also brought over
a couple of copy changes from 0-9-12-stable.
This commit is contained in:
Ryan Fitzgerald 2014-02-02 17:01:32 -08:00
parent b9b87171f9
commit 8ed7a869c7
3 changed files with 34 additions and 22 deletions

View File

@ -137,7 +137,8 @@ if Pry::Helpers::BaseHelpers.jruby?
begin
require 'ffi'
rescue LoadError
warn "Need to `gem install ffi`"
# TODO: Why do we need this?
warn "For a better Pry experience on JRuby, please `gem install ffi`."
end
end
@ -148,7 +149,8 @@ if Pry::Helpers::BaseHelpers.windows? && !Pry::Helpers::BaseHelpers.windows_ansi
# only fail on jruby (where win32console doesn't work).
# Instead we'll recommend ansicon, which does.
rescue LoadError
warn "For a better pry experience, please use ansicon: https://github.com/adoxa/ansicon"
warn "For a better Pry experience on Windows, please use ansicon:"
warn " http://adoxa.3eeweb.com/ansicon/"
end
end

View File

@ -1,19 +1,8 @@
class Pry::Config::Default
include Pry::Config::Behavior
def self.lazy_readline
require 'readline'
Readline
rescue LoadError => e
warn "Pry says!"
warn "require of 'readline' has failed."
warn "you can rebuild ruby with readline support from C through '--with-readline'."
warn "alternatively, you can use the pure-ruby version of readline through 'gem install rb-readline'"
raise(e)
end
default = {
:input => method(:lazy_readline).to_proc,
:input => proc { lazy_readline },
:output => proc { $stdout },
:commands => proc { Pry::Commands },
:prompt_name => proc { Pry::DEFAULT_PROMPT_NAME },
@ -46,13 +35,7 @@ class Pry::Config::Default
:extra_sticky_locals => proc { {} },
:command_completer => proc { proc { Pry.commands.commands.keys } },
:file_completer => proc { proc { Dir["."] } },
:completer => proc {
if defined?(Bond) && Readline::VERSION !~ /editline/i
Pry::BondCompleter.start
else
Pry::InputCompleter.start
end
}
:completer => proc { lazy_completer }
}
def initialize
@ -65,13 +48,14 @@ class Pry::Config::Default
default.each do |key, value|
define_method(key) do
if default[key].equal?(value)
default[key] = value.call
default[key] = instance_eval(&value)
end
default[key]
end
end
private
# TODO:
# all of this configure_* stuff is a relic of old code.
# we should try move this code to being command-local.
@ -112,4 +96,27 @@ private
history.should_load = false
end
end
def lazy_readline
require 'readline'
Readline
rescue LoadError
warn "Sorry, you can't use Pry without Readline or a compatible library."
warn "Possible solutions:"
warn " * Rebuild Ruby with Readline support using `--with-readline`"
warn " * Use the rb-readline gem, which is a pure-Ruby port of Readline"
raise
end
def lazy_completer
if defined?(Bond) && !is_editline?(input)
Pry::BondCompleter.start
else
Pry::InputCompleter.start
end
end
def is_editline?(input)
defined?(input::VERSION) && input::VERSION =~ /editline/i
end
end

View File

@ -15,6 +15,9 @@ require 'spec_helpers/bacon'
require 'spec_helpers/mock_pry'
require 'spec_helpers/repl_tester'
# FIXME: temporary until history is fixed to not need Readline
require 'readline'
class Module
public :remove_const
public :remove_method