From 522e7bc2033d3af6a72ea8b9af51e4cbcc4f0b24 Mon Sep 17 00:00:00 2001 From: John Mair Date: Wed, 7 Sep 2011 19:56:23 +1200 Subject: [PATCH] added Pry::NAV_PROMPT and Pry::SIMPLE_PRINT to pry.rb NAV_PROMPT shows you your current context along with all the previous contexts separated by a "/" a la shell-style; making it easier to navigate around. Also includes current index of _in_ and _out_ locals. SIMPLE_PRINT is just a simple inspect style printer (a la IRB); it doesnt use coloration or pretty printing or paging and can die for weird input. But is likely slightly faster for large output --- CHANGELOG | 1 + lib/pry.rb | 26 +++++++++++++++++++++++++- lib/pry/version.rb | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 8a3942bfa..d52486029 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -31,6 +31,7 @@ * got rid of Pry#null_input? since all that was needed was eval_string.empty? * cd command now supports complex syntax: cd ../@y/y/../z * JRuby is no longer a 2nd class citizen, almost full JRuby support, passing 100% tests +* added Pry::NAV_PROMPT (great new navigation prompt, per robgleeson) and Pry::SIMPLE_PRINT for simple (IRB-style) print output (just using inspect) */7/2011 version 0.9.3 * cat --ex (cats 5 lines above and below line in file where exception was raised) diff --git a/lib/pry.rb b/lib/pry.rb index a5419c2b5..57ce782d1 100644 --- a/lib/pry.rb +++ b/lib/pry.rb @@ -35,6 +35,16 @@ class Pry Helpers::BaseHelpers.stagger_output("=> #{Helpers::BaseHelpers.colorize_code(stringified)}", output) end + # may be convenient when working with enormous objects and + # pretty_print is too slow + SIMPLE_PRINT = proc do |output, value| + begin + output.puts "=> #{value.inspect}" + rescue RescuableException + output.puts "=> unknown" + end + end + # Will only show the first line of the backtrace DEFAULT_EXCEPTION_HANDLER = proc do |output, exception| output.puts "#{exception.class}: #{exception.message}" @@ -84,7 +94,21 @@ class Pry SHELL_PROMPT = [ proc { |target_self, _, _| "pry #{Pry.view_clip(target_self)}:#{Dir.pwd} $ " }, proc { |target_self, _, _| "pry #{Pry.view_clip(target_self)}:#{Dir.pwd} * " } - ] + ] + + # A prompt that includes the full object path as well as + # input/output (_in_ and _out_) information. Good for navigation. + NAV_PROMPT = [ + proc do |_, level, pry| + tree = pry.binding_stack.map { |b| Pry.view_clip(b.eval("self")) }.join " / " + "[#{pry.input_array.size}] (pry) #{tree}: #{level}> " + end, + proc do |_, level, pry| + tree = pry.binding_stack.map { |b| Pry.view_clip(b.eval("self")) }.join " / " + "[#{pry.input_array.size}] (pry) #{tree}: #{level}* " + end, + ] + # As a REPL, we often want to catch any unexpected exceptions that may have # been raised; however we don't want to go overboard and prevent the user diff --git a/lib/pry/version.rb b/lib/pry/version.rb index 9b5b3cf66..a9f5fb9fe 100644 --- a/lib/pry/version.rb +++ b/lib/pry/version.rb @@ -1,3 +1,3 @@ class Pry - VERSION = "0.9.4pre1" + VERSION = "0.9.4pre2" end