code: def stream_has_colours(stream):
      
      if not hasattr(stream, "isatty"):
          return False
  
      if not stream.isatty():
          return False  # auto color only on TTYs
      try:
          import curses
          curses.setupterm()
          return curses.tigetnum("colors") > 2
      except:
          return False
docs: True if stream supports colours. Python cookbook, #475186