Skip to content

Can prompt.ask be cancelled using escape? #170

Answered by piotrmurach
fiedl asked this question in Q&A
Discussion options

You must be logged in to vote

You could raise an error:

prompt.on(:keypress) do
  raise EscapePressedError
end

Then rescue an ask call like so:

begin
  name = prompt.ask "What is your name?", default: "John Doe"
rescue EscapePressedError
  puts "bailing out..."
end

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@fiedl
Comment options

Answer selected by fiedl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants