34 lines
561 B
Ruby
Raw Normal View History

2020-10-10 14:16:11 +02:00
# typed: true
# frozen_string_literal: true
require "irb"
# @private
module IRB
2020-09-20 05:57:37 +02:00
def self.start_within(binding)
unless @setup_done
setup(nil, argv: [])
@setup_done = true
end
2020-09-20 05:57:37 +02:00
workspace = WorkSpace.new(binding)
irb = Irb.new(workspace)
2020-09-20 05:57:37 +02:00
@CONF[:IRB_RC]&.call(irb.context)
@CONF[:MAIN_CONTEXT] = irb.context
2015-03-10 23:25:31 -04:00
2021-04-13 17:41:35 +01:00
prev_trap = trap("SIGINT") do
2020-09-20 05:57:37 +02:00
irb.signal_handle
end
2020-09-20 05:57:37 +02:00
begin
catch(:IRB_EXIT) do
irb.eval_input
end
2020-09-20 05:57:37 +02:00
ensure
2021-04-13 17:41:35 +01:00
trap("SIGINT", prev_trap)
2020-09-20 05:57:37 +02:00
irb_at_exit
end
2020-09-20 05:57:37 +02:00
end
end