Permalink
Browse files

added Pry.config.control_d_handler and also changed way control d (^D…

…) works inside multi-line expressions (it clears input buffer)
  • Loading branch information...
1 parent 34bfa39 commit 3e137e8b1ba9ff9c2c80420fb383ef3dcff68882 @banister banister committed Aug 29, 2011
Showing with 33 additions and 13 deletions.
  1. +3 −0 CHANGELOG
  2. +19 −1 lib/pry.rb
  3. +4 −0 lib/pry/config.rb
  4. +2 −0 lib/pry/pry_class.rb
  5. +5 −12 lib/pry/pry_instance.rb
View
@@ -12,6 +12,9 @@
* changed `exit` command so that it now called Kernel#exit (after saving history)
* 'quit' now behaves like 'exit-all' (and aliased to exit-all) - it breaks out of the repl loop and sets empties the binding_stack
* 'cd ..' just pops a binding off the binding_stack with special behaviour when only one binding in stack - it breaks out of the repl loop
+* show-method and show-doc now accept multiple method names
+* control_d hook added (Pry.config.control_d_handler)
+* behaviour of ^d is now to break out of current expr if in multi-line expr, or break out of current context if nested, or break out of pry repl loop if at top-level
*/7/2011 version 0.9.3
* cat --ex (cats 5 lines above and below line in file where exception was raised)
View
@@ -58,7 +58,25 @@ class Pry
"pry(#{Pry.view_clip(target_self)}):#{Pry.view_clip(nest_level)}* "
end
}
- ]
+ ]
+ # Deal with the ^D key being pressed, different behaviour in
+ # different cases:
+ # 1) In an expression - behave like `!` command (clear input buffer)
+ # 2) At top-level session - behave like `exit command (break out of repl loop)
+ # 3) In a nested session - behave like `cd ..` (pop a binding)
+ DEFAULT_CONTROL_D_HANDLER = proc do |eval_string, _pry_|
+ if !eval_string.empty?
+ # clear input buffer
+ eval_string.replace("")
+ elsif _pry_.binding_stack.one?
+ # ^D at top-level breaks out of loop
+ _pry_.binding_stack.clear
+ throw(:breakout)
+ else
+ # otherwise just pops a binding
+ _pry_.binding_stack.pop
+ end
+ end
# A simple prompt - doesn't display target or nesting level
SIMPLE_PROMPT = [proc { ">> " }, proc { " | " }]
View
@@ -107,6 +107,10 @@ class Config < OpenStruct
# @return [Integer] Amount of results that will be stored into out
attr_accessor :memory_size
+
+ # @return [Proc] The proc that manages ^D presses in the REPL.
+ # The proc is passed the current eval_string and the current pry instance.
+ attr_accessor :control_d_handler
end
end
@@ -236,6 +236,8 @@ def self.set_config_defaults
config.history.should_load = true
config.history.file = File.expand_path("~/.pry_history")
+ config.control_d_handler = DEFAULT_CONTROL_D_HANDLER
+
config.memory_size = 100
end
@@ -257,19 +257,12 @@ def retrieve_line(eval_string, target)
# exit session if we receive EOF character (^D)
if !val
- output.puts
- if binding_stack.one?
- # ^D at top-level breaks out of loop
- binding_stack.clear
- throw(:breakout)
- else
- # otherwise just pops a binding
- binding_stack.pop
- val = ""
- end
+ output.puts ""
+ Pry.config.control_d_handler.call(eval_string, self)
+ ""
+ else
+ val
end
-
- val
end
# Process the line received.

0 comments on commit 3e137e8

Please sign in to comment.