I M-x shell to run a program that tries to produce nice color output. But I get:
?- true. ^[[1mtrue.^[[0m
This is clearly not a fault of EMACS, as it sets the environment variable TERM to dumb. It is just the program I called that ignored this information.
I am aware of ansi-color-for-comint-mode-on which fixes this problem in an ad hoc manner: The environment variable TERM is still dumb. That is, a program interpreting this variable accordingly would not use escapes at all.
Is there a less ad-hoc approach to this, setting the TERM or similar?
You can use
M-x ansi-terminstead of the other shells (M-x shell,M-x termandM-x eshell). Ansi-term was designed to work off-the-shelf with ansi colors. And even better, I suggest that you use multi-term (you can read more about it here and here) which essentially supports all the features of ansi-term plus the ability to easily switch between terminals and define which keyboard shortcuts are sent to the terminal and which ones are captured and interpreted by Emacs.