pry 0.6.7-i386-mingw32

Sign up to get free protection for your applications and to get access to all the features.
data/bin/pry ADDED
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # (C) John Mair (banisterfiend)
4
+ # MIT license
5
+
6
+ begin
7
+ require 'pry'
8
+ rescue LoadError
9
+ require 'rubygems'
10
+ require 'pry'
11
+ end
12
+ require 'optparse'
13
+
14
+ # defaults
15
+ options = {
16
+ :context_string => "TOPLEVEL_BINDING",
17
+ :loadrc => true
18
+ }
19
+
20
+ OptionParser.new do |opts|
21
+ opts.banner = %{Usage: pry [OPTIONS]
22
+ Start a Pry session.
23
+ See: `https://github.com/banister` for more information.
24
+ --
25
+ }
26
+ opts.on("-r", "--require FILE", "`require` a Ruby script at startup.") do |file|
27
+ require file
28
+ end
29
+
30
+ opts.on("-e", "--exec CODE", "A line of Ruby code to execute in context before the session starts.") do |code|
31
+ options[:code] = code
32
+ end
33
+
34
+ opts.on("-f", "Suppress loading of ~/.pryrc") do
35
+ options[:loadrc] = false
36
+ end
37
+
38
+ opts.on("--color", "Start session with syntax highlighting on.") do
39
+ Pry.color = true
40
+ end
41
+
42
+ opts.on("--simple-prompt", "Simple prompt mode.") do
43
+ Pry.prompt = Pry::SIMPLE_PROMPT
44
+ end
45
+
46
+ opts.on("-I LOADPATH", "Specify $LOAD_PATH directory.") do |load_path|
47
+ $LOAD_PATH << load_path
48
+ end
49
+
50
+ opts.on("-v", "--version", "Display the Pry version.") do
51
+ puts "Pry version #{Pry::VERSION} on Ruby #{RUBY_VERSION}"
52
+ exit
53
+ end
54
+
55
+ opts.on("-c", "--context CONTEXT",
56
+ "Start the session in the specified context. Equivalent to `context.pry` in a session.") do |context|
57
+
58
+ # save the context name
59
+ options[:context_string] = context
60
+ end
61
+
62
+ opts.on_tail("-h", "--help", "This message.") do
63
+ puts opts
64
+ exit
65
+ end
66
+ end.parse!
67
+
68
+ rcpath = File.expand_path("~/.pryrc")
69
+
70
+ # load ~/.pryrc, if not suppressed with -f option
71
+ load rcpath if File.exists?(rcpath) && options[:loadrc]
72
+
73
+ # create the actual context
74
+ context = Pry.binding_for(eval(options[:context_string]))
75
+
76
+ # run code passed with `-e`, if there is any.
77
+ if options[:code]
78
+ Pry.new(:input => StringIO.new(options[:code]), :print => proc {}).rep(context)
79
+ end
80
+
81
+ # start the session
82
+ context.pry
@@ -0,0 +1,17 @@
1
+ direc = File.dirname(__FILE__)
2
+
3
+ require 'rubygems'
4
+ require "#{direc}/../lib/pry"
5
+
6
+ # define a local.
7
+ a = "a local variable"
8
+
9
+ # defing a top-level method.
10
+ def hello
11
+ puts "hello world!"
12
+ end
13
+
14
+ # Start pry session at top-level.
15
+ # The local variable `a` and the `hello` method will
16
+ # be accessible.
17
+ pry
@@ -0,0 +1,35 @@
1
+ direc = File.dirname(__FILE__)
2
+
3
+ require 'rubygems'
4
+ require "#{direc}/../lib/pry"
5
+
6
+ # Inherit standard command set, but tweak them by importing some and
7
+ # overriding others.
8
+ # Illustrates use of `command`, `run`, and `import_from` commands.
9
+ class MyCommands < Pry::CommandBase
10
+
11
+ # Override ls command
12
+ command "ls", "An unhelpful ls" do
13
+ output.puts "No, i refuse to display any useful information."
14
+ end
15
+
16
+ # bring in just the status command from Pry::Commands
17
+ import_from Pry::Commands, "status"
18
+
19
+ # analogy to Ruby's native alias_method idiom for decorating a method
20
+ alias_command "old_status", "status", ""
21
+
22
+ # Invoke one command from within another using `run`
23
+ command "status", "Modified status." do |x|
24
+ output.puts "About to show status, are you ready?"
25
+ run "old_status", x
26
+ output.puts "Finished showing status."
27
+ end
28
+
29
+ # bring in a few other commands
30
+ import_from Pry::Commands, "quit", "show-method"
31
+ end
32
+
33
+ # Start a Pry session using the commands defined in MyCommands
34
+ # Type 'help' in Pry to get a list of the commands and their descriptions
35
+ Pry.start(TOPLEVEL_BINDING, :commands => MyCommands)
@@ -0,0 +1,39 @@
1
+ direc = File.dirname(__FILE__)
2
+
3
+ require 'rubygems'
4
+ require "#{direc}/../lib/pry"
5
+
6
+ class MathCommands < Pry::CommandBase
7
+ command "greet", "Greet a person, e.g: greet john" do |name|
8
+ output.puts "Good afternoon #{name.capitalize}! Do you like Math?"
9
+ end
10
+
11
+ command "add", "Add a list of numbers together, e.g: add 1 2 3 4" do |*args|
12
+ output.puts "Total: #{args.map(&:to_f).inject(&:+)}"
13
+ end
14
+
15
+ command "multiply", "Multiply a list of numbers together, e.g: multiply 1 2 3 4" do |*args|
16
+ output.puts "Total: #{args.map(&:to_f).inject(&:*)}"
17
+ end
18
+
19
+ # Explicitly giving a description of "" to prevent command being
20
+ # displayed in 'help'
21
+ command "exit", "" do
22
+ throw :breakout, 0
23
+ end
24
+
25
+ # Bring in the "!" method from Pry::Commands
26
+ import_from Pry::Commands, "!"
27
+ end
28
+
29
+ # Since we provide math commands, let's have mathematical
30
+ # before_session and after_session hooks, and a mathematical prompt
31
+ math_prompt = [proc { "math> " }, proc { "math* " }]
32
+ math_hooks = {
33
+ :before_session => proc { |output, *| output.puts "Welcome! Let's do some math! Type 'help' for a list of commands." },
34
+ :after_session => proc { |output, *| output.puts "Goodbye!" }
35
+ }
36
+
37
+ # Start a Pry session using the commands defined in MyCommands
38
+ # Type 'help' in Pry to get a list of the commands and their descriptions
39
+ Pry.start(TOPLEVEL_BINDING, :commands => MathCommands, :prompt => math_prompt, :hooks => math_hooks)
@@ -0,0 +1,12 @@
1
+ direc = File.dirname(__FILE__)
2
+
3
+ require 'rubygems'
4
+ require "#{direc}/../lib/pry"
5
+
6
+ my_hooks = {
7
+ :before_session => proc { |out, obj| out.puts "Opening #{obj}." },
8
+ :after_session => proc { |out, obj| out.puts "Closing #{obj}." }
9
+ }
10
+
11
+ # Start a Pry session using the hooks hash defined in my_hooks
12
+ Pry.start(TOPLEVEL_BINDING, :hooks => my_hooks)
@@ -0,0 +1,71 @@
1
+ # Note: this requires you to have Gosu and TexPlay installed.
2
+ # `gem install gosu`
3
+ # `gem install texplay`
4
+ #
5
+ # Extra instructions for installing Gosu on Linux can be found here:
6
+ # http://code.google.com/p/gosu/wiki/GettingStartedOnLinux
7
+ #
8
+ # Instructions for using TexPlay can be found here:
9
+ # http://banisterfiend.wordpress.com/2008/08/23/texplay-an-image-manipulation-tool-for-ruby-and-gosu/
10
+ #
11
+ # Have fun! :)
12
+
13
+ direc = File.dirname(__FILE__)
14
+
15
+ require 'rubygems'
16
+ require "texplay"
17
+ require "#{direc}/../lib/pry"
18
+
19
+ WIDTH = 640
20
+ HEIGHT = 480
21
+
22
+ IMAGE_PROMPT = [ proc { "(image edit)> " }, proc { "(image edit)* " } ]
23
+
24
+ class ImageCommands < Pry::CommandBase
25
+ command "drawing_methods", "Show a list of TexPlay methods" do
26
+ output.puts "#{Pry.view(TexPlay.public_instance_methods)}"
27
+ end
28
+
29
+ command "exit", "Exit the program." do
30
+ output.puts "Thanks for dropping by!"
31
+ exit
32
+ end
33
+
34
+ import_from Pry::Commands, "ls", "!"
35
+ end
36
+
37
+ class WinClass < Gosu::Window
38
+
39
+ def initialize
40
+ super(WIDTH, HEIGHT, false)
41
+ @img = TexPlay.create_image(self, 200, 200).clear :color => :black
42
+ @img.rect 0, 0, @img.width - 1, @img.height - 1
43
+
44
+ @binding = Pry.binding_for(@img)
45
+
46
+ @pry_instance = Pry.new(:commands => ImageCommands, :prompt => IMAGE_PROMPT)
47
+ end
48
+
49
+ def draw
50
+ @img.draw_rot(WIDTH / 2, HEIGHT / 2, 1, 0, 0.5, 0.5)
51
+ end
52
+
53
+ def update
54
+ exit if button_down?(Gosu::KbEscape)
55
+
56
+ # We do not want a REPL session as the loop prevents the image
57
+ # being updated; instead we do a REP session, and let the image
58
+ # update each time the user presses enter. We maintain the same
59
+ # binding object to keep locals between calls to `Pry#rep()`
60
+ @pry_instance.rep(@binding)
61
+ end
62
+ end
63
+
64
+ puts "Welcome to ImageEdit; type `help` for a list of commands and `drawing_methods` for a list of drawing methods available."
65
+ puts "--"
66
+ puts "Example: Try typing 'circle width/2, height/2, 95, :color => :blue, :fill => true'"
67
+ puts "If you want to save your image, type: save(\"img.png\")"
68
+
69
+ w = WinClass.new
70
+ w.show
71
+
@@ -0,0 +1,10 @@
1
+ direc = File.dirname(__FILE__)
2
+
3
+ require 'rubygems'
4
+ require "#{direc}/../lib/pry"
5
+
6
+ # Create a StringIO that contains the input data
7
+ str_input = StringIO.new("puts 'hello world!'\nputs \"I am in \#{self}\"\nexit")
8
+
9
+ # Start a Pry session on the Fixnum 5 using the input data in str_input
10
+ Pry.start(5, :input => str_input)
@@ -0,0 +1,32 @@
1
+ direc = File.dirname(__FILE__)
2
+
3
+ require 'rubygems'
4
+ require "#{direc}/../lib/pry"
5
+
6
+ # Create a StringIO that contains the input data for all the Pry objects
7
+ cmds = <<-CMDS
8
+ cd 1
9
+ status
10
+ puts 'hello from 1!!'
11
+ cd 2
12
+ nesting
13
+ puts 'hello from 2!!'
14
+ _pry_.parent.input = Readline
15
+ back
16
+ exit-all
17
+ CMDS
18
+
19
+ # create our StringIO object
20
+ str_input = StringIO.new(cmds)
21
+
22
+ # set global input to str_input, this means that all pry sessions
23
+ # adopt this object as their input object.
24
+ Pry.input = str_input
25
+
26
+ # Start the session reading from str_input.
27
+ # Note that because `Pry.input` is set to `str_input` all nested pry
28
+ # sessions will read from `str_input` too. All pry sessions are there
29
+ # for non-interactive, except for `pry(1)` which starts off
30
+ # non-interactive but is set to be interactive by pry(2) (using
31
+ # _pry_.parent.input = Readline)
32
+ 0.pry
@@ -0,0 +1,14 @@
1
+ direc = File.dirname(__FILE__)
2
+
3
+ require 'rubygems'
4
+ require "#{direc}/../lib/pry"
5
+
6
+ # Create a StringIO to contain the output data
7
+ str_output = StringIO.new
8
+
9
+ # Start a Pry session on the Fixnum 5 using str_output to store the
10
+ # output (not writing to $stdout)
11
+ Pry.start(5, :output => str_output)
12
+
13
+ # Display all the output accumulated during the session
14
+ puts str_output.string
@@ -0,0 +1,9 @@
1
+ direc = File.dirname(__FILE__)
2
+
3
+ require 'rubygems'
4
+ require "#{direc}/../lib/pry"
5
+
6
+ my_print = proc { |out, value| out.puts "Output is: #{value.inspect}" }
7
+
8
+ # Start a Pry session using the print object defined in my_print
9
+ Pry.start(TOPLEVEL_BINDING, :print => my_print)
@@ -0,0 +1,12 @@
1
+ direc = File.dirname(__FILE__)
2
+
3
+ require 'rubygems'
4
+ require "#{direc}/../lib/pry"
5
+
6
+ # Remember, first prompt in array is the main prompt, second is the wait
7
+ # prompt (used for multiline input when more input is required)
8
+ my_prompt = [ proc { |obj, *| "inside #{obj}> " },
9
+ proc { |obj, *| "inside #{obj}* "} ]
10
+
11
+ # Start a Pry session using the prompt defined in my_prompt
12
+ Pry.start(TOPLEVEL_BINDING, :prompt => my_prompt)
@@ -0,0 +1,32 @@
1
+ # (C) John Mair (banisterfiend) 2011
2
+ # MIT License
3
+
4
+ direc = File.dirname(__FILE__)
5
+
6
+ $LOAD_PATH << File.expand_path(direc)
7
+
8
+ require "method_source"
9
+ require 'shellwords'
10
+ require "readline"
11
+ require "stringio"
12
+ require "coderay"
13
+
14
+ if RUBY_PLATFORM =~ /mswin/ || RUBY_PLATFORM =~ /mingw/
15
+ begin
16
+ require 'win32console'
17
+ rescue LoadError
18
+ $stderr.puts "Need to `gem install win32console`"
19
+ exit 1
20
+ end
21
+ end
22
+
23
+ require "pry/version"
24
+ require "pry/hooks"
25
+ require "pry/print"
26
+ require "pry/command_base"
27
+ require "pry/commands"
28
+ require "pry/prompts"
29
+ require "pry/completion"
30
+ require "pry/core_extensions"
31
+ require "pry/pry_class"
32
+ require "pry/pry_instance"
@@ -0,0 +1,150 @@
1
+ class Pry
2
+
3
+ # Basic command functionality. All user-defined commands must
4
+ # inherit from this class. It provides the `command` method.
5
+ class CommandBase
6
+ class << self
7
+ attr_accessor :commands
8
+ attr_accessor :opts, :output, :target
9
+
10
+ # private because we want to force function style invocation. We require
11
+ # that the location where the block is defined has the `opts`
12
+ # method in scope.
13
+ private
14
+
15
+ # Defines a new Pry command.
16
+ # @param [String, Array] names The name of the command (or array of
17
+ # command name aliases).
18
+ # @param [String] description A description of the command.
19
+ # @param [Hash] options The optional configuration parameters.
20
+ # @option options [Boolean] :keep_retval Whether or not to use return value
21
+ # of the block for return of `command` or just to return `nil`
22
+ # (the default).
23
+ # @yield The action to perform. The parameters in the block
24
+ # determines the parameters the command will receive. All
25
+ # parameters passed into the block will be strings. Successive
26
+ # command parameters are separated by whitespace at the Pry prompt.
27
+ # @example
28
+ # class MyCommands < Pry::CommandBase
29
+ # command "greet", "Greet somebody" do |name|
30
+ # puts "Good afternoon #{name.capitalize}!"
31
+ # end
32
+ # end
33
+ #
34
+ # # From pry:
35
+ # # pry(main)> _pry_.commands = MyCommands
36
+ # # pry(main)> greet john
37
+ # # Good afternoon John!
38
+ # # pry(main)> help greet
39
+ # # Greet somebody
40
+ def command(names, description="No description.", options={}, &block)
41
+ options = {
42
+ :keep_retval => false
43
+ }.merge!(options)
44
+
45
+ @commands ||= {}
46
+
47
+ Array(names).each do |name|
48
+ commands[name] = {
49
+ :description => description,
50
+ :action => block,
51
+ :keep_retval => options[:keep_retval]
52
+ }
53
+ end
54
+ end
55
+
56
+ # Delete a command or an array of commands.
57
+ # Useful when inheriting from another command set and pruning
58
+ # those commands down to the ones you want.
59
+ # @param [Array<String>] names The command name or array
60
+ # of command names you want to delete
61
+ # @example Deleteing inherited commands
62
+ # class MyCommands < Pry::Commands
63
+ # delete "show_method", "show_imethod", "show_doc", "show_idoc"
64
+ # end
65
+ # Pry.commands = MyCommands
66
+ def delete(*names)
67
+ names.each { |name| commands.delete(name) }
68
+ end
69
+
70
+ # Execute a command (this enables commands to call other commands).
71
+ # @param [String] name The command to execute
72
+ # @param [Array] args The parameters to pass to the command.
73
+ # @example Wrap one command with another
74
+ # class MyCommands < Pry::Commands
75
+ # command "ls2" do
76
+ # output.puts "before ls"
77
+ # run "ls"
78
+ # output.puts "after ls"
79
+ # end
80
+ # end
81
+ def run(name, *args)
82
+ action = opts[:commands][name][:action]
83
+ instance_exec(*args, &action)
84
+ end
85
+
86
+ # Import commands from another command object.
87
+ # @param [Pry::CommandBase] klass The class to import from (must
88
+ # be a subclass of `Pry::CommandBase`)
89
+ # @param [Array<String>] names The commands to import.
90
+ # @example
91
+ # class MyCommands < Pry::CommandBase
92
+ # import_from Pry::Commands, "ls", "show_method", "cd"
93
+ # end
94
+ def import_from(klass, *names)
95
+ imported_hash = Hash[klass.commands.select { |k, v| names.include?(k) }]
96
+ commands.merge!(imported_hash)
97
+ end
98
+
99
+ # Create an alias for a command.
100
+ # @param [String] new_command The alias name.
101
+ # @param [String] orig_command The original command name.
102
+ # @param [String] desc The optional description.
103
+ # @example
104
+ # class MyCommands < Pry::CommandBase
105
+ # alias_command "help_alias", "help"
106
+ # end
107
+ def alias_command(new_command_name, orig_command_name, desc=nil)
108
+ commands[new_command_name] = commands[orig_command_name].dup
109
+ commands[new_command_name][:description] = desc if desc
110
+ end
111
+
112
+ # Set the description for a command (replacing the old
113
+ # description.)
114
+ # @param [String] name The command name.
115
+ # @param [String] description The command description.
116
+ # @example
117
+ # class MyCommands < Pry::CommandBase
118
+ # desc "help", "help description"
119
+ # end
120
+ def desc(name, description)
121
+ commands[name][:description] = description
122
+ end
123
+ end
124
+
125
+ command "help", "This menu." do |cmd|
126
+ command_info = opts[:commands]
127
+ param = cmd
128
+
129
+ if !param
130
+ output.puts "Command list:"
131
+ output.puts "--"
132
+ command_info.each do |k, data|
133
+ output.puts "#{k}".ljust(18) + data[:description] if !data[:description].empty?
134
+ end
135
+ else
136
+ if command_info[param]
137
+ output.puts command_info[param][:description]
138
+ else
139
+ output.puts "No info for command: #{param}"
140
+ end
141
+ end
142
+ end
143
+
144
+ # Ensures that commands can be inherited
145
+ def self.inherited(klass)
146
+ klass.commands = commands.dup
147
+ end
148
+
149
+ end
150
+ end