def number_of_colors(self):
"""
Read-only property: number of colors supported by terminal.
Common values are 0, 8, 16, 88, and 256.
Most commonly, this may be used to test whether the terminal supports
colors. Though the underlying capability returns -1 when there is no
color support, we return 0. This lets you test more Pythonically::
if term.number_of_colors:
...
"""
# This is actually the only remotely useful numeric capability. We
# don't name it after the underlying capability, because we deviate
# slightly from its behavior, and we might someday wish to give direct
# access to it.
# trim value to 0, as tigetnum('colors') returns -1 if no support,
# and -2 if no such capability.
return max(0, self.does_styling and curses.tigetnum('colors') or -1)
评论列表
文章目录