lib/guard/interactors/readline.rb in guard-1.2.3 vs lib/guard/interactors/readline.rb in guard-1.3.0
- old
+ new
@@ -1,18 +1,20 @@
+require 'guard'
+require 'guard/ui'
+require 'guard/interactor'
+require 'guard/interactors/helpers/terminal'
+require 'guard/interactors/helpers/completion'
+
module Guard
- autoload :TerminalHelper, 'guard/interactors/helpers/terminal'
- autoload :CompletionHelper, 'guard/interactors/helpers/completion'
- autoload :UI, 'guard/ui'
-
# Interactor that used readline for getting the user input.
# This enables history support and auto-completion, but is
# broken on OS X without installing `rb-readline` or using JRuby.
#
# @see http://bugs.ruby-lang.org/issues/5539
#
- class ReadlineInteractor < Interactor
+ class ReadlineInteractor < ::Guard::Interactor
include ::Guard::CompletionHelper
include ::Guard::TerminalHelper
# Test if the Interactor is
# available in the current environment?
@@ -27,10 +29,14 @@
true
else
::Guard::UI.error 'The :readline interactor runs only fine on JRuby, Linux or with the gem \'rb-readline\' installed.' unless silent
false
end
+
+ rescue LoadError => e
+ ::Guard::UI.error "Please install Ruby Readline support or add \"gem 'rb-readline'\" to your Gemfile and run Guard with \"bundle exec\"." unless silent
+ false
end
# Initialize the interactor.
#
def initialize
@@ -47,21 +53,21 @@
# Stop the interactor.
#
def stop
# Erase the current line for Ruby Readline
- if Readline.respond_to?(:refresh_line)
+ if Readline.respond_to?(:refresh_line) && !defined?(::JRUBY_VERSION)
Readline.refresh_line
end
-
+
# Erase the current line for Rb-Readline
if defined?(RbReadline) && RbReadline.rl_outstream
RbReadline._rl_erase_entire_line
end
super
end
-
+
# Read a line from stdin with Readline.
#
def read_line
require 'readline'