terminalHasColors() reinitializes curses every time it is called,
which breaks curses applications. For example, bcc was seeing Python
curses crashes in https://github.com/iovisor/bcc/pull/615, and GNU
readline is broken by llvm::SMDiagnostic::print() in my own project:
Instead of reinitializing curses every time we check for colors, only do
it if curses hasn't already been initialized. For that, we can check
cur_term, the global variable which is set up by curses when
newterm() or setupterm() is called.