From 8ed7a869c7adf233d00f0b59b579272df01c9fcf Mon Sep 17 00:00:00 2001 From: Ryan Fitzgerald Date: Sun, 2 Feb 2014 17:01:32 -0800 Subject: [PATCH] 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. --- lib/pry.rb | 6 +++-- lib/pry/config/default.rb | 47 ++++++++++++++++++++++----------------- spec/helper.rb | 3 +++ 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/lib/pry.rb b/lib/pry.rb index 2bde869a..10b1a675 100644 --- a/lib/pry.rb +++ b/lib/pry.rb @@ -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 diff --git a/lib/pry/config/default.rb b/lib/pry/config/default.rb index 7950a2d6..49d588ab 100644 --- a/lib/pry/config/default.rb +++ b/lib/pry/config/default.rb @@ -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 diff --git a/spec/helper.rb b/spec/helper.rb index 60193949..0290d0d6 100644 --- a/spec/helper.rb +++ b/spec/helper.rb @@ -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