mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Add support for history with Reline backend
This commit is contained in:
parent
2c91c5b329
commit
29c16b30ce
1 changed files with 6 additions and 4 deletions
|
|
@ -58,8 +58,6 @@ module IRB
|
||||||
end
|
end
|
||||||
|
|
||||||
module HistorySavingAbility # :nodoc:
|
module HistorySavingAbility # :nodoc:
|
||||||
include Readline
|
|
||||||
|
|
||||||
def HistorySavingAbility.extended(obj)
|
def HistorySavingAbility.extended(obj)
|
||||||
IRB.conf[:AT_EXIT].push proc{obj.save_history}
|
IRB.conf[:AT_EXIT].push proc{obj.save_history}
|
||||||
obj.load_history
|
obj.load_history
|
||||||
|
|
@ -67,18 +65,22 @@ module IRB
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_history
|
def load_history
|
||||||
|
return unless self.class.const_defined?(:HISTORY)
|
||||||
|
history = self.class::HISTORY
|
||||||
if history_file = IRB.conf[:HISTORY_FILE]
|
if history_file = IRB.conf[:HISTORY_FILE]
|
||||||
history_file = File.expand_path(history_file)
|
history_file = File.expand_path(history_file)
|
||||||
end
|
end
|
||||||
history_file = IRB.rc_file("_history") unless history_file
|
history_file = IRB.rc_file("_history") unless history_file
|
||||||
if File.exist?(history_file)
|
if File.exist?(history_file)
|
||||||
open(history_file) do |f|
|
open(history_file) do |f|
|
||||||
f.each {|l| HISTORY << l.chomp}
|
f.each {|l| history << l.chomp}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def save_history
|
def save_history
|
||||||
|
return unless self.class.const_defined?(:HISTORY)
|
||||||
|
history = self.class::HISTORY
|
||||||
if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) > 0
|
if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) > 0
|
||||||
if history_file = IRB.conf[:HISTORY_FILE]
|
if history_file = IRB.conf[:HISTORY_FILE]
|
||||||
history_file = File.expand_path(history_file)
|
history_file = File.expand_path(history_file)
|
||||||
|
|
@ -96,7 +98,7 @@ module IRB
|
||||||
end
|
end
|
||||||
|
|
||||||
open(history_file, 'w', 0600 ) do |f|
|
open(history_file, 'w', 0600 ) do |f|
|
||||||
hist = HISTORY.to_a
|
hist = history.to_a
|
||||||
f.puts(hist[-num..-1] || hist)
|
f.puts(hist[-num..-1] || hist)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue