Going beyond the normal terminal colours means using a different display library than the standard and easily portable curses.
I am not sure if you mean to include ncurses or not, but ncurses supports, dependent on terminal capabilities, both more than sixteen colors as well as redefining colors by specifying arbitrary RGB values. That is in addition to the other attributes many terminals support such as standout, dim, bold, reverse, underline, etc.
Of course, if one chose the ncurses library to provide portability, then to make the display both aesthetic and functional on the widest variety of terminals one would need to pride some sort of fall-back strategy.
I redefine my colors to be a little better suited to my world, but I try to keep them roughly in-line with the standard eight terminal colors and their brighter variants so in the case that I cannot redefine colors on some terminal I do not get a really bizarre looking map. To nicely support more than sixteen colors I just use a bitmask on the palette index to strip it down to the correct size for that terminal. Since I know that color 23 will fall back to 7 in sixteen color mode as well as eight color mode I make sure that color 23 is similar (or at least will make sense) as color 7. I only redefine the standard eight and brights to make them "nicer" but if the terminal doesn't support that it's no problem.
By the by, I'm a RL developer who has recently come out of the closet. I've been harboring ideas and code snippets for years, nay decades, and just recently decided to do something about it. Hence, this is my first post ever to the RL community on any fora or newsgroup despite having read r.g.r.d for too many years to count.