Method: Password.echo

Defined in:
lib/password.rb

.echo(on = true, masked = false) ⇒ Object

Turn local terminal echo on or off. This method is used for securing the display, so that a soon to be entered password will not be echoed to the screen. It is also used for restoring the display afterwards.

If masked is true, the keyboard is put into unbuffered mode, allowing the retrieval of characters one at a time. masked has no effect when on is false. You are unlikely to need this method in the course of normal operations.



166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/password.rb', line 166

def Password.echo(on=true, masked=false)
  term = Termios::getattr( $stdin )

  if on
    term.c_lflag |= ( Termios::ECHO | Termios::ICANON )
  else # off
    term.c_lflag &= ~Termios::ECHO
    term.c_lflag &= ~Termios::ICANON if masked
  end

  Termios::setattr( $stdin, Termios::TCSANOW, term )
end