Portable password input

This has been asked about before, and I’ve been wondering about it
myself. So I worked on it and came up with this. I know it’s rather a
poor man’s way of handling it but at least it’s light and portable
(well, at least I think it is).

def password( msg=nil )
msg ||= “Enter Password”
inp = ‘’

i = Thread.new{ inp = $stdin.gets }
c = Thread.new do
  loop do
    sleep 0.01
    $stdout << "\r#{msg}:        "
    $stdout << "\r#{msg}: "
    $stdout.flush
  end
end

i.join

return inp

end

On Tue, 13 Mar 2007, Trans wrote:

c = Thread.new do
return inp
end

gem install highline !!

:wink:

-a

On Mar 13, 2007, at 10:00 AM, [email protected] wrote:

i.join

return inp
end

gem install highline !!

I agree. :slight_smile:

James Edward G. II

gem install highline
require ‘highline/import’
ask('password: ') {|q| q.echo = ‘*’ }