MCPcopy Create free account
hub / github.com/numpy/numpy / terminal_has_colors

Function terminal_has_colors

numpy/distutils/misc_util.py:323–348  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

321# Hooks for colored terminal output.
322# See also https://web.archive.org/web/20100314204946/http://www.livinglogic.de/Python/ansistyle
323def terminal_has_colors():
324 if sys.platform=='cygwin' and 'USE_COLOR' not in os.environ:
325 # Avoid importing curses that causes illegal operation
326 # with a message:
327 # PYTHON2 caused an invalid page fault in
328 # module CYGNURSES7.DLL as 015f:18bbfc28
329 # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]
330 # ssh to Win32 machine from debian
331 # curses.version is 2.2
332 # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))
333 return 0
334 if hasattr(sys.stdout, 'isatty') and sys.stdout.isatty():
335 try:
336 import curses
337 curses.setupterm()
338 if (curses.tigetnum("colors") >= 0
339 and curses.tigetnum("pairs") >= 0
340 and ((curses.tigetstr("setf") is not None
341 and curses.tigetstr("setb") is not None)
342 or (curses.tigetstr("setaf") is not None
343 and curses.tigetstr("setab") is not None)
344 or curses.tigetstr("scp") is not None)):
345 return 1
346 except Exception:
347 pass
348 return 0
349
350if terminal_has_colors():
351 _colour_codes = dict(black=0, red=1, green=2, yellow=3,

Callers 1

misc_util.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected