[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Printing a backspace

RubyTalk@gmail.com

10/21/2004 3:11:00 AM

######code 1
print "monkey cat"
print "\x08\x08\x08"
### works remves cat

#########code 2
print "Enter password:\n"
pass = ''
while true
ca = STDIN.getc
print "\x08\x08\x08"
if ca.to_i ==10 then
break
end
pass << ca
end
pass.strip!
###### does not work :(

Any Help would be good. I also tried \b . I am running windows i am
using a bat file but i also tried rde it just prints the squares


4 Answers

Florian Gross

10/21/2004 4:46:00 AM

0

ruby talk wrote:

> ######code 1
> print "monkey cat"
> print "\x08\x08\x08"
> ### works remves cat
>
> #########code 2
> print "Enter password:\n"
> pass = ''
> while true
> ca = STDIN.getc
> print "\x08\x08\x08"
> if ca.to_i ==10 then
> break
> end
> pass << ca
> end
> pass.strip!
> ###### does not work :(
>
> Any Help would be good. I also tried \b . I am running windows i am
> using a bat file but i also tried rde it just prints the squares

The problem is that .getc will read a whole line at the time then buffer
the characters and when all are used up it will read a whole line again etc.

So I guess the best you can do without using a terminal library is
calling `cls` immediately after you read in the password.

Regards,
Florian Gross

RubyTalk@gmail.com

10/21/2004 1:32:00 PM

0

Is there any documentation on cls? Or exmaples?
Becker


On Thu, 21 Oct 2004 13:49:23 +0900, Florian Gross <flgr@ccan.de> wrote:
> ruby talk wrote:
>
>
>
> > ######code 1
> > print "monkey cat"
> > print "\x08\x08\x08"
> > ### works remves cat
> >
> > #########code 2
> > print "Enter password:\n"
> > pass = ''
> > while true
> > ca = STDIN.getc
> > print "\x08\x08\x08"
> > if ca.to_i ==10 then
> > break
> > end
> > pass << ca
> > end
> > pass.strip!
> > ###### does not work :(
> >
> > Any Help would be good. I also tried \b . I am running windows i am
> > using a bat file but i also tried rde it just prints the squares
>
> The problem is that .getc will read a whole line at the time then buffer
> the characters and when all are used up it will read a whole line again etc.
>
> So I guess the best you can do without using a terminal library is
> calling `cls` immediately after you read in the password.
>
> Regards,
> Florian Gross
>
>


nobu.nokada

10/21/2004 1:58:00 PM

0

Hi,

At Thu, 21 Oct 2004 12:11:24 +0900,
ruby talk wrote in [ruby-talk:117254]:
> Any Help would be good. I also tried \b . I am running windows i am
> using a bat file but i also tried rde it just prints the squares

If you want to hide the input by user, this may help you:

http://nokada.jin.gr.jp/ruby/io-conso...

Usage:

require 'io/console'
p STDIN.noecho {STDIN.gets}

--
Nobu Nakada


Florian Gross

10/21/2004 2:50:00 PM

0

ruby talk wrote:

> Is there any documentation on cls? Or exmaples?
> Becker

It is just a windows specific command that clears the complete console.
See "help cls".

Regards,
Florian Gross