diff options
author | Stan Lo <[email protected]> | 2023-07-14 16:45:04 +0100 |
---|---|---|
committer | git <[email protected]> | 2023-07-14 15:45:09 +0000 |
commit | 174bc2257065785efbbefca797a50f0847bb6062 (patch) | |
tree | e74c9d73c61cb645fe0ea6faba660e4b1b0b85a1 /lib/irb/context.rb | |
parent | bc8cc68aeff7ae3be1353f4077633cda4d30b54b (diff) |
[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.
- https://github.com/ruby/irb/blob/3ac96be660bf052902fb4e532c7a46cf294b71eb/lib/irb/history.rb#L10
- https://github.com/ruby/irb/blob/3ac96be660bf052902fb4e532c7a46cf294b71eb/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
Diffstat (limited to 'lib/irb/context.rb')
-rw-r--r-- | lib/irb/context.rb | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/lib/irb/context.rb b/lib/irb/context.rb index d755622f32..bf5b4c5708 100644 --- a/lib/irb/context.rb +++ b/lib/irb/context.rb @@ -154,8 +154,12 @@ module IRB def save_history=(val) IRB.conf[:SAVE_HISTORY] = 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 @@ -576,11 +580,5 @@ module IRB command = command_aliases.fetch(command.to_sym, command) ExtendCommandBundle.load_command(command)&.respond_to?(:transform_args) end - - def init_save_history# :nodoc: - unless (class<<@io;self;end).include?(HistorySavingAbility) - @io.extend(HistorySavingAbility) - end - end end end |