History doc tweaks and other misc faffing
This commit is contained in:
parent
e378f023d4
commit
c1f8c3f954
|
@ -1,6 +1,6 @@
|
||||||
class Pry
|
class Pry
|
||||||
# The History class is responsible for maintaining the user's input history, both
|
# The History class is responsible for maintaining the user's input history,
|
||||||
# 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
|
||||||
|
|
||||||
|
@ -44,9 +44,8 @@ class Pry
|
||||||
end
|
end
|
||||||
alias << push
|
alias << push
|
||||||
|
|
||||||
# Clear all history. Anything the user entered before this point won't be
|
# Clear this session's history. This won't affect the contents of the
|
||||||
# saved, but anything they put in afterwards will still be appended to the
|
# history file.
|
||||||
# history file on exit.
|
|
||||||
def clear
|
def clear
|
||||||
@clearer.call
|
@clearer.call
|
||||||
@history = []
|
@history = []
|
||||||
|
@ -57,6 +56,7 @@ class Pry
|
||||||
@history.count
|
@history.count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @return [Fixnum] The number of lines in history from just this session.
|
||||||
def session_line_count
|
def session_line_count
|
||||||
@history.count - @original_lines
|
@history.count - @original_lines
|
||||||
end
|
end
|
||||||
|
@ -69,18 +69,16 @@ class Pry
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# The default loader. Yields lines from `Pry.history.config.file`.
|
# The default loader. Yields lines from `Pry.history.config.file`.
|
||||||
def read_from_file
|
def read_from_file
|
||||||
begin
|
filename = File.expand_path(Pry.config.history.file)
|
||||||
history_file = File.expand_path(Pry.config.history.file)
|
|
||||||
if File.exists?(history_file)
|
if File.exists?(filename)
|
||||||
File.foreach(history_file) { |line| yield(line) }
|
File.foreach(filename) { |line| yield(line) }
|
||||||
end
|
|
||||||
rescue => error
|
|
||||||
unless error.message.empty?
|
|
||||||
warn "History file not loaded, received an error: #{error.message}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
rescue => error
|
||||||
|
warn "History file not loaded: #{error.message}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# The default pusher. Appends the given line to Readline::HISTORY.
|
# The default pusher. Appends the given line to Readline::HISTORY.
|
||||||
|
@ -94,23 +92,21 @@ class Pry
|
||||||
Readline::HISTORY.shift until Readline::HISTORY.empty?
|
Readline::HISTORY.shift until Readline::HISTORY.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# The default saver. Appends the given line to `Pry.history.config.file`.
|
||||||
def save_to_file(line)
|
def save_to_file(line)
|
||||||
history_file.puts line if history_file
|
history_file.puts line if history_file
|
||||||
end
|
end
|
||||||
|
|
||||||
# The history file for appending
|
# The history file, opened for appending.
|
||||||
def history_file
|
def history_file
|
||||||
if @history_file.nil?
|
if defined?(@history_file)
|
||||||
begin
|
@history_file
|
||||||
@history_file ||= File.open(file_path, 'a')
|
else
|
||||||
@history_file.sync = true
|
@history_file = File.open(file_path, 'a').tap { |f| f.sync = true }
|
||||||
rescue Errno::EACCES
|
|
||||||
# We should probably create an option Pry.show_warnings?!?!?!
|
|
||||||
warn 'Unable to write to your history file, history not saved'
|
|
||||||
@history_file = false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
@history_file
|
rescue Errno::EACCES
|
||||||
|
warn 'History not saved; unable to open your history file for writing.'
|
||||||
|
@history_file = false
|
||||||
end
|
end
|
||||||
|
|
||||||
def file_path
|
def file_path
|
||||||
|
|
Loading…
Reference in New Issue