Method: Terraspace::Shell#handle_input

Defined in:
lib/terraspace/shell.rb

#handle_input(stdin, line) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/terraspace/shell.rb', line 103

def handle_input(stdin, line)
  # Edge case: "value:" chopped off "Enter a" and "value" prompt
  #   This means "Enter a value:" is not needed but leaving it for now
  patterns = [
    /^ value:/,
    "Enter a value:",
    "\e[0m\e[1mvar.", # prompts for variable input. can happen on plan or apply. looking for bold marker also in case "var." shows up somewhere else
  ]
  matched = patterns.any? do |pattern|
    if pattern.is_a?(String)
      line.include?(pattern)
    else # Regexp
      line.match(pattern)
    end
  end
  if matched
    answer = $stdin.gets
    logger.stdin_capture(answer.strip)
    stdin.write_nonblock(answer)
  end
end