Class: Prompt

Inherits:
Object
  • Object
show all
Defined in:
lib/prompt.rb

Overview

Class for prompting in terminal

Instance Method Summary collapse

Instance Method Details

#ask(message, options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/prompt.rb', line 7

def ask(message, options = {})
  print "#{message} "
  input = $stdin.gets.chomp

  # Print input if running under specs
  Utilities.rspec_running? && (puts input)

  # Check for required input
  check_input(options, input)

  input
end

#mask(message, options = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/prompt.rb', line 20

def mask(message, options = {})
  # Use simple output for specs
  Utilities.rspec_running? && (ask(message, options) && return)

  print "#{message} "
  return unless $stdin.class.method_defined?(:noecho)

  pass = $stdin.noecho(&:gets).chomp

  # Check for required input
  check_input(options, pass)

  puts
  pass
end