The terminal application has full control over the graphical elements. The gui terminal app will give text applications some control via “escape codes”. For example, vt100/xterm terminals, including Mac OS X Terminal, allow you to change colors using the sequence
m. Try it in the shell:
echo -e "\e[1;37;41mhello"
This should print the word “hello” in a white foreground on red background.
Emacs uses these codes to control the text color. Note: although most terminals use the same sequences for colors, other codes are not always the same, so applications normally go through some library (termcap? curses?) and the
TERM environment variable to look up what's needed and available in the given terminal. Emacs has its own elisp for each terminal type; see the source file term/xterm.el for example, or term/README for more details.
Cursor style is available in some terminals but not all. iTerm2 has its own set of sequences; I don't know if there's a similar list for Mac OS Terminal. They both emulate xterm/vt100 which has a long list here. The “set cursor style” sequences on that page show control over blink/underline/solid, but I don't think Terminal or iTerm2 support those. I've not seen any codes for cursor color; Emacs on my system is unable to set the cursor color in either Terminal or iTerm2. You can fake blinking by hiding the cursor (
l) and then showing it again (
h) at some interval.
Related: an emacs frequently asked question is why you can't bind some keys in the terminal version of emacs, and the answer is that it's up to the terminal to decide which keys are sent to the program, and not all keys are assigned an escape code, so emacs can't see them all.