From: Jakub Travnik Date: 2002-09-29T04:08:40+09:00 Subject: Re: Question about character input 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/ unstable version of Debian GNU/Linux contains JTTui as package libjttui-ruby Jakub Travnik, jabber://jtra@jabber.com