Sha256: 0eae0e2ec2c31378b5ef3f0b643adf1dc70236db80c99dda196f2dd727df4f6a

Contents?: true

Size: 1002 Bytes

Versions: 76

Compression:

Stored size: 1002 Bytes

Contents

require 'timeout'
module Eco
  module API
    module Common
      module Session
        module Helpers
          module PromptUser

            def prompt_user(question, default:, explanation: "", timeout: nil)
              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

76 entries across 76 versions & 1 rubygems

Version Path
eco-helpers-2.4.9 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.4.8 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.4.7 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.4.6 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.4.5 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.4.4 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.4.3 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.4.2 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.3.3 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.3.2 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.2.5 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.2.4 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.2.3 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.2.2 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.2.1 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.1.12 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.1.11 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.1.10 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.1.9 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.1.8 lib/eco/api/common/session/helpers/prompt_user.rb