mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
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
This commit is contained in:
parent
7135d5179e
commit
47d34790e7
4 changed files with 37 additions and 27 deletions
|
@ -85,6 +85,14 @@ class Pry
|
||||||
out.puts "Invalid nest level. Must be between 0 and #{max_nest_level}. Got #{break_level}."
|
out.puts "Invalid nest level. Must be between 0 and #{max_nest_level}. Got #{break_level}."
|
||||||
opts[:eval_string].clear
|
opts[:eval_string].clear
|
||||||
end
|
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
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -105,7 +113,9 @@ class Pry
|
||||||
"show_idoc" => "Show the comments above instance method <methname>",
|
"show_idoc" => "Show the comments above instance method <methname>",
|
||||||
"show_method" => "Show sourcecode for method <methname>",
|
"show_method" => "Show sourcecode for method <methname>",
|
||||||
"show_imethod" => "Show sourcecode for instance method <methname>",
|
"show_imethod" => "Show sourcecode for instance method <methname>",
|
||||||
"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
|
end
|
||||||
|
|
||||||
|
@ -143,7 +153,7 @@ class Pry
|
||||||
out.puts "--"
|
out.puts "--"
|
||||||
out.puts "Receiver: #{Pry.view(target.eval('self'))}"
|
out.puts "Receiver: #{Pry.view(target.eval('self'))}"
|
||||||
out.puts "Nesting level: #{nesting.level}"
|
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 "Pry instance: #{Pry.active_instance}"
|
||||||
out.puts "Last result: #{Pry.view(Pry.last_result)}"
|
out.puts "Last result: #{Pry.view(Pry.last_result)}"
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,20 +1,21 @@
|
||||||
class Pry
|
class Pry
|
||||||
DEFAULT_PROMPT = proc do |v, nest|
|
DEFAULT_PROMPT = [
|
||||||
if nest == 0
|
proc do |v, nest|
|
||||||
"pry(#{Pry.view(v)})> "
|
if nest == 0
|
||||||
else
|
"pry(#{Pry.view(v)})> "
|
||||||
"pry(#{Pry.view(v)}):#{Pry.view(nest)}> "
|
else
|
||||||
end
|
"pry(#{Pry.view(v)}):#{Pry.view(nest)}> "
|
||||||
end
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
WAIT_PROMPT = proc do |v, nest|
|
proc do |v, nest|
|
||||||
if nest == 0
|
if nest == 0
|
||||||
"pry(#{Pry.view(v)})* "
|
"pry(#{Pry.view(v)})* "
|
||||||
else
|
else
|
||||||
"pry(#{Pry.view(v)}):#{Pry.view(nest)}* "
|
"pry(#{Pry.view(v)}):#{Pry.view(nest)}* "
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
]
|
||||||
|
|
||||||
SIMPLE_PROMPT = proc { "pry> " }
|
SIMPLE_PROMPT = [proc { "pry> " }, proc { "pry* " }]
|
||||||
SIMPLE_WAIT = proc { "pry* " }
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,7 +6,7 @@ class Pry
|
||||||
attr_accessor :last_result, :active_instance
|
attr_accessor :last_result, :active_instance
|
||||||
attr_accessor :input, :output
|
attr_accessor :input, :output
|
||||||
attr_accessor :commands, :print, :hooks
|
attr_accessor :commands, :print, :hooks
|
||||||
attr_accessor :default_prompt, :wait_prompt
|
attr_accessor :default_prompt
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.start(target=TOPLEVEL_BINDING, options={})
|
def self.start(target=TOPLEVEL_BINDING, options={})
|
||||||
|
@ -15,7 +15,7 @@ class Pry
|
||||||
|
|
||||||
def self.view(obj)
|
def self.view(obj)
|
||||||
case obj
|
case obj
|
||||||
when String, Array, Hash, Symbol, nil
|
when String, Hash, Array, Symbol, nil
|
||||||
obj.inspect
|
obj.inspect
|
||||||
else
|
else
|
||||||
obj.to_s
|
obj.to_s
|
||||||
|
@ -27,7 +27,6 @@ class Pry
|
||||||
@output = Output.new
|
@output = Output.new
|
||||||
@commands = Commands.new(@output)
|
@commands = Commands.new(@output)
|
||||||
@default_prompt = DEFAULT_PROMPT
|
@default_prompt = DEFAULT_PROMPT
|
||||||
@wait_prompt = WAIT_PROMPT
|
|
||||||
@print = DEFAULT_PRINT
|
@print = DEFAULT_PRINT
|
||||||
@hooks = DEFAULT_HOOKS
|
@hooks = DEFAULT_HOOKS
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
class Pry
|
class Pry
|
||||||
|
|
||||||
ConfigOptions = [:input, :output, :commands, :print,
|
ConfigOptions = [:input, :output, :commands, :print,
|
||||||
:default_prompt, :wait_prompt, :hooks]
|
:default_prompt, :hooks]
|
||||||
|
|
||||||
attr_accessor *ConfigOptions
|
attr_accessor *ConfigOptions
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ class Pry
|
||||||
Pry.active_instance = self
|
Pry.active_instance = self
|
||||||
|
|
||||||
# Make sure special locals exist
|
# Make sure special locals exist
|
||||||
target.eval("__pry__ = Pry.active_instance")
|
target.eval("_pry_ = Pry.active_instance")
|
||||||
target.eval("_ = Pry.last_result")
|
target.eval("_ = Pry.last_result")
|
||||||
|
|
||||||
break_level = catch(:breakout) do
|
break_level = catch(:breakout) do
|
||||||
|
@ -67,7 +67,7 @@ class Pry
|
||||||
target = binding_for(target)
|
target = binding_for(target)
|
||||||
Pry.last_result = target.eval r(target)
|
Pry.last_result = target.eval r(target)
|
||||||
Pry.active_instance = self
|
Pry.active_instance = self
|
||||||
target.eval("__pry__ = Pry.active_instance")
|
target.eval("_pry_ = Pry.active_instance")
|
||||||
target.eval("_ = Pry.last_result")
|
target.eval("_ = Pry.last_result")
|
||||||
rescue SystemExit => e
|
rescue SystemExit => e
|
||||||
exit
|
exit
|
||||||
|
@ -111,9 +111,9 @@ class Pry
|
||||||
target_self = target.eval('self')
|
target_self = target.eval('self')
|
||||||
|
|
||||||
if eval_string.empty?
|
if eval_string.empty?
|
||||||
default_prompt.call(target_self, nest)
|
default_prompt.first.call(target_self, nest)
|
||||||
else
|
else
|
||||||
wait_prompt.call(target_self, nest)
|
default_prompt.last.call(target_self, nest)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue