Skip to content

Commit

Permalink
added Pry::NAV_PROMPT and Pry::SIMPLE_PRINT to pry.rb
Browse files Browse the repository at this point in the history
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
  • Loading branch information
banister committed Sep 7, 2011
1 parent 9a2a1bd commit 522e7bc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -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)
Expand Down
26 changes: 25 additions & 1 deletion lib/pry.rb
Expand Up @@ -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}"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/version.rb
@@ -1,3 +1,3 @@
class Pry
VERSION = "0.9.4pre1"
VERSION = "0.9.4pre2"
end

0 comments on commit 522e7bc

Please sign in to comment.