# Question about character input

**URL:** <https://rubytalk.org/t/question-about-character-input/2030>\
**Category:** ruby-talk\
**Created:** [27 September 2002 18:23 UTC](https://rubytalk.org/t/question-about-character-input/2030 "2002-09-27T18:23:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Cowan](https://avatars.discourse-cdn.com/v4/letter/a/cc9497/32.png) [@Andrew\_Cowan](https://rubytalk.org/u/Andrew_Cowan)\
**Post date:** [27 September 2002 18:23 UTC](https://rubytalk.org/t/question-about-character-input/2030/1 "2002-09-27T18:23:36Z")

</div>

I am working on an text-based application (no GUI involved) and am  
wondering if there is a way to get character input back from the user but  
replacing each displayed character as it is typed with a ‘\*’ - e.g. to hide  
a password being typed in.

I figured I could just do a getc, then putc the meta sequence for the  
Delete character but it isn’t working at all…

Any ideas? I’d love some help and would greatly appreciate a quick example  
that shows that this is possible.

Thanks in advance!  
Andy

> **···**
>
> * * *
> 
> Posted Via [Uncensored-News.Com](http://Uncensored-News.Com) - Still Only $9.95 - [http://www.uncensored-news.com](http://www.uncensored-news.com)  
> \<\>\<\>\<\>\<\>\<\>\<\>\<\> The Worlds Uncensored News Source \<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>

---

<div class="post-metadata">

**Author:** ![Jakub\_Travnik](https://avatars.discourse-cdn.com/v4/letter/j/b5ac83/32.png) [@Jakub\_Travnik](https://rubytalk.org/u/Jakub_Travnik)\
**Post date:** [28 September 2002 19:08 UTC](https://rubytalk.org/t/question-about-character-input/2030/2 "2002-09-28T19:08:40Z")

</div>

Andrew Cowan wrote:

> I am working on an text-based application (no GUI involved) and am  
> wondering if there is a way to get character input back from the user but  
> replacing each displayed character as it is typed with a ‘\*’ - e.g. to hide  
> a password being typed in.
> 
> I figured I could just do a getc, then putc the meta sequence for the  
> Delete character but it isn’t working at all..
> 
> Any ideas? I’d love some help and would greatly appreciate a quick example  
> that shows that this is possible.

Hello,

on linux (and other unices) you will need to know terminal escape codes  
or use some high level library such as  
termcap or terminfo (it will tell you escape codes for particular terminal)  
curses or ncurses (it will allow very simple windowing in terminal)  
jttui (high level ruby bindings to ncurses library)

jttui password dialog example (just a quick hack):

> **···**
>
> * * *
> 
> require ‘jttui/jttui’  
> require ‘jttui/jttuistd’
> 
> ## JTTui.run do |root| d=JTTDialog.new(root, ‘Dialog Window’, 0, 0, 30, 10, ‘Example 8 - password dialog’) d.align=JTTWindow::ALIGN\_CENTER l=JTTWLabel.new(d, ‘Label 1’, 0, 0, 40, 1, ‘Enter password:’) p=JTTWEditpass.new(d, ‘PWEdit 1’, 2, 2, 20, 1,‘’, true) b=JTTWButton.new(d, ‘Quit button’, 2, 4, 6, 1, ‘\_Quit’) { JTTWMessagebox.new(“You have typed ‘#{p.editor.text}’”, 0, 0, ‘Ok’).execute JTTui.addmessage nil, :close } [p,b].each{|x| d.addtabstop x} d.defaultbutton=b end
> 
> JTTui screenshots and download at  
> [http://klokan.sh.cvut.cz/~jtra/](http://klokan.sh.cvut.cz/~jtra/)
> 
> unstable version of Debian GNU/Linux contains JTTui as package  
> libjttui-ruby
> 
> Jakub Travnik,  
> jabber://jtra@jabber.com

---

<div class="post-metadata">

**Author:** ![Andrew\_Cowan](https://avatars.discourse-cdn.com/v4/letter/a/cc9497/32.png) [@Andrew\_Cowan](https://rubytalk.org/u/Andrew_Cowan)\
**Post date:** [29 September 2002 21:58 UTC](https://rubytalk.org/t/question-about-character-input/2030/3 "2002-09-29T21:58:04Z")

</div>

Jakub, I have always considered curses to be a console-oriented windowing  
system, can this be used through a socket connection, to create a window  
remotely on a terminal connected via telnet to the ruby application (server) ?

Thanks!  
Andy

> **···**
>
> On Saturday 28 September 2002 15:08, you wrote:
> 
> > Andrew Cowan wrote:
> > 
> > > I am working on an text-based application (no GUI involved) and am  
> > > wondering if there is a way to get character input back from the user but  
> > > replacing each displayed character as it is typed with a ‘\*’ - e.g. to  
> > > hide a password being typed in.
> > > 
> > > I figured I could just do a getc, then putc the meta sequence for the  
> > > Delete character but it isn’t working at all…
> > > 
> > > Any ideas? I’d love some help and would greatly appreciate a quick  
> > > example that shows that this is possible.
> > 
> > Hello,
> > 
> > on linux (and other unices) you will need to know terminal escape codes  
> > or use some high level library such as  
> > termcap or terminfo (it will tell you escape codes for particular  
> > terminal) curses or ncurses (it will allow very simple windowing in  
> > terminal) jttui (high level ruby bindings to ncurses library)
> > 
> > ## jttui password dialog example (just a quick hack):
> > 
> > require ‘jttui/jttui’  
> > require ‘jttui/jttuistd’
> > 
> > ## JTTui.run do |root| d=JTTDialog.new(root, ‘Dialog Window’, 0, 0, 30, 10, ‘Example 8 - password dialog’) d.align=JTTWindow::ALIGN\_CENTER l=JTTWLabel.new(d, ‘Label 1’, 0, 0, 40, 1, ‘Enter password:’) p=JTTWEditpass.new(d, ‘PWEdit 1’, 2, 2, 20, 1,‘’, true) b=JTTWButton.new(d, ‘Quit button’, 2, 4, 6, 1, ‘\_Quit’) { JTTWMessagebox.new(“You have typed ‘#{p.editor.text}’”, 0, 0, ‘Ok’).execute JTTui.addmessage nil, :close } [p,b].each{|x| d.addtabstop x} d.defaultbutton=b end
> > 
> > JTTui screenshots and download at  
> > [http://klokan.sh.cvut.cz/~jtra/](http://klokan.sh.cvut.cz/~jtra/)
> > 
> > unstable version of Debian GNU/Linux contains JTTui as package  
> > libjttui-ruby
> > 
> > Jakub Travnik,  
> > jabber://jtra@jabber.com
