[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Portable password input

Trans

3/13/2007 2:56:00 PM

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


3 Answers

Ara.T.Howard

3/13/2007 3:00:00 PM

0

James Gray

3/13/2007 3:04:00 PM

0

On Mar 13, 2007, at 10:00 AM, ara.t.howard@noaa.gov wrote:

> On Tue, 13 Mar 2007, Trans wrote:
>
>> 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
>
> gem install highline !!

I agree. :)

James Edward Gray II

greg

3/13/2007 6:17:00 PM

0

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

On Mar 13, 9:00 am, ara.t.how...@noaa.gov wrote:
> On Tue, 13 Mar 2007, Trans wrote:
> > 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
>
> gem install highline !!
>
> ;-)
>
> -a
> --
> be kind whenever possible... it is always possible.
> - the dalai lama