Open LunarLambda opened 5 years ago
There's actually a $TERM_PROGRAM environment variable designed for just this sort of thing, and it seems to be becoming a sort-of-standard! Apple's built-in Terminal.app sets it to "Apple_Terminal", while iTerm 2 sets it to "iTerm.app". GNOME Terminal sets it to "gnome-terminal". CRT currently leaves it blank. There's even a $TERM_PROGRAM_VERSION too, if you really want to get specific!
Currently as an interim stopgap measure I'm detecting it as $TERM="xterm", since every other terminal I use happens to have 256 color support and sets it to "xterm-256color", but that may not work for you. And of course it might mess you up if you want to log into Linux VT consoles.
One thing you could do is set TERM to vt100. That suppresses color in vim, though, oddly, not for "ls --color=auto".
Wouldn't that mess up keys and escape sequences as well, though?
The standard seems to be for a terminal emulator that supports 256 colors to append -256color to its TERM identification string, like xterm-256color or rxvt-unicode-256color. So, I would recommend identifying as cool-retro-term-256color. However, Cool Retro Term would need its own terminfo entry under /etc/terminfo or /lib/terminfo to describe its capabilities. This would be the correct long-term solution, I think.
As a short-term fix, so that Bash, Vim, Mutt, etc. would realize that Cool Retro Term supports 256 colors, I added the following to my .bashrc file (near the beginning):
# Cool Retro Term doesn't properly identify as a 256 color terminal.
# Force it to identify as xterm-256color instead of just xterm.
[ -z "$COLORSCHEMES_DIR" ] || export TERM='xterm-256color'
This works because Cool Retro Term sets a COLORSCHEMES_DIR environment variable that can be detected. But, this is a pretty clunky workaround.
CRT doesn't just support 256 colors (as identified by xterm-256color). It also supports full-on 24-bit color! (e.g. #rrggbb)
Terminal-wise – keys and such – it's an xterm as far as I know, so we shouldn't need to do anything with $TERM beyond setting it to xterm-256color
. But having a $TERM_PROGRAM set would be nice, so we can have a different theme for bright glowy CRT (as mentioned in the OP).
There's also apparently a $COLORTERM variable, which gnome-terminal sets to truecolor
, and iTerm 2 sets to something (I can't remember exactly what). That would be good for 24-bit color detection.
One way would be to have /usr/share/terminfo/c/cool-retro-term be a link to /usr/share/terminfo/x/xterm, and set TERM to cool-retro-term, or to keep TERM as-is and export a different variable, like COOL_RETRO_TERM, containing a version number or something else.
The reason for this is that there is no easy way for programs (like Vim) to determine what terminal I'm running in beyond checking $TERM. Since CRT is visually quite different from pretty much any other terminal emulator out there, it would be nice to be have a little if statement in my setups to pick different visual styling for it. Since, for example, using solarized light in vim might look fine in a standard xterm, but would probably not work at all in CRT, since it's a very bright colorscheme.