summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Fitzgerald <rwfitzge@gmail.com>2014-02-02 19:51:39 -0800
committerRyan Fitzgerald <rwfitzge@gmail.com>2014-02-02 19:51:39 -0800
commit87f8ac439e53c762441ef5743d9eeb4e1e6b48aa (patch)
tree17d0bb24a287e9f38bffd7bd3536eb5fbda450e0
parent95d0ca534b5dd948005a29f7e3aab46ef63a87cd (diff)
downloadpry-87f8ac439e53c762441ef5743d9eeb4e1e6b48aa.tar.gz
Initialize History lazily, make it work without Readline
-rw-r--r--lib/pry/history.rb17
-rw-r--r--lib/pry/pry_class.rb7
-rw-r--r--spec/helper.rb3
3 files changed, 17 insertions, 10 deletions
diff --git a/lib/pry/history.rb b/lib/pry/history.rb
index 571a9318..1bef4a23 100644
--- a/lib/pry/history.rb
+++ b/lib/pry/history.rb
@@ -2,7 +2,6 @@ class Pry
# The History class is responsible for maintaining the user's input history,
# both internally and within Readline.
class History
-
attr_accessor :loader, :saver, :pusher, :clearer
# @return [Fixnum] Number of lines in history when Pry first loaded.
@@ -17,10 +16,18 @@ class Pry
# Assign the default methods for loading, saving, pushing, and clearing.
def restore_default_behavior
- @loader = method(:read_from_file)
- @saver = method(:save_to_file)
- @pusher = method(:push_to_readline)
- @clearer = method(:clear_readline)
+ Pry.config.input # force Readline to load if applicable
+
+ @loader = method(:read_from_file)
+ @saver = method(:save_to_file)
+
+ if defined?(Readline)
+ @pusher = method(:push_to_readline)
+ @clearer = method(:clear_readline)
+ else
+ @pusher = proc { }
+ @clearer = proc { }
+ end
end
# Load the input history using `History.loader`.
diff --git a/lib/pry/pry_class.rb b/lib/pry/pry_class.rb
index cf284b89..e9ba2be5 100644
--- a/lib/pry/pry_class.rb
+++ b/lib/pry/pry_class.rb
@@ -10,11 +10,11 @@ class Pry
attr_accessor :current_line
attr_accessor :line_buffer
attr_accessor :eval_path
- attr_accessor :history
attr_accessor :cli
attr_accessor :quiet
attr_accessor :last_internal_error
attr_accessor :config
+ attr_writer :history
def_delegators :@plugin_manager, :plugins, :load_plugins, :locate_plugins
@@ -28,6 +28,10 @@ class Pry
def prompt
config.prompt
end
+
+ def history
+ @history ||= History.new
+ end
end
def self.main
@@ -276,7 +280,6 @@ Readline version #{Readline::VERSION} detected - will not auto_resize! correctly
# Basic initialization.
def self.init
@plugin_manager ||= PluginManager.new
- self.history ||= History.new
reset_defaults
locate_plugins
end
diff --git a/spec/helper.rb b/spec/helper.rb
index 0290d0d6..60193949 100644
--- a/spec/helper.rb
+++ b/spec/helper.rb
@@ -15,9 +15,6 @@ 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