Can prompt.ask
be cancelled using escape?
#170
-
I'm asking a simple question like this: name = prompt.ask "What is your name?", default: "John Doe" Can I somehow have the I've been experimenting with the prompt.on(:keyescape) { print "escape has been pressed."; @escape_pressed = true }
name = prompt.ask "What is your name?", default: "John Doe"
unless @escape_pressed
# ...
end In the above code, the Thank you very much! |
Beta Was this translation helpful? Give feedback.
Answered by
piotrmurach
Jul 14, 2021
Replies: 1 comment 1 reply
-
You could raise an error: prompt.on(:keypress) do
raise EscapePressedError
end Then rescue an begin
name = prompt.ask "What is your name?", default: "John Doe"
rescue EscapePressedError
puts "bailing out..."
end |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
fiedl
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could raise an error:
Then rescue an
ask
call like so: