Use stdlib's curses for detection of color capability.

STDOUT.tty? is sadly not enough: there are terminals that are not capable
of color, and yet return true for STDOUT.tty? (as they should). Examples:
emacs, 9term (basically anything that sets $TERM to "dumb").