Sha256: a71eb03b7518c492a9c705aaae836ed4edbfd2823308336af29876b45521ed26
Contents?: true
Size: 1.48 KB
Versions: 17
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
17 entries across 17 versions & 1 rubygems