Sha256: 7551d52d093f01459ee5a4f7a516f6eda0f223c6657cdc48a15c466b277db0be

Contents?: true

Size: 678 Bytes

Versions: 1

Compression:

Stored size: 678 Bytes

Contents

# This is originally from: https://gist.github.com/2040373

module Bini
  # A few prompts I may need in making CLI's.
  module Prompts
    extend self
    def ask(*params)
      params = params[0] if params[0]
      raise RuntimeError, 'No interactive terminal present.' unless $stdin.tty?
      if params[:prompt]
        $stderr.print params[:prompt]
        $stderr.flush
      end
      if params[:password]
        raise RuntimeError 'Could not disable echo to ask for password security' unless system 'stty -echo -icanon'
      end
      output = $stdin.gets
      output.chomp! if output
      #unmuck the prompt.
      `stty echo icanon`
      output
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bini-0.5.5 lib/bini/prompts.rb