aboutsummaryrefslogtreecommitdiffstats
path: root/lib/irb.rb
diff options
context:
space:
mode:
authorStan Lo <stan001212@gmail.com>2023-08-09 15:57:47 +0100
committergit <svn-admin@ruby-lang.org>2023-08-09 14:57:52 +0000
commitab0f90f1f5583a64a125701e3b08f6620f029eb6 (patch)
tree2998b14ea2cdb106ea71e5beba2aa38257ac13fe /lib/irb.rb
parent6acfc50bccf0c201f77c274281ac33920a0a6923 (diff)
downloadruby-ab0f90f1f5583a64a125701e3b08f6620f029eb6.tar.gz
[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.rb')
-rw-r--r--lib/irb.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/irb.rb b/lib/irb.rb
index 1f86a0f386..839115d649 100644
--- a/lib/irb.rb
+++ b/lib/irb.rb
@@ -482,9 +482,16 @@ module IRB
end
def run(conf = IRB.conf)
+ in_nested_session = !!conf[:MAIN_CONTEXT]
conf[:IRB_RC].call(context) if conf[:IRB_RC]
conf[:MAIN_CONTEXT] = context
+ save_history = !in_nested_session && conf[:SAVE_HISTORY] && context.io.support_history_saving?
+
+ if save_history
+ context.io.load_history
+ end
+
prev_trap = trap("SIGINT") do
signal_handle
end
@@ -496,6 +503,7 @@ module IRB
ensure
trap("SIGINT", prev_trap)
conf[:AT_EXIT].each{|hook| hook.call}
+ context.io.save_history if save_history
end
end