Most elegant way to detect available colors in terminal to use colorschemes in vim?
Another try: some information is here, if you haven't found it already, including informative link at bottom of the linked page:
So far as I know Vim gets the t_Co number from termcap. So if you can get value from termcap to accurately reflect max colors supported then you're set. I think that's what the info in linked page does, at least for 256 color terms. . .