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?

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).

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.