1

In an answer to another question, Chris Page said that Terminal can detect when the terminal parameters are in a state that is likely to be for password entry. For example, the terminal may be in cooked mode with character echo turned off.

How does Terminal detect this? Is there an API where you can subscribe to changes to the terminal parameters? Does Terminal poll? Is a special character sent to the terminal when the terminal parameters change?

3 Answers 3

1

Terminal polls the tty device state using tcgetattr(3) x-man-page://3/tcgetattr and checks that the c_lflag ICANON flag is set and the ECHO flag is not.

It polls after receiving output from the remote program, or when the user enters text using an inline input method that may need to be blocked from displaying user input as “marked” text.

1

Since Terminal.app is closed source, no one can do more than guess exactly what it does (polling or some notification feature that Apple's provided). In any case, it does have complete control over the data moving between the master/slave pseudoterminals, and could poll that using POSIX termios calls such as tcgetattr to see what the current terminal modes are.

0

The Terminal app communicates with the shell (bash) process via a pty (pseudotty) device. When bash or another process goes into "password" mode, it changes the properties of the pty device by sending an ANSI escape sequence

I'm not sure that another process can intercept the communication (have to check my POSIX books).

1
  • 2
    It wouldn't be an escape sequence (none of those can ever change raw/cooked modes). Nov 26, 2017 at 1:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .