mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
18c45d26c5
This will greatly ease Pry support on Ruby 3.0 (when it's out).
28 lines
962 B
Ruby
28 lines
962 B
Ruby
# frozen_string_literal: true
|
|
|
|
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 ..`.
|
|
def self.default(pry_instance)
|
|
if !pry_instance.eval_string.empty?
|
|
# Clear input buffer.
|
|
pry_instance.eval_string = ''
|
|
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).
|
|
cd_state = Pry::CommandState.default.state_for('cd')
|
|
cd_state.old_stack = pry_instance.binding_stack.dup
|
|
pry_instance.binding_stack.pop
|
|
end
|
|
end
|
|
end
|
|
end
|