lib/praxis/tasks/console.rb in praxis-2.0.pre.29 vs lib/praxis/tasks/console.rb in praxis-2.0.pre.30

- old
+ new

@@ -1,38 +1,33 @@ # frozen_string_literal: true namespace :praxis do desc 'Run interactive pry/irb console' task :console do - have_pry = false + # Use irb if available (which it almost always is). + require 'irb' - begin - # Use pry if available; require pry _before_ environment to maximize - # debuggability. - require 'pry' - have_pry = true - rescue LoadError - # Fall back on irb - require 'irb' - end - Rake::Task['praxis:environment'].invoke - if have_pry - Praxis::Application.instance.pry - else - # Keep IRB.setup from complaining about bad ARGV options - old_argv = ARGV.dup - ARGV.clear - IRB.setup nil - ARGV.concat(old_argv) + # Keep IRB.setup from complaining about bad ARGV options + old_argv = ARGV.dup + ARGV.clear + IRB.setup nil + ARGV.concat(old_argv) - # Allow reentrant IRB - IRB.conf[:MAIN_CONTEXT] = IRB::Irb.new.context - require 'irb/ext/multi-irb' + # Allow reentrant IRB + IRB.conf[:MAIN_CONTEXT] = IRB::Irb.new.context + require 'irb/ext/multi-irb' - # Use some special initialization magic to ensure that 'self' in the - # IRB session refers to Praxis::Application.instance. - IRB.irb(nil, Praxis::Application.instance) - end + # Remove main object from prompt (its stringify is not useful) + nickname = File.basename(::Praxis::Application.instance.root) + IRB.conf[:PROMPT][:DEFAULT] = { + PROMPT_I: "%N(#{nickname}):%03n:%i> ", + PROMPT_N: "%N(#{nickname}):%03n:%i> ", + PROMPT_S: "%N(#{nickname}):%03n:%i%l ", + PROMPT_C: "%N(#{nickname}):%03n:%i* " + } + + # Set the IRB main object. + IRB.irb(nil, Praxis::Application.instance) end end