summaryrefslogtreecommitdiff
path: root/lib/irb/input-method.rb
diff options
context:
space:
mode:
authorStan Lo <[email protected]>2023-08-09 15:57:47 +0100
committergit <[email protected]>2023-08-09 14:57:52 +0000
commitab0f90f1f5583a64a125701e3b08f6620f029eb6 (patch)
tree2998b14ea2cdb106ea71e5beba2aa38257ac13fe /lib/irb/input-method.rb
parent6acfc50bccf0c201f77c274281ac33920a0a6923 (diff)
[ruby/irb] Fix nested IRB sessions' history saving
(https://github.com/ruby/irb/pull/652) 1. Dynamically including `HistorySavingAbility` makes things unnecessarily complicated and should be avoided. 2. Because both `Reline` and `Readline` use a single `HISTORY` constant to store history data. When nesting IRB sessions, only the first IRB session should handle history loading and saving so we can avoid duplicating history. 3. History saving callback should NOT be stored in `IRB.conf` as it's recreated every time `IRB.setup` is called, which would happen when nesting IRB sessions. https://github.com/ruby/irb/commit/0fef0ae160
Diffstat (limited to 'lib/irb/input-method.rb')
-rw-r--r--lib/irb/input-method.rb12
1 files changed, 4 insertions, 8 deletions
diff --git a/lib/irb/input-method.rb b/lib/irb/input-method.rb
index 4dc43abba3..245b935668 100644
--- a/lib/irb/input-method.rb
+++ b/lib/irb/input-method.rb
@@ -5,6 +5,7 @@
#
require_relative 'completion'
+require_relative "history"
require 'io/console'
require 'reline'
@@ -167,6 +168,8 @@ module IRB
include ::Readline
end
+ include HistorySavingAbility
+
# Creates a new input method object using Readline
def initialize
self.class.initialize_readline
@@ -219,10 +222,6 @@ module IRB
true
end
- def support_history_saving?
- true
- end
-
# Returns the current line number for #io.
#
# #line counts the number of times #gets is called.
@@ -250,6 +249,7 @@ module IRB
class RelineInputMethod < InputMethod
HISTORY = Reline::HISTORY
+ include HistorySavingAbility
# Creates a new input method object using Reline
def initialize
IRB.__send__(:set_encoding, Reline.encoding_system_needs.name, override: false)
@@ -451,10 +451,6 @@ module IRB
str += " and #{inputrc_path}" if File.exist?(inputrc_path)
str
end
-
- def support_history_saving?
- true
- end
end
class ReidlineInputMethod < RelineInputMethod