6

In the GUI version of Emacs, it is easy to see that something like (blink-cursor-mode t) makes the cursor blink.

However, in a terminal emulator, such as on Mac OS X, it is possible to set things such as the cursor color or whether or not the cursor blinks, in various places (like your ~/.profile or in the Terminal Preferences.

So, my question is, what determines when a "graphical" element, such as text color, is controlled by a terminal emulator (in Terminal in Mac OS you can set the ANSI colors) versus when Emacs controls it (specifically when Emacs is running in a terminal emulator)

Startec
  • 1,354
  • 1
  • 13
  • 30
  • `~/.profile` controls the shell that the terminal emulator is running (like bash). AFAIK it has no control over the appearance of a particular terminal emulator – nitishch Jul 22 '16 at 08:21

1 Answers1

4

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 ESC [ numbers 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 (ESC ? 2 5 l) and then showing it again (ESC ? 2 5 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.

amitp
  • 2,451
  • 12
  • 23