cpp-terminal
cpp-terminal copied to clipboard
Functions for determining terminal support
I think it would be a great thing to have functions to determine things like color support (4bit / 24bit) and maybe even some more information on what the current terminal supports. That would also make it possible to include fall back functions in window24 for example (we could fall back to 4bit colors, if 24bit is not supported). As Ncurses and such libraries are already implementing that feature I think this won't that of a big deal. I have looked it up quickly, but there are no ANSI code for that, also it would require a system dependent solution (on linux probably even terminal dependent). Windows has some functions inside of windows.h
to do that, linux has the TERM
variable. The problem with the term variable though is that Terminals like xterm and the visual studio integrated terminal set it to xterm-256color
wich means that it supports 256 colors (8bit colors) but doesn't tells if it supports true color (24bit) for example. The actuall problem here is that Kitty (my primary terminal) sets it to "xterm-kitty" which means that if we just check that variable to be equal to "xterm-256color" we wouldn't cover all terminals.
But I think this would be a great thing, if we are done with #73.
I have done some research on this and there are almost no terminals that are not supporting 4 or 8 bit colors. Problem as we already know is the 24bit color support. We could use one or more of the following methods to determine true color support:
-
windows -> Powershell 5 (windows build in), Powershell 7 ("Powershell core", can be installed manually and is cross plattform), CMD, WSL/WSL2 and the microsoft opensource terminal support true color starting with windows 10. I guess that we can simply check the operating system version and disable true color if it's windows 8.1 or below -> old windows shells (cmder, PuTTY, probably others) don't support true color, my thing here is that i'm not sure if they are even used anymore / if they are still developed or already dead projects -> Termus has no true color support and probably wont have it at all because it's propritary - i'm not sure yet what we could do about this one, Kitty doesn't have it either
-
linux -> Most terminal support already true color (Kitty, vscode integrated terminal, xterm, deepin-terminal, gnome-terminal, terminator and many more) and maybe even all have the
$COLORTERM
variable set to "truecolor" or "24bit" so they are easily detectable -> variables won't be passed through ssh, so we probably need something for that case -> there are still some Terminal that don't support 24bit colors (Terminus, gtk2term and some others) but they are not that much and many look abonded -> Maybe some terminal support 24bit colors but don't set the COLORTERM variable -> I'd suggest to only support consoles that are still supported by their authors and would use 8bit colors by default for everything, but turn on 24bit colors if the COLORTERM variable is set. Also we can (and probably have to) add extra checks for specific terminals like using the $TERM variable wich contains the Terminal name -> There is also the terminfo file wich contains informations about specific terminals, but i think that would be far more complicated than just checking $COLORTERM -
macos -> default terminal does not have true color support -> maybe it doesn't set the TRUECOLOR variable, then it would be no issue at all -> Kitty etc have true color support
-
unix / *BSD -> the default bsd terminal has no true color support but might also not set the COLORTERM variable, then same as at macos -> not sure, if BSD has other terminals at all? Might require a research...
-
other systems -> Android will be like linux
I'll do a small demo on this the next days and do a small overview here then. The implementation will happen after #116 was merged. Also it would be great if @certik could check if the macos default terminal sets the COLORTERM variable and if yes what's stored inside and what's included in the $TERM variable. Also are there terminals that are really important besides the default ones?