mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
163f974208
commit
adf6297ec8
2 changed files with 7 additions and 32 deletions
|
@ -1,4 +1,7 @@
|
||||||
Sat May 8 13:05:37 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Sat May 8 13:11:28 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/rubygems/user_interaction.rb (Gem::StreamUI#ask_for_password):
|
||||||
|
use io/console.
|
||||||
|
|
||||||
* ext/io/console: imported. [ruby-dev:40897]
|
* ext/io/console: imported. [ruby-dev:40897]
|
||||||
|
|
||||||
|
|
|
@ -224,41 +224,13 @@ class Gem::StreamUI
|
||||||
def ask_for_password(question)
|
def ask_for_password(question)
|
||||||
return nil if not @ins.tty?
|
return nil if not @ins.tty?
|
||||||
|
|
||||||
|
require 'io/console'
|
||||||
|
|
||||||
@outs.print(question + " ")
|
@outs.print(question + " ")
|
||||||
@outs.flush
|
@outs.flush
|
||||||
|
|
||||||
Gem.win_platform? ? ask_for_password_on_windows : ask_for_password_on_unix
|
password = @ins.noecho {@ins.gets}
|
||||||
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
|
password.chomp! if password
|
||||||
system "stty echo"
|
|
||||||
password
|
password
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue