How to display custom key icon on Terminal.app?
When sending a POST request to a server that requires user and password authentication, Terminal.app displays a blinking key icon which I believe is not Unicode.
When asking the user to enter sensible information in my own script, I could check whether TERM_PROGRAM
is an Apple_Terminal
, but I don't know how to display the blinking icon.
Solution 1:
The “key” image isn't a character glyph, it's a custom cursor shape that Terminal draws.
Terminal displays this special cursor shape whenever it looks like the user is being asked to enter a password or similar sensitive data. In addition to displaying this cursor, it restricts the keyboard to Roman input methods in order to avoid having an input method inadvertently display sensitive information as inline text or in another window. This behaves like the standard OS X password text field.
Terminal enters this mode when it sees that the TTY device is configured for canonical (aka “cooked”) mode and character echo is off. In this configuration, user input isn't echoed and only the TTY device input buffer will see the characters until you type Return to send it to the application program. This ensures that neither the TTY device nor the application program are able to echo user input while you're entering the text, so this configuration is usually only used for reading sensitive information.
You can see it in action in Bash, by running
stty -echo && echo Tell me your secrets: && cat; stty echo
stty -echo
turns off TTY character echo, and when Bash runs a command it enables canonical mode, so the following cat
command will run in “password” mode. cat
will echo each line of input until you type Control-D. stty echo
turns it back on after cat
exits.
Note that a shell script can simply use read -s
to read with the TTY in this mode, e.g.,
while read -sp 'Tell me your secrets: '; do echo; echo $REPLY | vis; done