2019-05-02 18:33:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-04-14 20:18:17 -04:00
|
|
|
class Pry
|
|
|
|
# @api private
|
|
|
|
# @since ?.?.?
|
|
|
|
module ControlDHandler
|
|
|
|
# Deal with the ^D key being pressed. Different behaviour in different
|
|
|
|
# cases:
|
|
|
|
# 1. In an expression behave like `!` command.
|
|
|
|
# 2. At top-level session behave like `exit` command.
|
|
|
|
# 3. In a nested session behave like `cd ..`.
|
2019-05-04 11:09:57 -04:00
|
|
|
def self.default(pry_instance)
|
|
|
|
if !pry_instance.eval_string.empty?
|
|
|
|
# Clear input buffer.
|
|
|
|
pry_instance.eval_string = ''
|
2019-04-14 20:18:17 -04:00
|
|
|
elsif pry_instance.binding_stack.one?
|
|
|
|
pry_instance.binding_stack.clear
|
|
|
|
throw(:breakout)
|
|
|
|
else
|
|
|
|
# Otherwise, saves current binding stack as old stack and pops last
|
|
|
|
# binding out of binding stack (the old stack still has that binding).
|
2019-04-29 12:21:54 -04:00
|
|
|
cd_state = Pry::CommandState.default.state_for('cd')
|
|
|
|
cd_state.old_stack = pry_instance.binding_stack.dup
|
2019-04-14 20:18:17 -04:00
|
|
|
pry_instance.binding_stack.pop
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|