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, # The History class is responsible for maintaining the user's input history,
# both internally and within Readline. # both internally and within Readline.
class History class History
attr_accessor :loader, :saver, :pusher, :clearer attr_accessor :loader, :saver, :pusher, :clearer
# @return [Fixnum] Number of lines in history when Pry first loaded. # @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. # Assign the default methods for loading, saving, pushing, and clearing.
def restore_default_behavior def restore_default_behavior
@loader = method(:read_from_file) Pry.config.input # force Readline to load if applicable
@saver = method(:save_to_file)
@pusher = method(:push_to_readline) @loader = method(:read_from_file)
@clearer = method(:clear_readline) @saver = method(:save_to_file)
if defined?(Readline)
@pusher = method(:push_to_readline)
@clearer = method(:clear_readline)
else
@pusher = proc { }
@clearer = proc { }
end
end end
# Load the input history using `History.loader`. # Load the input history using `History.loader`.

View File

@ -10,11 +10,11 @@ class Pry
attr_accessor :current_line attr_accessor :current_line
attr_accessor :line_buffer attr_accessor :line_buffer
attr_accessor :eval_path attr_accessor :eval_path
attr_accessor :history
attr_accessor :cli attr_accessor :cli
attr_accessor :quiet attr_accessor :quiet
attr_accessor :last_internal_error attr_accessor :last_internal_error
attr_accessor :config attr_accessor :config
attr_writer :history
def_delegators :@plugin_manager, :plugins, :load_plugins, :locate_plugins def_delegators :@plugin_manager, :plugins, :load_plugins, :locate_plugins
@ -28,6 +28,10 @@ class Pry
def prompt def prompt
config.prompt config.prompt
end end
def history
@history ||= History.new
end
end end
def self.main def self.main
@ -276,7 +280,6 @@ Readline version #{Readline::VERSION} detected - will not auto_resize! correctly
# Basic initialization. # Basic initialization.
def self.init def self.init
@plugin_manager ||= PluginManager.new @plugin_manager ||= PluginManager.new
self.history ||= History.new
reset_defaults reset_defaults
locate_plugins locate_plugins
end end

View File

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