1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

more docs for hooks, print, and prompts

This commit is contained in:
John Mair 2011-01-19 21:40:43 +13:00
parent 7fa4750650
commit cb9df87779
4 changed files with 19 additions and 10 deletions

View file

@ -49,7 +49,7 @@ effect:
Test.instance_variable_get(:@y) #=> 20 Test.instance_variable_get(:@y) #=> 20
#### Alternative Syntax ### Alternative Syntax
You can also use the `Pry.start(obj)` or `pry(obj)` syntax to start a pry session on You can also use the `Pry.start(obj)` or `pry(obj)` syntax to start a pry session on
`obj`. e.g `obj`. e.g
@ -64,8 +64,8 @@ OR
beginning Pry session for 6 beginning Pry session for 6
pry(6)> pry(6)>
Example: Pry sessions can nest arbitrarily deep so we can pry on objects inside objects: Example: Pry sessions can nest arbitrarily deep
---------------------------------------------------------------------------------------- -----------------------------------------------
Here we will begin Pry at top-level, then pry on a class and then on Here we will begin Pry at top-level, then pry on a class and then on
an instance variable inside that class: an instance variable inside that class:
@ -139,7 +139,7 @@ uses (such as implementing a quake-like console for games, for example). Here is
list of Pry's features along with some of its limitations given at the list of Pry's features along with some of its limitations given at the
end. end.
####Features: ###Features:
* Pry can be invoked at any time and on any object in the running program. * Pry can be invoked at any time and on any object in the running program.
* Pry sessions can nest arbitrarily deeply -- to go back one level of nesting type 'exit' or 'quit' or 'back' * Pry sessions can nest arbitrarily deeply -- to go back one level of nesting type 'exit' or 'quit' or 'back'
@ -159,7 +159,7 @@ for reading; `Pry#re` for eval; `Pry#rep` for printing; and `Pry#repl`
for the loop (`Pry.start` simply wraps `Pry.new.repl`). You can for the loop (`Pry.start` simply wraps `Pry.new.repl`). You can
invoke any of these methods directly depending on exactly what aspect of the functionality you need. invoke any of these methods directly depending on exactly what aspect of the functionality you need.
####Limitations: ###Limitations:
* Pry does not pretend to be a replacement for `irb`, * Pry does not pretend to be a replacement for `irb`,
and so does not have an executable. It is designed to be used by and so does not have an executable. It is designed to be used by
@ -265,7 +265,7 @@ passing config hash options to `Pry.start()` or to `Pry.new()`; also the
same accessors as described above for the `Pry` class exist for a same accessors as described above for the `Pry` class exist for a
Pry instance so that customization can occur during runtime. Pry instance so that customization can occur during runtime.
### Input: ### Input
For input Pry accepts any object that implements the `readline` method. This For input Pry accepts any object that implements the `readline` method. This
includes `IO` objects, `StringIO`, `Readline` and custom objects. Pry includes `IO` objects, `StringIO`, `Readline` and custom objects. Pry
@ -367,7 +367,7 @@ Then inside a pry session:
As in the case of `input` and `output`: As in the case of `input` and `output`:
##### At session start: ##### At session start:
nnnnn
Pry.start(self, :commands => MyCommands) Pry.start(self, :commands => MyCommands)
##### At runtime: ##### At runtime:
@ -405,7 +405,7 @@ command.
#### opts hash #### opts hash
Note that in the example above we are using `opts[:output]` for output; this is the output Note that in the example above we are using `opts[:output]` for output; this is the output
object in use by the current pry session. Other hash values accesible object in use by the current pry session. Other hash values accessible
within a `command` block include: within a `command` block include:
* `opts[:output]` - The session's output object. * `opts[:output]` - The session's output object.
@ -521,7 +521,7 @@ The print object should be a `Proc` and the parameters passed to the
`Proc` are the output object for the current session and the 'value' `Proc` are the output object for the current session and the 'value'
returned by the current expression. returned by the current expression.
#### Example: Setting global prompt #### Example: Setting global print object
Let's define a print object that displays the full backtrace of any Let's define a print object that displays the full backtrace of any
exception and precedes the output of a value by the text `"Output is: "`: exception and precedes the output of a value by the text `"Output is: "`:
@ -535,7 +535,7 @@ exception and precedes the output of a value by the text `"Output is: "`:
end end
end end
#### Example: Setting the prompt for a specific session #### Example: Setting the print object for a specific session
##### At session start ##### At session start
@ -566,3 +566,4 @@ Problems or questions contact me at [github](http://github.com/banister)
]

View file

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

View file

@ -1,4 +1,7 @@
class Pry class Pry
# The default print object - only show first line of backtrace and
# prepend output with `=>`
DEFAULT_PRINT = proc do |output, value| DEFAULT_PRINT = proc do |output, value|
case value case value
when Exception when Exception

View file

@ -1,4 +1,6 @@
class Pry class Pry
# The default prompt; includes the target
DEFAULT_PROMPT = [ DEFAULT_PROMPT = [
proc do |target_self, nest_level| proc do |target_self, nest_level|
if nest_level == 0 if nest_level == 0
@ -17,5 +19,6 @@ class Pry
end end
] ]
# A simple prompt - doesn't display target or nesting level
SIMPLE_PROMPT = [proc { "pry> " }, proc { "pry* " }] SIMPLE_PROMPT = [proc { "pry> " }, proc { "pry* " }]
end end