I know that in bash terminals a reliable way to change color is using ANSI escape sequences. For example:
echo -e \"\\033[0;31mbrown text\\033[0;00m\"
Currently true color escape sequences (\e[38;2;R;G;Bm) are supported by certain terminal emulators including gnome-terminal (with vte >= 0.36), konsole, and st [suckless].
The feature is not supported by certain others, e.g. pterm [putty], terminology [enlightenment], urxvt.
xterm is halfway in between: it recognizes the escape sequences, but rounds every color to the nearest one in the 256-color palette.