added Pry.config.control_d_handler and also changed way control d (^D) works inside multi-line expressions (it clears input buffer)
This commit is contained in:
parent
34bfa3980c
commit
3e137e8b1b
|
@ -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)
|
||||
|
|
20
lib/pry.rb
20
lib/pry.rb
|
@ -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 { " | " }]
|
||||
|
|
|
@ -107,6 +107,10 @@ class Pry
|
|||
|
||||
# @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 @@ class Pry
|
|||
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 @@ class Pry
|
|||
|
||||
# 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.
|
||||
|
|
Loading…
Reference in New Issue