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.0.35 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.0.34 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.0.33 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.0.32 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.0.31 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.0.30 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.0.29 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.0.28 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.0.27 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.0.26 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.0.25 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.0.24 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.0.23 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.0.22 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.0.21 lib/eco/api/common/session/helpers/prompt_user.rb
eco-helpers-2.0.19 lib/eco/api/common/session/helpers/prompt_user.rb