I am curious that how a program determines its terminal supports colour as I am trying to create some terminal apps like this, however it doesn't seem to be outputting colours (just plain gray text) and upon inspecting the environment of the java
it runs, I found
HOME=/home/user
LANG=en_US.UTF-8
LOGNAME=root
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42
MAIL=/var/mail/root
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
SHELL=/bin/bash
SUDO_COMMAND=/usr/local/bin/minecraftd -d
SUDO_GID=1000
SUDO_UID=1000
SUDO_USER=user
TERM=xterm-256color
USER=root
USERNAME=root
Which has a $TERM
supporting colours.
And upon inspecting the environment of another process which outputs colours properly (FYI it's bash), I found
GCC_COLORS=error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01
HOME=/home/user
LANG=en_US.UTF-8
LESSCLOSE=/usr/bin/lesspipe %s %s
LESSOPEN=| /usr/bin/lesspipe %s
LOGNAME=user
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42
MAIL=/var/mail/user
MYSQL_PS1=\u@\h [\c/\d]>
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
PWD=/home/user
SHELL=/bin/bash
SHLVL=1
SSH_CLIENT=[irrelevant]
SSH_CONNECTION=[irrelevant]
SSH_TTY=/dev/pts/4
TERM=screen
TMUX=/tmp/tmux-1000/default,28912,0
TMUX_PANE=%3
USER=user
XDG_RUNTIME_DIR=/run/user/1000
XDG_SESSION_ID=c57
_=/usr/bin/tmux
Which also has a $TERM
supporting colours.
My question is, how a program determine if colours is supported because I have troubles figuring it out.