From 8fadbe5f3e5e8b2d9f635a274b4121811313de84 Mon Sep 17 00:00:00 2001 From: drbrain Date: Fri, 13 Dec 2013 00:51:04 +0000 Subject: * lib/rubygems: Update to RubyGems master ddac51f. Changes: * Allow override for the shared gem installation directory for rubygems packagers. * Lock gem cache files for read and write to improve thread safety. * Use io/console when available. * Minor cleanup. * test/rubygems: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44157 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rubygems/user_interaction.rb | 71 ++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 43 deletions(-) (limited to 'lib/rubygems/user_interaction.rb') diff --git a/lib/rubygems/user_interaction.rb b/lib/rubygems/user_interaction.rb index fad29b4afd..f5e460f994 100644 --- a/lib/rubygems/user_interaction.rb +++ b/lib/rubygems/user_interaction.rb @@ -4,6 +4,11 @@ # See LICENSE.txt for permissions. #++ +begin + require 'io/console' +rescue LoadError +end + ## # Module that defines the default UserInteraction. Any class including this # module will have access to the +ui+ method that returns the default UI. @@ -283,41 +288,27 @@ class Gem::StreamUI result end - if RUBY_VERSION > '1.9.2' then - ## - # Ask for a password. Does not echo response to terminal. - - def ask_for_password(question) - return nil if not tty? - - require 'io/console' - - @outs.print(question + " ") - @outs.flush + ## + # Ask for a password. Does not echo response to terminal. - password = @ins.noecho {@ins.gets} - password.chomp! if password - password - end - else - ## - # Ask for a password. Does not echo response to terminal. + def ask_for_password(question) + return nil if not tty? - def ask_for_password(question) - return nil if not tty? + @outs.print(question, " ") + @outs.flush - @outs.print(question + " ") - @outs.flush + password = _gets_noecho + @outs.puts + password.chomp! if password + password + end - Gem.win_platform? ? ask_for_password_on_windows : ask_for_password_on_unix + if IO.method_defined?(:noecho) then + def _gets_noecho + @ins.noecho {@ins.gets} end - - ## - # Asks for a password that works on windows. Ripped from the Heroku gem. - - def ask_for_password_on_windows - return nil if not tty? - + elsif Gem.win_platform? + def _gets_noecho require "Win32API" char = nil password = '' @@ -330,22 +321,16 @@ class Gem::StreamUI password << char.chr end end - - puts password end - - ## - # Asks for a password that works on unix - - def ask_for_password_on_unix - return nil if not tty? - + else + def _gets_noecho system "stty -echo" - password = @ins.gets - password.chomp! if password - system "stty echo" - password + begin + @ins.gets + ensure + system "stty echo" + end end end -- cgit v1.2.3