mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Pry.input_history -> Pry.history, Pry::InputHistory -> Pry::History
This commit is contained in:
parent
226f1ae816
commit
a1a7cdc03d
6 changed files with 25 additions and 25 deletions
|
@ -97,7 +97,7 @@ e.g amend-line puts 'hello again' # no line number modifies immediately preced
|
|||
|
||||
command "hist", "Show and replay Readline history. Type `hist --help` for more info. Aliases: history" do |*args|
|
||||
# exclude the current command from history.
|
||||
history = Pry.input_history.to_a[0..-2]
|
||||
history = Pry.history.to_a[0..-2]
|
||||
|
||||
opts = Slop.parse!(args) do |opt|
|
||||
opt.banner "Usage: hist [--replay START..END] [--clear] [--grep PATTERN] [--head N] [--tail N] [--help] [--save [START..END] file.txt]\n"
|
||||
|
@ -170,7 +170,7 @@ e.g amend-line puts 'hello again' # no line number modifies immediately preced
|
|||
opt.on "save", "Save history to a file. --save [start..end] output.txt. Pry commands are excluded from saved history.", true, :as => Range
|
||||
|
||||
opt.on :c, :clear, 'Clear the history', :unless => :grep do
|
||||
Pry.input_history.clear
|
||||
Pry.history.clear
|
||||
output.puts 'History cleared.'
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class Pry
|
||||
class InputHistory
|
||||
class History
|
||||
def initialize
|
||||
@history = []
|
||||
@first_new_line = 0 # TODO: rename this
|
||||
|
|
|
@ -38,8 +38,8 @@ class Pry
|
|||
# @return [OpenStruct] Return Pry's config object.
|
||||
attr_accessor :config
|
||||
|
||||
# @return [InputHistory] TODO: put something here
|
||||
attr_accessor :input_history
|
||||
# @return [History] TODO: put something here
|
||||
attr_accessor :history
|
||||
|
||||
# @return [Boolean] Whether Pry was activated from the command line.
|
||||
attr_accessor :cli
|
||||
|
@ -126,12 +126,12 @@ class Pry
|
|||
|
||||
# Load Readline history if required.
|
||||
def self.load_history
|
||||
Pry.input_history.load(history_file) if File.exists?(history_file)
|
||||
Pry.history.load(history_file) if File.exists?(history_file)
|
||||
end
|
||||
|
||||
# Save new lines of Readline history if required.
|
||||
def self.save_history
|
||||
Pry.input_history.save(history_file)
|
||||
Pry.history.save(history_file)
|
||||
end
|
||||
|
||||
# Get the full path of the history_path for pry.
|
||||
|
@ -232,7 +232,7 @@ class Pry
|
|||
def self.init
|
||||
@plugin_manager ||= PluginManager.new
|
||||
self.config ||= Config.new
|
||||
self.input_history ||= InputHistory.new
|
||||
self.history ||= History.new
|
||||
|
||||
reset_defaults
|
||||
locate_plugins
|
||||
|
|
|
@ -154,7 +154,7 @@ class Pry
|
|||
|
||||
Pry.active_sessions -= 1
|
||||
binding_stack.pop
|
||||
Pry.save_history if Pry.config.history.should_save && Pry.active_sessions == 0
|
||||
Pry.history.save if Pry.config.history.should_save && Pry.active_sessions == 0
|
||||
break_data
|
||||
end
|
||||
|
||||
|
@ -373,7 +373,7 @@ class Pry
|
|||
|
||||
if input == Readline
|
||||
line = input.readline(current_prompt, false)
|
||||
Pry.input_history << line
|
||||
Pry.history << line
|
||||
line
|
||||
else
|
||||
begin
|
||||
|
|
|
@ -202,8 +202,8 @@ describe "Pry::DefaultCommands::Input" do
|
|||
end
|
||||
|
||||
before do
|
||||
Pry.input_history.clear
|
||||
@hist = Pry.input_history
|
||||
Pry.history.clear
|
||||
@hist = Pry.history
|
||||
end
|
||||
|
||||
it 'should display the correct history' do
|
||||
|
|
|
@ -4,7 +4,7 @@ require 'tempfile'
|
|||
describe Pry do
|
||||
|
||||
before do
|
||||
Pry.input_history.clear
|
||||
Pry.history.clear
|
||||
@hist = Tempfile.new(["tmp", ".pry_history"]).tap(&:close).path
|
||||
File.open(@hist, 'w') {|f| f << "1\n2\n3\n" }
|
||||
@old_hist = Pry.config.history.file
|
||||
|
@ -19,13 +19,13 @@ describe Pry do
|
|||
|
||||
describe ".load_history" do
|
||||
it "should read the contents of the file" do
|
||||
Pry.input_history.to_a[-2..-1].should === ["2", "3"]
|
||||
Pry.history.to_a[-2..-1].should === ["2", "3"]
|
||||
end
|
||||
end
|
||||
|
||||
describe ".save_history" do
|
||||
it "should include a trailing newline" do
|
||||
Pry.input_history << "4"
|
||||
Pry.history << "4"
|
||||
Pry.save_history
|
||||
File.read(@hist).should =~ /4\n\z/
|
||||
end
|
||||
|
@ -37,45 +37,45 @@ describe Pry do
|
|||
end
|
||||
|
||||
it "should append new lines to the file" do
|
||||
Pry.input_history << "4"
|
||||
Pry.history << "4"
|
||||
Pry.save_history
|
||||
File.read(@hist).should == "1\n2\n3\n4\n"
|
||||
end
|
||||
|
||||
it "should not clobber lines written by other Pry's in the meantime" do
|
||||
Pry.input_history << "5"
|
||||
Pry.history << "5"
|
||||
File.open(@hist, 'a') {|f| f << "4\n" }
|
||||
Pry.save_history
|
||||
|
||||
Pry.input_history.to_a[-3..-1].should == ["2", "3", "5"]
|
||||
Pry.history.to_a[-3..-1].should == ["2", "3", "5"]
|
||||
File.read(@hist).should == "1\n2\n3\n4\n5\n"
|
||||
end
|
||||
|
||||
it "should not delete lines from the file if this session's history was cleared" do
|
||||
Pry.input_history.clear
|
||||
Pry.history.clear
|
||||
Pry.save_history
|
||||
File.read(@hist).should == "1\n2\n3\n"
|
||||
end
|
||||
|
||||
it "should save new lines that are added after the history was cleared" do
|
||||
Pry.input_history.clear
|
||||
Pry.input_history << "4"
|
||||
Pry.history.clear
|
||||
Pry.history << "4"
|
||||
|
||||
# doing this twice as libedit on 1.8.7 has bugs and sometimes ignores the
|
||||
# first line in history
|
||||
Pry.input_history << "4"
|
||||
Pry.history << "4"
|
||||
Pry.save_history
|
||||
File.read(@hist).should =~ /1\n2\n3\n4\n/
|
||||
end
|
||||
|
||||
it "should only append new lines the second time it is saved" do
|
||||
Pry.input_history << "4"
|
||||
Pry.history << "4"
|
||||
Pry.save_history
|
||||
File.open(@hist, 'a') {|f| f << "5\n" }
|
||||
Pry.input_history << "6"
|
||||
Pry.history << "6"
|
||||
Pry.save_history
|
||||
|
||||
Pry.input_history.to_a[-4..-1].should == ["2", "3", "4", "6"]
|
||||
Pry.history.to_a[-4..-1].should == ["2", "3", "4", "6"]
|
||||
File.read(@hist).should == "1\n2\n3\n4\n5\n6\n"
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue