Sha256: 57797dede0c65b78e38ea5f7ef2eac29c2a9c0352128f9364c9e95eff930af73

Contents?: true

Size: 993 Bytes

Versions: 32

Compression:

Stored size: 993 Bytes

Contents

module Eco
  module API
    module Common
      module Session
        module Helpers
          module PromptUser
            # Prompts user for input with option for default on timeout.
            def prompt_user(question, default:, explanation: "", timeout: nil)
              require 'timeout'
              response = \
                if config.run_mode_remote?
                  default
                else
                  puts explanation
                  print "#{question} "
                  if timeout
                    begin
                      Timeout::timeout(timeout) { STDIN.gets.chop }
                    rescue Timeout::Error
                      default
                    end
                  else
                    STDIN.gets.chop
                  end
                end
              return response unless block_given?
              yield(response)
            end
          end
        end
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
eco-helpers-2.7.24 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.7.23 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.7.22 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.7.21 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.7.20 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.7.19 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.7.18 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.7.17 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.7.16 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.7.15 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.7.14 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.7.13 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.7.12 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.7.4 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.7.2 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.7.1 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.7.0 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.6.4 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.6.3 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.6.2 lib/eco/api/common/session/helpers/prompt_user.rb