-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
high like/agree default option? #275
Comments
It completely makes sense for me to have such feature documented. The current implementation of I believe, I think I can do it this week. 👍 |
Meanwhile, you can try this. I have changed the require "highline"
def agree_with_default(yes_or_no_question, character = nil, default:)
answer_type = ->(yn) { yn.downcase[0] == "y" || (yn.empty? && default.downcase[0] == "y") }
HighLine.ask(yes_or_no_question, answer_type) do |q|
q.validate = /\A(?:y(?:es)?|no?|)\Z/i
q.responses[:not_valid] = 'Please enter "yes" or "no".'
q.responses[:ask_on_error] = :question
q.character = character
q.completion = %w[yes no]
yield q if block_given?
end
end
# Using it
agree_with_default("Install lib xyz (yes/NO)?", true, default: "n") |
Have you considered using timeout with highline at all? Something simple like this might work? require 'timeout'
TIMEOUT_SECONDS = 10
begin
Timeout::timeout(TIMEOUT_SECONDS) do
<highline stuff with default>
end
rescue Timeout::Error
<do default>
end |
It would be a really nice addition. I use things like that in shell scripts like As soon as I get some free time I can try doing that. |
I added an implementation here: |
Nice. Perhaps we could do that from inside the "answer gathering" workflow. |
Is there a way to set a default value when using agree such that enter would choose that default?
(If that's not currently possible... This is a feature request.)
The text was updated successfully, but these errors were encountered: