Printing a backspace

######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 :frowning:

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

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 :frowning:

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

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-console.tar.bz2

Usage:

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

···

--
Nobu Nakada

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 :frowning:
>
> 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

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