From adf6297ec815edc2a4270384f83f0d96e09f25a1 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 8 May 2010 04:11:30 +0000 Subject: [PATCH] * lib/rubygems/user_interaction.rb (Gem::StreamUI#ask_for_password): use io/console. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27669 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 ++++- lib/rubygems/user_interaction.rb | 34 +++----------------------------- 2 files changed, 7 insertions(+), 32 deletions(-) diff --git a/ChangeLog b/ChangeLog index bc679027b4..9ade4b72ca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,7 @@ -Sat May 8 13:05:37 2010 Nobuyoshi Nakada +Sat May 8 13:11:28 2010 Nobuyoshi Nakada + + * lib/rubygems/user_interaction.rb (Gem::StreamUI#ask_for_password): + use io/console. * ext/io/console: imported. [ruby-dev:40897] diff --git a/lib/rubygems/user_interaction.rb b/lib/rubygems/user_interaction.rb index 1ab948dcb6..5db2dfd21c 100644 --- a/lib/rubygems/user_interaction.rb +++ b/lib/rubygems/user_interaction.rb @@ -224,41 +224,13 @@ class Gem::StreamUI def ask_for_password(question) return nil if not @ins.tty? + require 'io/console' + @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 = @ins.noecho {@ins.gets} password.chomp! if password - system "stty echo" password end