Sha256: 562bfe2fc0a17e0c65af6a418c8f005a750cda871988530887f23697c50abb6f
Contents?: true
Size: 1.48 KB
Versions: 9
Compression:
Stored size: 1.48 KB
Contents
#!/usr/bin/env ruby require 'packetgen' require 'packetgen/config' require 'packetgen/utils' use_pry = false begin require 'pry' use_pry = true puts "use Pry!" rescue LoadError require 'irb' require 'irb/completion' end class PgConsole include PacketGen include Utils def config PacketGen::Config.instance end PacketGen.singleton_methods.each do |m| define_method m, PacketGen.method(m).to_proc end Utils.singleton_methods.each do |m| define_method m, Utils.method(m).to_proc end def get_binding binding end end def start_message(use_pry) print "\npgconsole uses #{use_pry ? 'Pry' : 'IRB'}\n\n" end start_message use_pry if use_pry Pry.config.prompt = [ proc { |target_self, nest_level, pry| "#{pry.config.prompt_name}(#{Pry.view_clip(target_self)})#{":#{nest_level}" unless nest_level.zero?}> " }, proc { |target_self, nest_level, pry| "#{pry.config.prompt_name}(#{Pry.view_clip(target_self)})#{":#{nest_level}" unless nest_level.zero?}* " } ] Pry.config.prompt_name = 'pg' PgConsole.new.get_binding.pry else IRB.setup nil irb = IRB::Irb.new(IRB::WorkSpace.new(PgConsole.new.get_binding)) IRB.conf[:MAIN_CONTEXT] = irb.context irb.context.auto_indent_mode = true irb.context.prompt_i = "pg> " irb.context.prompt_s = "pg* " irb.context.prompt_c = "pg* " trap("SIGINT") do irb.signal_handle end begin catch(:IRB_EXIT) do irb.eval_input end ensure IRB.irb_at_exit end end
Version data entries
9 entries across 9 versions & 1 rubygems