diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-02-22 02:52:35 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-02-22 02:52:35 +0000 |
commit | b551e8c8b36766651be4e782e09e3b02e7d14a10 (patch) | |
tree | e164a1ef908bd4451568abf05b688f1593915b81 /lib/rubygems/user_interaction.rb | |
parent | 65544f575b25b18dc27f9364f973556ddb48538f (diff) | |
download | ruby-b551e8c8b36766651be4e782e09e3b02e7d14a10.tar.gz |
* lib/rubygems: update to 1.3.6.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26728 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/user_interaction.rb')
-rw-r--r-- | lib/rubygems/user_interaction.rb | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/rubygems/user_interaction.rb b/lib/rubygems/user_interaction.rb index 6a80c7c0bc..1ab948dcb6 100644 --- a/lib/rubygems/user_interaction.rb +++ b/lib/rubygems/user_interaction.rb @@ -112,6 +112,7 @@ module Gem::UserInteraction :alert_error, :alert_warning, :ask, + :ask_for_password, :ask_yes_no, :choose_from_list, :say, @@ -218,6 +219,50 @@ class Gem::StreamUI end ## + # Ask for a password. Does not echo response to terminal. + + def ask_for_password(question) + return nil if not @ins.tty? + + @outs.print(question + " ") + @outs.flush + + Gem.win_platform? ? ask_for_password_on_windows : ask_for_password_on_unix + end + + ## + # Asks for a password that works on windows. Ripped from the Heroku gem. + + def ask_for_password_on_windows + require "Win32API" + char = nil + 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 + + puts + password + end + + ## + # Asks for a password that works on unix + + def ask_for_password_on_unix + system "stty -echo" + password = @ins.gets + password.chomp! if password + system "stty echo" + password + end + + ## # Display a statement. def say(statement="") |