Monday, 4 November 2019

macos - How does Terminal.app detect a change to the terminal parameters?


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?



Answer



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.


No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...