[ruby/irb] Fix history-saving feature
(https://github.com/ruby/irb/pull/642) * Define RelineInputMethod::HISTORY The HistorySavingAbility module doesn't do anything if the input method class doesn't define HISTORY. -3ac96be660/lib/irb/history.rb (L10)
-3ac96be660/lib/irb/history.rb (L34)
This patch defines RelineInputMethod::HISTORY to avoid this. * Improve history-saving's ability check Instead of checking the existence of `input_method_class::HISTORY`, we should make every input method class declare if it supports history saving or not. Since the default value is `false`, it shouldn't break any custom input method that inherits from `IRB::InputMethod`. https://github.com/ruby/irb/commit/aec7a5b3f5
This commit is contained in:
parent
bc8cc68aef
commit
174bc22570
@ -154,8 +154,12 @@ module IRB
|
|||||||
|
|
||||||
def save_history=(val)
|
def save_history=(val)
|
||||||
IRB.conf[:SAVE_HISTORY] = val
|
IRB.conf[:SAVE_HISTORY] = val
|
||||||
|
|
||||||
if val
|
if val
|
||||||
(IRB.conf[:MAIN_CONTEXT] || self).init_save_history
|
context = (IRB.conf[:MAIN_CONTEXT] || self)
|
||||||
|
if context.io.support_history_saving? && !context.io.singleton_class.include?(HistorySavingAbility)
|
||||||
|
context.io.extend(HistorySavingAbility)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -576,11 +580,5 @@ module IRB
|
|||||||
command = command_aliases.fetch(command.to_sym, command)
|
command = command_aliases.fetch(command.to_sym, command)
|
||||||
ExtendCommandBundle.load_command(command)&.respond_to?(:transform_args)
|
ExtendCommandBundle.load_command(command)&.respond_to?(:transform_args)
|
||||||
end
|
end
|
||||||
|
|
||||||
def init_save_history# :nodoc:
|
|
||||||
unless (class<<@io;self;end).include?(HistorySavingAbility)
|
|
||||||
@io.extend(HistorySavingAbility)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -7,7 +7,6 @@ module IRB
|
|||||||
end
|
end
|
||||||
|
|
||||||
def load_history
|
def load_history
|
||||||
return unless self.class.const_defined?(:HISTORY)
|
|
||||||
history = self.class::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)
|
||||||
@ -31,7 +30,6 @@ module IRB
|
|||||||
end
|
end
|
||||||
|
|
||||||
def save_history
|
def save_history
|
||||||
return unless self.class.const_defined?(:HISTORY)
|
|
||||||
history = self.class::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]
|
||||||
|
@ -47,6 +47,10 @@ module IRB
|
|||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def support_history_saving?
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
# For debug message
|
# For debug message
|
||||||
def inspect
|
def inspect
|
||||||
'Abstract InputMethod'
|
'Abstract InputMethod'
|
||||||
@ -230,6 +234,10 @@ module IRB
|
|||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def support_history_saving?
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
# Returns the current line number for #io.
|
# Returns the current line number for #io.
|
||||||
#
|
#
|
||||||
# #line counts the number of times #gets is called.
|
# #line counts the number of times #gets is called.
|
||||||
@ -256,6 +264,7 @@ module IRB
|
|||||||
end
|
end
|
||||||
|
|
||||||
class RelineInputMethod < InputMethod
|
class RelineInputMethod < InputMethod
|
||||||
|
HISTORY = Reline::HISTORY
|
||||||
# Creates a new input method object using Reline
|
# Creates a new input method object using Reline
|
||||||
def initialize
|
def initialize
|
||||||
IRB.__send__(:set_encoding, Reline.encoding_system_needs.name, override: false)
|
IRB.__send__(:set_encoding, Reline.encoding_system_needs.name, override: false)
|
||||||
@ -458,6 +467,10 @@ module IRB
|
|||||||
str += " and #{inputrc_path}" if File.exist?(inputrc_path)
|
str += " and #{inputrc_path}" if File.exist?(inputrc_path)
|
||||||
str
|
str
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def support_history_saving?
|
||||||
|
true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class ReidlineInputMethod < RelineInputMethod
|
class ReidlineInputMethod < RelineInputMethod
|
||||||
|
Loading…
x
Reference in New Issue
Block a user