Version 0.4.9pre1. Added show_command, added -g option to ls and got it working in combination with -c, e.g ls -gc. Changed documentation for !

This commit is contained in:
John Mair 2011-02-14 04:49:53 +13:00
parent afa3cabf77
commit 33780cc77d
6 changed files with 61 additions and 24 deletions

View File

@ -38,16 +38,16 @@ class WinClass < Gosu::Window
def initialize
super(WIDTH, HEIGHT, false)
@img = TexPlay.create_image(self, 200, 200).clear :color => :black
@img.rect 0, 0, @img.width - 1, @img.height - 1
$img = TexPlay.create_image(self, 200, 200).clear :color => :black
$img.rect 0, 0, $img.width - 1, $img.height - 1
@binding = @img.__binding__
@binding = $img.__binding__
@pry_instance = Pry.new(:commands => ImageCommands, :prompt => IMAGE_PROMPT)
end
def draw
@img.draw_rot(WIDTH / 2, HEIGHT / 2, 1, 0, 0.5, 0.5)
$img.draw_rot(WIDTH / 2, HEIGHT / 2, 1, 0, 0.5, 0.5)
end
def update
@ -57,7 +57,7 @@ class WinClass < Gosu::Window
# being updated; instead we do a REP session, and let the image
# update each time the user presses enter. We maintain the same
# binding object to keep locals between calls to `Pry#rep()`
@pry_instance.rep(@binding)
# @pry_instance.rep(@binding)
end
end
@ -66,5 +66,7 @@ puts "--"
puts "Example: Try typing 'circle width/2, height/2, 95, :color => :blue, :fill => true'"
puts "If you want to save your image, type: save(\"img.png\")"
WinClass.new.show
w = WinClass.new
Thread.new { Pry.start(w) }
w.show

View File

@ -6,8 +6,8 @@ class Pry
# Default commands used by Pry.
class Commands < CommandBase
command "!", "Refresh the REPL" do
output.puts "Refreshed REPL"
command "!", "Clear the input buffer. Useful if the parsing process goes wrong." do
output.puts "Input buffer cleared!"
opts[:eval_string].clear
end
@ -27,9 +27,9 @@ class Pry
out.puts "--"
nesting.each do |level, obj|
if level == 0
out.puts "#{level}. #{Pry.view(obj)} (Pry top level)"
out.puts "#{level}. #{Pry.view_clip(obj)} (Pry top level)"
else
out.puts "#{level}. #{Pry.view(obj)}"
out.puts "#{level}. #{Pry.view_clip(obj)}"
end
end
end
@ -40,7 +40,7 @@ class Pry
out.puts "Status:"
out.puts "--"
out.puts "Receiver: #{Pry.view(target.eval('self'))}"
out.puts "Receiver: #{Pry.view_clip(target.eval('self'))}"
out.puts "Nesting level: #{nesting.level}"
out.puts "Local variables: #{Pry.view(target.eval('local_variables'))}"
out.puts "Pry instance: #{Pry.active_instance}"
@ -51,17 +51,26 @@ class Pry
throw(:breakout, 0)
end
command "ls", "Show the list of vars in the current scope. Use -c to include constants." do |arg|
with_constants = (arg == "-c")
command "ls", "Show the list of vars in the current scope. Use -c to include constants and -g to include globals." do |*args|
params = []
args.each do |v|
if v[0].chr == "-"
params += v[1..-1].split("")
end
end
target_self = target.eval('self')
extras = []
extras += target.eval("global_variables") if params.include?("g")
case target_self
when Module
c = with_constants ? target_self.constants.inspect : [].inspect
output.puts "#{Pry.view(target.eval("local_variables + instance_variables + #{c}"))}"
extras += target.eval("constants") if params.include?("c")
output.puts "#{Pry.view(target.eval("local_variables + instance_variables + #{extras.inspect}"))}"
else
c = with_constants ? target_self.class.constants.inspect : [].inspect
output.puts "#{Pry.view(target.eval("local_variables + instance_variables + #{c}"))}"
extras += target.eval("self.class.constants") if params.include?("c")
output.puts "#{Pry.view(target.eval("local_variables + instance_variables + #{extras.inspect}"))}"
end
end
@ -104,6 +113,17 @@ class Pry
output.puts code
end
command "show_command", "Show sourcecode for a Pry command, e.g: show_command ls" do |command_name|
cmds = Pry.active_instance.commands.commands
if cmds[command_name]
code = cmds[command_name][:action].source
output.puts code
else
output.puts "No such command: #{command_name}."
end
end
command "jump_to", "Jump to a Pry session further up the stack, exiting all sessions below." do |break_level|
break_level = break_level.to_i
nesting = opts[:nesting]

View File

@ -2,7 +2,7 @@ class Pry
# The default hooks - display messages when beginning and ending Pry sessions.
DEFAULT_HOOKS = {
:before_session => proc { |out, obj| out.puts "Beginning Pry session for #{Pry.view(obj)}" },
:after_session => proc { |out, obj| out.puts "Ending Pry session for #{Pry.view(obj)}" }
:before_session => proc { |out, obj| out.puts "Beginning Pry session for #{Pry.view_clip(obj)}" },
:after_session => proc { |out, obj| out.puts "Ending Pry session for #{Pry.view_clip(obj)}" }
}
end

View File

@ -1,20 +1,22 @@
class Pry
# The default prompt; includes the target and nesting level
DEFAULT_PROMPT = [
proc do |target_self, nest_level|
if nest_level == 0
"pry(#{Pry.view(target_self)})> "
"pry(#{Pry.view_clip(target_self)})> "
else
"pry(#{Pry.view(target_self)}):#{Pry.view(nest_level)}> "
"pry(#{Pry.view_clip(target_self)}):#{Pry.view_clip(nest_level)}> "
end
end,
proc do |target_self, nest_level|
if nest_level == 0
"pry(#{Pry.view(target_self)})* "
"pry(#{Pry.view_clip(target_self)})* "
else
"pry(#{Pry.view(target_self)}):#{Pry.view(nest_level)}* "
"pry(#{Pry.view_clip(target_self)}):#{Pry.view_clip(nest_level)}* "
end
end
]

View File

@ -81,6 +81,19 @@ class Pry
end
end
# A version of `Pry.view` that clips the output to `max_size` chars.
# In case of > `max_size` chars the `#<Object...> notation is used.
# @param obj The object to view.
# @param max_size The maximum number of chars before clipping occurs.
# @return [String] The string representation of `obj`.
def self.view_clip(obj, max_size=60)
if Pry.view(obj).size < max_size
Pry.view(obj)
else
"#<#{obj.class}:%#x>" % (obj.object_id << 1)
end
end
# Set all the configurable options back to their default values
def self.reset_defaults
@input = Readline

View File

@ -1,3 +1,3 @@
class Pry
VERSION = "0.4.8"
VERSION = "0.4.9pre1"
end