本文整理匯總了Python中curses.tigetnum方法的典型用法代碼示例。如果您正苦於以下問題:Python curses.tigetnum方法的具體用法?Python curses.tigetnum怎麽用?Python curses.tigetnum使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類curses
的用法示例。
在下文中一共展示了curses.tigetnum方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: supported
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import tigetnum [as 別名]
def supported(cls, stream=sys.stdout):
"""
A class method that returns True if the current platform supports
coloring terminal output using this method. Returns False otherwise.
"""
if not stream.isatty():
return False # auto color only on TTYs
try:
import curses
except ImportError:
return False
else:
try:
try:
return curses.tigetnum("colors") > 2
except curses.error:
curses.setupterm()
return curses.tigetnum("colors") > 2
except:
raise
# guess false in case of error
return False
示例2: supported
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import tigetnum [as 別名]
def supported(cls, stream=sys.stdout):
"""
A class method that returns True if the current platform supports
coloring terminal output using this method. Returns False otherwise.
"""
if not stream.isatty():
return False # auto color only on TTYs
try:
import curses
except ImportError:
return False
else:
try:
try:
return curses.tigetnum("colors") > 2
except curses.error:
curses.setupterm()
return curses.tigetnum("colors") > 2
except Exception:
# guess false in case of error
return False
示例3: _stderr_supports_color
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import tigetnum [as 別名]
def _stderr_supports_color() -> bool:
try:
if hasattr(sys.stderr, "isatty") and sys.stderr.isatty():
if curses:
curses.setupterm()
if curses.tigetnum("colors") > 0:
return True
elif colorama:
if sys.stderr is getattr(
colorama.initialise, "wrapped_stderr", object()
):
return True
except Exception:
# Very broad exception handling because it's always better to
# fall back to non-colored logs than to break at startup.
pass
return False
示例4: supported
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import tigetnum [as 別名]
def supported(cls, stream=sys.stdout):
"""Check the current platform supports coloring terminal output
A class method that returns True if the current platform supports
coloring terminal output using this method. Returns False otherwise.
"""
if not stream.isatty():
return False # auto color only on TTYs
try:
import curses
except ImportError:
return False
else:
try:
try:
return curses.tigetnum("colors") > 2
except curses.error:
curses.setupterm()
return curses.tigetnum("colors") > 2
except Exception:
# guess false in case of error
return False
示例5: supported
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import tigetnum [as 別名]
def supported(cls, stream=sys.stdout):
"""
A class method that returns True if the current platform supports
coloring terminal output using this method. Returns False otherwise.
"""
if not stream.isatty():
return False # auto color only on TTYs
try:
import curses
except ImportError:
return False
else:
try:
try:
return curses.tigetnum("colors") > 2
except curses.error:
curses.setupterm()
return curses.tigetnum("colors") > 2
except:
# guess false in case of error
return False
示例6: number_of_colors
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import tigetnum [as 別名]
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)
示例7: __has_colors
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import tigetnum [as 別名]
def __has_colors(stream):
"""
Is tty output check
:param object stream: input stream
:return: bool
"""
if not hasattr(stream, "isatty"):
return False
# noinspection PyUnresolvedReferences
if not stream.isatty():
return False # auto color only on TTYs
# noinspection PyBroadException
try:
import curses
curses.setupterm()
return curses.tigetnum("colors") > 2
except Exception:
# guess false in case of error
return False
示例8: supported
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import tigetnum [as 別名]
def supported(stream=sys.stdout):
"""
A method that returns True if the current platform supports
coloring terminal output using this method. Returns False otherwise.
"""
if not stream.isatty():
return False # auto color only on TTYs
try:
import curses
except ImportError:
return False
else:
try:
try:
return curses.tigetnum("colors") > 2
except curses.error:
curses.setupterm()
return curses.tigetnum("colors") > 2
except Exception:
# guess false in case of error
return False
示例9: DrawLine
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import tigetnum [as 別名]
def DrawLine(LineChr,LineColor,LineCount):
"""
Function : Drawing of Line with various character type, color and count
Usage of DrawLine:
LineChr - Character to use as line
LineColor - Color of the line
LineCount - Number of character to print. "" is print from one end to another
Examples : Lookup DemoDrawLine for examples
"""
printd(fcolor.CDebugB + "DrawLine Function\n" + fcolor.CDebug + " LineChr - " + str(LineChr) + "\n " + "LineColor = " + str(LineColor) + "\n " + "LineCount = " + str(LineCount))
if LineColor=="":
LineColor=fcolor.SBlack
if LineChr=="":
LineChr="_"
if LineCount=="":
curses.setupterm()
TWidth=curses.tigetnum('cols')
TWidth=TWidth-1
else:
TWidth=LineCount
print LineColor + LineChr * TWidth
示例10: enable_pretty_logging
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import tigetnum [as 別名]
def enable_pretty_logging():
"""Turns on formatted logging output as configured."""
if (options.log_to_stderr or
(options.log_to_stderr is None and not options.log_file_prefix)):
# Set up color if we are in a tty and curses is installed
color = False
if curses and sys.stderr.isatty():
try:
curses.setupterm()
if curses.tigetnum("colors") > 0:
color = True
except:
pass
channel = logging.StreamHandler()
channel.setFormatter(_LogFormatter(color=color))
logging.getLogger().addHandler(channel)
if options.log_file_prefix:
channel = logging.handlers.RotatingFileHandler(
filename=options.log_file_prefix,
maxBytes=options.log_file_max_size,
backupCount=options.log_file_num_backups)
channel.setFormatter(_LogFormatter(color=False))
logging.getLogger().addHandler(channel)
示例11: supported
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import tigetnum [as 別名]
def supported(stream=sys.stdout):
"""Method that checks if the current terminal supports coloring.
Returns True or False.
"""
if not stream.isatty():
return False # auto color only on TTYs
try:
import curses
except ImportError:
return False
else:
try:
try:
return curses.tigetnum("colors") > 2
except curses.error:
curses.setupterm()
return curses.tigetnum("colors") > 2
except Exception:
# guess false in case of error
return False
示例12: supported
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import tigetnum [as 別名]
def supported(cls, stream=sys.stdout):
"""
A class method that returns True if the current platform supports
coloring terminal output using this method. Returns False otherwise.
"""
if not stream.isatty():
return False # auto color only on TTYs
try:
import curses
except ImportError:
return False
else:
try:
try:
return curses.tigetnum("colors") > 2
except curses.error:
curses.setupterm()
return curses.tigetnum("colors") > 2
except:
# guess false in case of error
return False
示例13: _height_and_width
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import tigetnum [as 別名]
def _height_and_width(self):
"""Return a tuple of (terminal height, terminal width).
Start by trying TIOCGWINSZ (Terminal I/O-Control: Get Window Size),
falling back to environment variables (LINES, COLUMNS), and returning
(None, None) if those are unavailable or invalid.
"""
# tigetnum('lines') and tigetnum('cols') update only if we call
# setupterm() again.
for descriptor in self._init_descriptor, sys.__stdout__:
try:
return struct.unpack(
'hhhh', ioctl(descriptor, TIOCGWINSZ, '\000' * 8))[0:2]
except IOError:
# when the output stream or init descriptor is not a tty, such
# as when when stdout is piped to another program, fe. tee(1),
# these ioctls will raise IOError
pass
try:
return int(environ.get('LINES')), int(environ.get('COLUMNS'))
except TypeError:
return None, None
示例14: number_of_colors
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import tigetnum [as 別名]
def number_of_colors(self):
"""Return the number of colors the terminal supports.
Common values are 0, 8, 16, 88, and 256.
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:
...
We also return 0 if the terminal won't tell us how many colors it
supports, which I think is rare.
"""
# 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.
colors = tigetnum('colors') # Returns -1 if no color support, -2 if no
# such cap.
# self.__dict__['colors'] = ret # Cache it. It's not changing.
# (Doesn't work.)
return colors if colors >= 0 else 0
示例15: _syntax_highlighting
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import tigetnum [as 別名]
def _syntax_highlighting(self, data):
try:
from pygments import highlight
from pygments.lexers import GasLexer
from pygments.formatters import TerminalFormatter, Terminal256Formatter
from pygments.styles import get_style_by_name
style = get_style_by_name('colorful')
import curses
curses.setupterm()
if curses.tigetnum('colors') >= 256:
FORMATTER = Terminal256Formatter(style=style)
else:
FORMATTER = TerminalFormatter()
# When pygments is available, we
# can print the disassembled
# instructions with syntax
# highlighting.
data = highlight(data, GasLexer(), FORMATTER)
except ImportError:
pass
finally:
data = data.encode()
return data