Initialize History lazily, make it work without Readline

This commit is contained in:
Ryan Fitzgerald 2014-02-02 19:51:39 -08:00
parent 95d0ca534b
commit 87f8ac439e
3 changed files with 17 additions and 10 deletions

View File

@ -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`.

View File

@ -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

View File

@ -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