class Gem::StreamUI

def _gets_noecho

def _gets_noecho
  @ins.noecho {@ins.gets}
end

def _gets_noecho

def _gets_noecho
  require "Win32API"
  password = ''
  while char = Win32API.new("crtdll", "_getch", [ ], "L").Call do
    break if char == 10 || char == 13 # received carriage return or newline
    if char == 127 || char == 8 # backspace and delete
      password.slice!(-1, 1)
    else
      password << char.chr
    end
  end
  password
end

def _gets_noecho

def _gets_noecho
  system "stty -echo"
  begin
    @ins.gets
  ensure
    system "stty echo"
  end
end

def alert(statement, question=nil)

def alert(statement, question=nil)
  @outs.puts "INFO:  #{statement}"
  ask(question) if question
end

def alert_error(statement, question=nil)

def alert_error(statement, question=nil)
  @errs.puts "ERROR:  #{statement}"
  ask(question) if question
end

def alert_warning(statement, question=nil)

def alert_warning(statement, question=nil)
  @errs.puts "WARNING:  #{statement}"
  ask(question) if question
end

def ask(question)

def ask(question)
  return nil if not tty?
  @outs.print(question + "  ")
  @outs.flush
  result = @ins.gets
  result.chomp! if result
  result
end

def ask_for_password(question)

def ask_for_password(question)
  return nil if not tty?
  @outs.print(question, "  ")
  @outs.flush
  password = _gets_noecho
  @outs.puts
  password.chomp! if password
  password
end

def ask_yes_no(question, default=nil)

def ask_yes_no(question, default=nil)
  unless tty? then
    if default.nil? then
      raise Gem::OperationNotSupportedError,
            "Not connected to a tty and no default specified"
    else
      return default
    end
  end
  default_answer = case default
                   when nil
                     'yn'
                   when true
                     'Yn'
                   else
                     'yN'
                   end
  result = nil
  while result.nil? do
    result = case ask "#{question} [#{default_answer}]"
             when /^y/i then true
             when /^n/i then false
             when /^$/  then default
             else            nil
             end
  end
  return result
end

def backtrace exception

def backtrace exception
  return unless Gem.configuration.backtrace
  @errs.puts "\t#{exception.backtrace.join "\n\t"}"
end

def choose_from_list(question, list)

def choose_from_list(question, list)
  @outs.puts question
  list.each_with_index do |item, index|
    @outs.puts " #{index+1}. #{item}"
  end
  @outs.print "> "
  @outs.flush
  result = @ins.gets
  return nil, nil unless result
  result = result.strip.to_i - 1
  return list[result], result
end

def close

def close
end

def debug(statement)

def debug(statement)
  @errs.puts statement
end

def download_reporter(*args)

def download_reporter(*args)
  case Gem.configuration.verbose
  when nil, false
    SilentDownloadReporter.new(@outs, *args)
  else
    VerboseDownloadReporter.new(@outs, *args)
  end
end

def initialize(in_stream, out_stream, err_stream=STDERR, usetty=true)

def initialize(in_stream, out_stream, err_stream=STDERR, usetty=true)
  @ins = in_stream
  @outs = out_stream
  @errs = err_stream
  @usetty = usetty
end

def progress_reporter(*args)

def progress_reporter(*args)
  case Gem.configuration.verbose
  when nil, false
    SilentProgressReporter.new(@outs, *args)
  when true
    SimpleProgressReporter.new(@outs, *args)
  else
    VerboseProgressReporter.new(@outs, *args)
  end
end

def say(statement="")

def say(statement="")
  @outs.puts statement
end

def terminate_interaction(status = 0)

def terminate_interaction(status = 0)
  close
  raise Gem::SystemExitException, status
end

def tty?

def tty?
  if RUBY_VERSION < '1.9.3' and RUBY_PLATFORM =~ /mingw|mswin/ then
    @usetty
  else
    @usetty && @ins.tty?
  end
end