# Printing a backspace

**URL:** <https://rubytalk.org/t/printing-a-backspace/14318>\
**Category:** ruby-talk\
**Created:** [21 October 2004 03:11 UTC](https://rubytalk.org/t/printing-a-backspace/14318 "2004-10-21T03:11:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RubyTalk](https://avatars.discourse-cdn.com/v4/letter/r/9fc29f/32.png) [@RubyTalk](https://rubytalk.org/u/RubyTalk)\
**Post date:** [21 October 2004 03:11 UTC](https://rubytalk.org/t/printing-a-backspace/14318/1 "2004-10-21T03:11:24Z")

</div>

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

#########code 2  
print "Enter password:\n"  
&nbsp;&nbsp;&nbsp;&nbsp;pass = ''  
&nbsp;&nbsp;&nbsp;&nbsp;while true  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ca = STDIN.getc  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print "\x08\x08\x08"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ca.to\_i ==10 then  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pass \<\< ca  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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

---

<div class="post-metadata">

**Author:** ![Florian\_Gross](https://avatars.discourse-cdn.com/v4/letter/f/e9a140/32.png) [@Florian\_Gross](https://rubytalk.org/u/Florian_Gross)\
**Post date:** [21 October 2004 04:49 UTC](https://rubytalk.org/t/printing-a-backspace/14318/2 "2004-10-21T04:49:23Z")

</div>

ruby talk wrote:

> ######code 1  
> print "monkey cat"  
> print "\x08\x08\x08"  
> ### works remves cat
> 
> #########code 2  
> print "Enter password:\n"  
> &nbsp;&nbsp;&nbsp;&nbsp;pass = ''  
> &nbsp;&nbsp;&nbsp;&nbsp;while true  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ca = STDIN.getc  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print "\x08\x08\x08"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ca.to\_i ==10 then  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pass \<\< ca end  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Nobuyoshi\_Nakada](https://rubytalk.org/u/Nobuyoshi_Nakada)\
**Post date:** [21 October 2004 13:57 UTC](https://rubytalk.org/t/printing-a-backspace/14318/3 "2004-10-21T13:57:46Z")

</div>

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:

&nbsp;&nbsp;[http://nokada.jin.gr.jp/ruby/io-console.tar.bz2](http://nokada.jin.gr.jp/ruby/io-console.tar.bz2)

Usage:

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

> **···**
>
> --  
> Nobu Nakada

---

<div class="post-metadata">

**Author:** ![RubyTalk](https://avatars.discourse-cdn.com/v4/letter/r/9fc29f/32.png) [@RubyTalk](https://rubytalk.org/u/RubyTalk)\
**Post date:** [21 October 2004 13:32 UTC](https://rubytalk.org/t/printing-a-backspace/14318/4 "2004-10-21T13:32:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Florian\_Gross](https://avatars.discourse-cdn.com/v4/letter/f/e9a140/32.png) [@Florian\_Gross](https://rubytalk.org/u/Florian_Gross)\
**Post date:** [21 October 2004 14:54 UTC](https://rubytalk.org/t/printing-a-backspace/14318/5 "2004-10-21T14:54:19Z")

</div>

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
