Hiding user input


#1

Before you all read on, there is a restriction…

Without Highline!!!
Sorry, James, I love the library, but I need this to work over IO.

How can I hide user input (as they type) without highline? Am I able
to use blocks after gets()?
I’m hoping I can do something like this:

name = gets.chomp {|let| let.echo = false}

or something. I don’t care how odd or crazy a solution, method, or
whatever is. I’m looking for guidance in an almost pitch-black room
of metaphors and elongation of said metaphors.

Thanks,
aRi
--------------------------------------------|
If you’re not living on the edge,
then you’re just wasting space.


#2

Ari B. wrote:

Ari,

If it’s on linux/unix, maybe mac as well,
system(‘stty -echo’)

Just make sure you later call
system(‘stty echo’), because it would be extremely rude not to. I would
also surround the whole program in a begin / ensure / end block so that
you can ensure “stty echo” gets called at the end.

Dan


#3

Hi,

At Tue, 31 Jul 2007 12:24:00 +0900,
Ari B. wrote in [ruby-talk:262575]:

Without Highline!!!
Sorry, James, I love the library, but I need this to work over IO.

Highline doesn’t work over IO?

How can I hide user input (as they type) without highline? Am I able
to use blocks after gets()?
I’m hoping I can do something like this:

name = gets.chomp {|let| let.echo = false}

require ‘io/console’
name = STDIN.noecho {|i| i.gets}.chomp

io/console http://www.rubyist.net/~nobu/ruby/io-console.tar.bz2
would work on the platforms support termios, termio or sgtty, and
Win32.


#4

On Jul 30, 2007, at 11:51 PM, Nobuyoshi N. wrote:

Hi,

At Tue, 31 Jul 2007 12:24:00 +0900,
Ari B. wrote in [ruby-talk:262575]:

Without Highline!!!
Sorry, James, I love the library, but I need this to work over IO.

Highline doesn’t work over IO?

I’ve not tested it over sockets, but I would like it to work there.
If there are problems, I would prefer we patch them.

James Edward G. II


#5

On Jul 31, 2007, at 12:51 AM, Nobuyoshi N. wrote:

require ‘io/console’
name = STDIN.noecho {|i| i.gets}.chomp

io/console http://www.rubyist.net/~nobu/ruby/io-console.tar.bz2
would work on the platforms support termios, termio or sgtty, and
Win32.

Will this work over sockets, though? The idea is that I don’t have
access to the user’s terminal.

Thanks,
aRi
-------------------------------------------|
Nietzsche is my copilot


#6

Hi,

At Tue, 31 Jul 2007 22:19:44 +0900,
James Edward G. II wrote in [ruby-talk:262624]:

Without Highline!!!
Sorry, James, I love the library, but I need this to work over IO.

Highline doesn’t work over IO?

I’ve not tested it over sockets, but I would like it to work there.
If there are problems, I would prefer we patch them.

Does noecho over sockets have any meanings?


#7

On Jul 31, 2007, at 12:00 PM, Nobuyoshi N. wrote:

If there are problems, I would prefer we patch them.

Does noecho over sockets have any meanings?

Exactly.

If you are talking to something like a Telnet client you would need
to use that protocol to query the client about its capabilities and
request that it change its input mode.

James Edward G. II


#8

On Jul 31, 2007, at 1:19 PM, James Edward G. II wrote:

If you are talking to something like a Telnet client you would need
to use that protocol to query the client about its capabilities and
request that it change its input mode.

Is there a nice easy way to do that in Ruby? Because this seems to be
EXACTLY what I need.

Thanks,
---------------------------------------------------------------|
~Ari
“I don’t suffer from insanity. I enjoy every minute of it” --1337est
man alive


#9

On Jul 31, 2007, at 12:36 PM, Ari B. wrote:

On Jul 31, 2007, at 1:19 PM, James Edward G. II wrote:

If you are talking to something like a Telnet client you would
need to use that protocol to query the client about its
capabilities and request that it change its input mode.

Is there a nice easy way to do that in Ruby? Because this seems to
be EXACTLY what I need.

A very quick search didn’t turn up a library that would handle this
for you, sadly. You may need to learn enough of the protocol to send
the needed commands manually.

James Edward G. II


#10

Hi,

At Wed, 1 Aug 2007 02:19:20 +0900,
James Edward G. II wrote in [ruby-talk:262677]:

Does noecho over sockets have any meanings?

Exactly.

If you are talking to something like a Telnet client you would need
to use that protocol to query the client about its capabilities and
request that it change its input mode.

In such case, pty would be used in common? I’m not sure if
sockets have such capabilities at all.