Sha256: 5628efe8004dd20e31244db0957ffa3c0cbd3d4b3560461a3b7498fce6436e6a

Contents?: true

Size: 1022 Bytes

Versions: 2

Compression:

Stored size: 1022 Bytes

Contents

# -*- coding: binary -*-
module Rex
module Ui
module Text

###
#
# This class wraps the creation of an IRB shell.
#
###
class IrbShell

	@@IrbInitialized = false

	def initialize(binding)
		@binding_ctx = binding
	end

	#
	# Runs the IRB shell until completion.  The binding parameter initializes
	# IRB to the appropriate binding context.
	#
	def run
		# Initialize IRB by setting up its internal configuration hash and
		# stuff.
		if (@@IrbInitialized == false)
			load('irb.rb')

			IRB.setup(nil)
			IRB.conf[:PROMPT_MODE]  = :SIMPLE

			@@IrbInitialized = true
		end

		# Create a new IRB instance
		irb = IRB::Irb.new(IRB::WorkSpace.new(@binding_ctx))

		# Set the primary irb context so that exit and other intrinsic
		# commands will work.
		IRB.conf[:MAIN_CONTEXT] = irb.context

		# Trap interrupt
		old_sigint = trap("SIGINT") do
			irb.signal_handle
		end

		# Keep processing input until the cows come home...
		catch(:IRB_EXIT) do
			irb.eval_input
		end

		trap("SIGINT", old_sigint)
	end

end
end
end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
librex-0.0.68 lib/rex/ui/text/irb_shell.rb
librex-0.0.66 lib/rex/ui/text/irb_shell.rb