From 47d34790e78705a5900c1738da81768a03db9703 Mon Sep 17 00:00:00 2001 From: John Mair Date: Tue, 28 Dec 2010 01:36:29 +1300 Subject: [PATCH] combined default_prompt and wait_prompt into one prompt array called default_prompt; added ls_methods and ls_imethods commands, version bump to 0.4.0 --- lib/pry/commands.rb | 14 ++++++++++++-- lib/pry/prompts.rb | 35 ++++++++++++++++++----------------- lib/pry/pry_class.rb | 5 ++--- lib/pry/pry_instance.rb | 10 +++++----- 4 files changed, 37 insertions(+), 27 deletions(-) diff --git a/lib/pry/commands.rb b/lib/pry/commands.rb index 0baecb47..5dc15b3b 100644 --- a/lib/pry/commands.rb +++ b/lib/pry/commands.rb @@ -85,6 +85,14 @@ class Pry out.puts "Invalid nest level. Must be between 0 and #{max_nest_level}. Got #{break_level}." opts[:eval_string].clear end + end, + "ls_methods" => proc do |opts| + out.puts "#{Pry.view(opts[:target].eval('public_methods(false)'))}" + opts[:eval_string].clear + end, + "ls_imethods" => proc do |opts| + out.puts "#{Pry.view(opts[:target].eval('public_instance_methods(false)'))}" + opts[:eval_string].clear end } end @@ -105,7 +113,9 @@ class Pry "show_idoc" => "Show the comments above instance method ", "show_method" => "Show sourcecode for method ", "show_imethod" => "Show sourcecode for instance method ", - "jump_to" => "Jump to a Pry session further up the stack, exiting all sessions below." + "jump_to" => "Jump to a Pry session further up the stack, exiting all sessions below.", + "ls_methods" => "List public methods defined on class of receiver.", + "ls_imethods" => "List public instance methods defined on receiver." } end @@ -143,7 +153,7 @@ class Pry out.puts "--" out.puts "Receiver: #{Pry.view(target.eval('self'))}" out.puts "Nesting level: #{nesting.level}" - out.puts "Local variables: #{target.eval('Pry.view(local_variables)')}" + out.puts "Local variables: #{Pry.view(target.eval('local_variables'))}" out.puts "Pry instance: #{Pry.active_instance}" out.puts "Last result: #{Pry.view(Pry.last_result)}" end diff --git a/lib/pry/prompts.rb b/lib/pry/prompts.rb index 1c2fee35..47aef9f4 100644 --- a/lib/pry/prompts.rb +++ b/lib/pry/prompts.rb @@ -1,20 +1,21 @@ class Pry - DEFAULT_PROMPT = proc do |v, nest| - if nest == 0 - "pry(#{Pry.view(v)})> " - else - "pry(#{Pry.view(v)}):#{Pry.view(nest)}> " - end - end - - WAIT_PROMPT = proc do |v, nest| - if nest == 0 - "pry(#{Pry.view(v)})* " - else - "pry(#{Pry.view(v)}):#{Pry.view(nest)}* " - end - end + DEFAULT_PROMPT = [ + proc do |v, nest| + if nest == 0 + "pry(#{Pry.view(v)})> " + else + "pry(#{Pry.view(v)}):#{Pry.view(nest)}> " + end + end, + + proc do |v, nest| + if nest == 0 + "pry(#{Pry.view(v)})* " + else + "pry(#{Pry.view(v)}):#{Pry.view(nest)}* " + end + end + ] - SIMPLE_PROMPT = proc { "pry> " } - SIMPLE_WAIT = proc { "pry* " } + SIMPLE_PROMPT = [proc { "pry> " }, proc { "pry* " }] end diff --git a/lib/pry/pry_class.rb b/lib/pry/pry_class.rb index ed312815..6bfacb10 100644 --- a/lib/pry/pry_class.rb +++ b/lib/pry/pry_class.rb @@ -6,7 +6,7 @@ class Pry attr_accessor :last_result, :active_instance attr_accessor :input, :output attr_accessor :commands, :print, :hooks - attr_accessor :default_prompt, :wait_prompt + attr_accessor :default_prompt end def self.start(target=TOPLEVEL_BINDING, options={}) @@ -15,7 +15,7 @@ class Pry def self.view(obj) case obj - when String, Array, Hash, Symbol, nil + when String, Hash, Array, Symbol, nil obj.inspect else obj.to_s @@ -27,7 +27,6 @@ class Pry @output = Output.new @commands = Commands.new(@output) @default_prompt = DEFAULT_PROMPT - @wait_prompt = WAIT_PROMPT @print = DEFAULT_PRINT @hooks = DEFAULT_HOOKS end diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index fe42cd79..3e60492b 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -1,7 +1,7 @@ class Pry ConfigOptions = [:input, :output, :commands, :print, - :default_prompt, :wait_prompt, :hooks] + :default_prompt, :hooks] attr_accessor *ConfigOptions @@ -35,7 +35,7 @@ class Pry Pry.active_instance = self # Make sure special locals exist - target.eval("__pry__ = Pry.active_instance") + target.eval("_pry_ = Pry.active_instance") target.eval("_ = Pry.last_result") break_level = catch(:breakout) do @@ -67,7 +67,7 @@ class Pry target = binding_for(target) Pry.last_result = target.eval r(target) Pry.active_instance = self - target.eval("__pry__ = Pry.active_instance") + target.eval("_pry_ = Pry.active_instance") target.eval("_ = Pry.last_result") rescue SystemExit => e exit @@ -111,9 +111,9 @@ class Pry target_self = target.eval('self') if eval_string.empty? - default_prompt.call(target_self, nest) + default_prompt.first.call(target_self, nest) else - wait_prompt.call(target_self, nest) + default_prompt.last.call(target_self, nest) end end