1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Move Pry#save_history to Pry.save_history.

This is for consistency with Pry.load_history
This commit is contained in:
Conrad Irwin 2011-08-07 02:30:08 -07:00 committed by John Mair
parent 43b261c2e1
commit ec3b22ede5
3 changed files with 14 additions and 11 deletions

View file

@ -67,7 +67,7 @@ class Pry
alias_command "!!@", "exit-all", ""
command "exit-program", "End the current program. Aliases: quit-program, !!!" do
Pry.active_instance.save_history if Pry.config.history.should_save
Pry.save_history if Pry.config.history.should_save
exit
end

View file

@ -139,10 +139,21 @@ class Pry
# Load Readline history if required.
def self.load_history
history_file = File.expand_path(Pry.config.history.file)
Readline::HISTORY.push(*File.readlines(history_file).map(&:chomp)) if File.exists?(history_file)
end
# Save Readline history if required.
def self.save_history
File.open(history_file, 'w') do |f|
f.write Readline::HISTORY.to_a.join("\n")
end
end
# Get the full path of the history_path for pry.
def self.history_file
File.expand_path(Pry.config.history.file)
end
# @return [Boolean] Whether this is the first time a Pry session has
# been started since loading the Pry class.
def self.initial_session?

View file

@ -149,7 +149,7 @@ class Pry
throw :breakout, break_data
end
save_history if Pry.config.history.should_save && finished_top_level_session?
Pry.save_history if Pry.config.history.should_save && finished_top_level_session?
return_value
end
@ -406,14 +406,6 @@ class Pry
!@suppress_output || last_result_is_exception?
end
# Save readline history to a file.
def save_history
history_file = File.expand_path(Pry.config.history.file)
File.open(history_file, 'w') do |f|
f.write Readline::HISTORY.to_a.join("\n")
end
end
# Returns the appropriate prompt to use.
# This method should not need to be invoked directly.
# @param [Boolean] first_line Whether this is the first line of input