本文整理汇总了Python中curses.tigetstr方法的典型用法代码示例。如果您正苦于以下问题:Python curses.tigetstr方法的具体用法?Python curses.tigetstr怎么用?Python curses.tigetstr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类curses
的用法示例。
在下文中一共展示了curses.tigetstr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setterm
# 需要导入模块: import curses [as 别名]
# 或者: from curses import tigetstr [as 别名]
def setterm(self, term):
# Dummy file for the purpose of tests.
with open('/dev/null', 'w') as f:
curses.setupterm(
term, f.fileno()) # This will raise if the termtype is not supported
self.TERM = term
self.ESCSEQ = {}
for k in self.KEYS.keys():
str_ = curses.tigetstr(curses.has_key._capability_names[k])
if str_:
self.ESCSEQ[str_] = k
self.CODES['DEOL'] = curses.tigetstr('el')
self.CODES['DEL'] = curses.tigetstr('dch1')
self.CODES['INS'] = curses.tigetstr('ich1')
self.CODES['CSRLEFT'] = curses.tigetstr('cub1')
self.CODES['CSRRIGHT'] = curses.tigetstr('cuf1')
示例2: resolve_capability
# 需要导入模块: import curses [as 别名]
# 或者: from curses import tigetstr [as 别名]
def resolve_capability(term, attr):
"""
Resolve a raw terminal capability using :func:`tigetstr`.
:arg Terminal term: :class:`~.Terminal` instance.
:arg str attr: terminal capability name.
:returns: string of the given terminal capability named by ``attr``,
which may be empty (u'') if not found or not supported by the
given :attr:`~.Terminal.kind`.
:rtype: str
"""
# Decode sequences as latin1, as they are always 8-bit bytes, so when
# b'\xff' is returned, this must be decoded to u'\xff'.
if not term.does_styling:
return u''
val = curses.tigetstr(term._sugar.get(attr, attr))
return u'' if val is None else val.decode('latin1')
示例3: __missing__
# 需要导入模块: import curses [as 别名]
# 或者: from curses import tigetstr [as 别名]
def __missing__(self, key):
# pylint: disable=unused-argument,no-self-use
if not self.has_colors:
return ''
try:
value = curses.tigetstr(self.attrs[key])
except KeyError:
try:
value = curses.tparm(
curses.tigetstr('setaf'), self.colors.index(key))
except ValueError:
return ''
value = value.decode()
self[key] = value
return value
示例4: setterm
# 需要导入模块: import curses [as 别名]
# 或者: from curses import tigetstr [as 别名]
def setterm(self, term):
"Set the curses structures for this terminal"
log.debug("Setting termtype to %s" % (term, ))
curses.setupterm(term) # This will raise if the termtype is not supported
self.TERM = term
self.ESCSEQ = {}
for k in self.KEYS.keys():
str = curses.tigetstr(curses.has_key._capability_names[k])
if str:
self.ESCSEQ[str] = k
# Create a copy to prevent altering the class
self.CODES = self.CODES.copy()
self.CODES['DEOL'] = curses.tigetstr('el')
self.CODES['DEL'] = curses.tigetstr('dch1')
self.CODES['INS'] = curses.tigetstr('ich1')
self.CODES['CSRLEFT'] = curses.tigetstr('cub1')
self.CODES['CSRRIGHT'] = curses.tigetstr('cuf1')
示例5: __init__
# 需要导入模块: import curses [as 别名]
# 或者: from curses import tigetstr [as 别名]
def __init__(self):
self.data = []
self.has_ipython = True
self.display_type = "multi"
self.global_data_size = 0
self.global_val_data_size = 0
self.snapped = False
global CURSES_SUPPORTED
if CURSES_SUPPORTED:
try:
curses.setupterm()
sys.stdout.write(curses.tigetstr('civis').decode())
except Exception:
CURSES_SUPPORTED = False
try:
clear_output
except NameError:
self.has_ipython = False
示例6: __init__
# 需要导入模块: import curses [as 别名]
# 或者: from curses import tigetstr [as 别名]
def __init__(self, use_colors):
logging.Handler.__init__(self)
self.use_colors = use_colors
# Initialize environment
curses.setupterm()
# Get the foreground color attribute for this environment
self.fcap = curses.tigetstr('setaf')
#Get the normal attribute
self.COLOR_NORMAL = curses.tigetstr('sgr0')
# Get + Save the color sequences
self.COLOR_INFO = curses.tparm(self.fcap, curses.COLOR_GREEN)
self.COLOR_ERROR = curses.tparm(self.fcap, curses.COLOR_RED)
self.COLOR_WARNING = curses.tparm(self.fcap, curses.COLOR_YELLOW)
self.COLOR_DEBUG = curses.tparm(self.fcap, curses.COLOR_BLUE)
示例7: __init__
# 需要导入模块: import curses [as 别名]
# 或者: from curses import tigetstr [as 别名]
def __init__(self, stream, charset=None):
# our Enterprise logic follows
self.stream_isatty = stream.isatty()
if charset is None:
charset = ENTERPRISE_CHARSET if self.stream_isatty else '.'
super(QubesSpinnerEnterpriseEdition, self).__init__(stream, charset)
if self.stream_isatty:
try:
curses.setupterm()
self.has_terminfo = True
self.cub1 = curses.tigetstr('cub1').decode()
except (curses.error, io.UnsupportedOperation):
# we are in very non-Enterprise environment
self.has_terminfo = False
else:
self.cub1 = ''
示例8: __init__
# 需要导入模块: import curses [as 别名]
# 或者: from curses import tigetstr [as 别名]
def __init__(self, color=True, fmt=DEFAULT_FORMAT,
datefmt=DEFAULT_DATE_FORMAT, colors=DEFAULT_COLORS):
r"""
:arg bool color: Enables color support.
:arg string fmt: Log message format.
It will be applied to the attributes dict of log records. The
text between ``%(color)s`` and ``%(end_color)s`` will be colored
depending on the level if color support is on.
:arg dict colors: color mappings from logging level to terminal color
code
:arg string datefmt: Datetime format.
Used for formatting ``(asctime)`` placeholder in ``prefix_fmt``.
.. versionchanged:: 3.2
Added ``fmt`` and ``datefmt`` arguments.
"""
logging.Formatter.__init__(self, datefmt=datefmt)
self._fmt = fmt
self._colors = {}
if color and _stderr_supports_color():
# The curses module has some str/bytes confusion in
# python3. Until version 3.2.3, most methods return
# bytes, but only accept strings. In addition, we want to
# output these strings with the logging module, which
# works with unicode strings. The explicit calls to
# unicode() below are harmless in python2 but will do the
# right conversion in python 3.
fg_color = (curses.tigetstr("setaf") or
curses.tigetstr("setf") or "")
if (3, 0) < sys.version_info < (3, 2, 3):
fg_color = unicode_type(fg_color, "ascii")
for levelno, code in colors.items():
self._colors[levelno] = unicode_type(curses.tparm(fg_color, code), "ascii")
self._normal = unicode_type(curses.tigetstr("sgr0"), "ascii")
else:
self._normal = ''
示例9: terminal_has_colors
# 需要导入模块: import curses [as 别名]
# 或者: from curses import tigetstr [as 别名]
def terminal_has_colors():
if sys.platform=='cygwin' and 'USE_COLOR' not in os.environ:
# Avoid importing curses that causes illegal operation
# with a message:
# PYTHON2 caused an invalid page fault in
# module CYGNURSES7.DLL as 015f:18bbfc28
# Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]
# ssh to Win32 machine from debian
# curses.version is 2.2
# CYGWIN_98-4.10, release 1.5.7(0.109/3/2))
return 0
if hasattr(sys.stdout, 'isatty') and sys.stdout.isatty():
try:
import curses
curses.setupterm()
if (curses.tigetnum("colors") >= 0
and curses.tigetnum("pairs") >= 0
and ((curses.tigetstr("setf") is not None
and curses.tigetstr("setb") is not None)
or (curses.tigetstr("setaf") is not None
and curses.tigetstr("setab") is not None)
or curses.tigetstr("scp") is not None)):
return 1
except Exception:
pass
return 0
示例10: tparm
# 需要导入模块: import curses [as 别名]
# 或者: from curses import tigetstr [as 别名]
def tparm(self, capabilities, *args):
"""A simplified version of tigetstr without terminal delays."""
for capability in capabilities:
term_string = curses.tigetstr(capability)
if term_string is not None:
term_string = re.sub(b"\$\<[^>]+>", "", term_string)
break
try:
return curses.tparm(term_string, *args)
except Exception as e:
self.logging.debug("Unable to set tparm: %s" % e)
return b""
示例11: setUp
# 需要导入模块: import curses [as 别名]
# 或者: from curses import tigetstr [as 别名]
def setUp(self):
# Skip for non-Windows if the terminal definition is incomplete.
# This typically means we're running inside a non-standard terminal.
# For example, this happens when embedded in PyCharm.
if sys.platform != "win32":
if not (("FORCE_TTY" in os.environ and os.environ["FORCE_TTY"] == "Y") or sys.stdout.isatty()):
self.skipTest("Not a valid TTY")
curses.initscr()
if curses.tigetstr("ri") is None:
self.skipTest("No valid terminal definition")
示例12: test_text_effects
# 需要导入模块: import curses [as 别名]
# 或者: from curses import tigetstr [as 别名]
def test_text_effects(self):
"""
Check effects can be played.
"""
# Skip for non-Windows if the terminal definition is incomplete.
# This typically means we're running inside a non-standard termina;.
# For example, thi happens when embedded in PyCharm.
if sys.platform != "win32":
if not (("FORCE_TTY" in os.environ and os.environ["FORCE_TTY"] == "Y") or sys.stdout.isatty()):
self.skipTest("Not a valid TTY")
curses.initscr()
if curses.tigetstr("ri") is None:
self.skipTest("No valid terminal definition")
# A lot of effects are just about the visual output working when played
# so check that playing a load of text effects doesn't crash.
#
# It's really not a great test, but it's important to show Effects are
# dynamically compatible with Screen.play().
def internal_checks(screen):
screen.play([
Scene([
MockEffect(count=5),
Print(screen, FigletText("hello"), 2),
Cycle(screen, FigletText("world"), 6),
BannerText(screen, FigletText("world"), 10, 3),
Mirage(screen, FigletText("huh?"), 14, 2)], 0)])
Screen.wrapper(internal_checks, height=25)
示例13: test_rainbow
# 需要导入模块: import curses [as 别名]
# 或者: from curses import tigetstr [as 别名]
def test_rainbow(self):
"""
Check that the Rainbow renderer works.
"""
# Skip for non-Windows if the terminal definition is incomplete.
# This typically means we're running inside a non-standard terminal.
# For example, this happens when embedded in PyCharm.
if sys.platform != "win32":
if not (("FORCE_TTY" in os.environ and os.environ["FORCE_TTY"] == "Y") or sys.stdout.isatty()):
self.skipTest("Not a valid TTY")
curses.initscr()
if curses.tigetstr("ri") is None:
self.skipTest("No valid terminal definition")
def internal_checks(screen):
# Create a base renderer
plain_text = (".-------.\n" +
"| hello |\n" +
"`-------`")
renderer = SpeechBubble("hello")
self.assertEqual(str(renderer), plain_text)
# Pretend that we always have an 8 colour palette for the test.
screen.colours = 8
# Check that the Rainbow renderer doesn't change this.
rainbow = Rainbow(screen, renderer)
self.assertEqual(str(rainbow), plain_text)
# Check rainbow colour scheme.
self.assertEqual(
rainbow.rendered_text[1], [
[(1, 1, None), (1, 1, None), (3, 1, None), (3, 1, None), (2, 1, None),
(2, 1, None), (6, 1, None), (6, 1, None), (4, 1, None)],
[(1, 1, None), (3, 1, None), (3, 1, None), (2, 1, None), (2, 1, None),
(6, 1, None), (6, 1, None), (4, 1, None), (4, 1, None)],
[(3, 1, None), (3, 1, None), (2, 1, None), (2, 1, None), (6, 1, None),
(6, 1, None), (4, 1, None), (4, 1, None), (5, 1, None)]])
Screen.wrapper(internal_checks, height=15)
示例14: __init__
# 需要导入模块: import curses [as 别名]
# 或者: from curses import tigetstr [as 别名]
def __init__(self, height):
super(Terminal, self).__init__(height, line_wrap=True, parser=AnsiTerminalParser())
#Key definitions
self._map = {}
for k, v in [
(Screen.KEY_LEFT, "kcub1"),
(Screen.KEY_RIGHT, "kcuf1"),
(Screen.KEY_UP, "kcuu1"),
(Screen.KEY_DOWN, "kcud1"),
(Screen.KEY_HOME, "khome"),
(Screen.KEY_END, "kend"),
(Screen.KEY_BACK, "kbs"),
]:
self._map[k] = curses.tigetstr(v)
self._map[Screen.KEY_TAB] = "\t".encode()
# Open a pseudo TTY to control the interactive session. Make it non-blocking.
self._master, slave = pty.openpty()
fl = fcntl.fcntl(self._master, fcntl.F_GETFL)
fcntl.fcntl(self._master, fcntl.F_SETFL, fl | os.O_NONBLOCK)
# Start the shell and thread to pull data from it.
self._shell = subprocess.Popen(["bash", "-i"], preexec_fn=os.setsid, stdin=slave, stdout=slave, stderr=slave)
self._lock = threading.Lock()
self._thread = threading.Thread(target=self._background)
self._thread.daemon = True
self._thread.start()
示例15: __init__
# 需要导入模块: import curses [as 别名]
# 或者: from curses import tigetstr [as 别名]
def __init__(self, color=True, *args, **kwargs):
logging.Formatter.__init__(self, *args, **kwargs)
self._color = color and _stderr_supports_color()
if self._color:
# The curses module has some str/bytes confusion in
# python3. Until version 3.2.3, most methods return
# bytes, but only accept strings. In addition, we want to
# output these strings with the logging module, which
# works with unicode strings. The explicit calls to
# unicode() below are harmless in python2 but will do the
# right conversion in python 3.
fg_color = (curses.tigetstr("setaf") or
curses.tigetstr("setf") or "")
if (3, 0) < sys.version_info < (3, 2, 3):
fg_color = unicode_type(fg_color, "ascii")
self._colors = {
logging.DEBUG: unicode_type(curses.tparm(fg_color, 4), # Blue
"ascii"),
logging.INFO: unicode_type(curses.tparm(fg_color, 2), # Green
"ascii"),
logging.WARNING: unicode_type(curses.tparm(fg_color, 3), # Yellow
"ascii"),
logging.ERROR: unicode_type(curses.tparm(fg_color, 1), # Red
"ascii"),
}
self._normal = unicode_type(curses.tigetstr("sgr0"), "ascii")