本文整理匯總了Python中blessed.Terminal方法的典型用法代碼示例。如果您正苦於以下問題:Python blessed.Terminal方法的具體用法?Python blessed.Terminal怎麽用?Python blessed.Terminal使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類blessed
的用法示例。
在下文中一共展示了blessed.Terminal方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_termcap_repr
# 需要導入模塊: import blessed [as 別名]
# 或者: from blessed import Terminal [as 別名]
def test_termcap_repr():
"Ensure ``hidden_cursor()`` writes hide_cursor and normal_cursor."
given_ttype='vt220'
given_capname = 'cursor_up'
expected = [r"<Termcap cursor_up:'\x1b\\[A'>",
r"<Termcap cursor_up:'\\\x1b\\[A'>",
r"<Termcap cursor_up:u'\\\x1b\\[A'>"]
@as_subprocess
def child():
import blessed
term = blessed.Terminal(given_ttype)
given = repr(term.caps[given_capname])
assert given in expected
child()
示例2: load_theme_from_json
# 需要導入模塊: import blessed [as 別名]
# 或者: from blessed import Terminal [as 別名]
def load_theme_from_json(json_theme):
"""
Load a theme from a json.
Expected format:
{
"Question": {
"mark_color": "yellow",
"brackets_color": "normal",
...
},
"List": {
"selection_color": "bold_blue",
"selection_cursor": "->"
}
}
Color values should be string representing valid blessings.Terminal colors.
"""
return load_theme_from_dict(json.loads(json_theme))
示例3: setUp
# 需要導入模塊: import blessed [as 別名]
# 或者: from blessed import Terminal [as 別名]
def setUp(self):
self.term = Terminal()
self.theme_dict = {
'Question': {
'mark_color': 'red',
'brackets_color': 'yellow'
},
'List': {
'selection_color': 'red',
'selection_cursor': '->'
}
}
self.theme_dict_wrong_field = {
'Question': {
'ark_color': 'red'
}
}
self.theme_dict_wrong_question = {
'questionn': {
'mark_color': 'red'
}
}
示例4: test_export_only_Terminal
# 需要導入模塊: import blessed [as 別名]
# 或者: from blessed import Terminal [as 別名]
def test_export_only_Terminal():
"Ensure only Terminal instance is exported for import * statements."
import blessed
assert blessed.__all__ == ('Terminal',)
示例5: test_null_fileno
# 需要導入模塊: import blessed [as 別名]
# 或者: from blessed import Terminal [as 別名]
def test_null_fileno():
"Make sure ``Terminal`` works when ``fileno`` is ``None``."
@as_subprocess
def child():
# This simulates piping output to another program.
out = six.StringIO()
out.fileno = None
t = TestTerminal(stream=out)
assert (t.save == u'')
child()
示例6: init_terminal
# 需要導入模塊: import blessed [as 別名]
# 或者: from blessed import Terminal [as 別名]
def init_terminal():
global terminal
if terminal:
return
else:
if sys.platform.startswith('win'):
terminal = WindowsTerminal()
else:
from blessed import Terminal
terminal = Terminal()
io.echo(terminal.clear())
示例7: __init__
# 需要導入模塊: import blessed [as 別名]
# 或者: from blessed import Terminal [as 別名]
def __init__(self):
self.term = Terminal()
self.roku = None
示例8: display
# 需要導入模塊: import blessed [as 別名]
# 或者: from blessed import Terminal [as 別名]
def display(self):
"""Render current tile and its items. Recurse into nested splits
if any.
"""
try:
t = self._terminal
except AttributeError:
t = self._terminal = Terminal()
tbox = TBox(t, 0, 0, t.width, t.height - 1)
self._fill_area(tbox.t, 0, 0, t.width, t.height - 1, "f") # FIXME
tbox = TBox(t, 0, 0, t.width, t.height - 1)
self._display(tbox, None)
# park cursor in a safe place and reset color
print(t.move(t.height - 3, 0) + t.color(0))
示例9: __init__
# 需要導入模塊: import blessed [as 別名]
# 或者: from blessed import Terminal [as 別名]
def __init__(self, pterminal = None, prefix="Controller",lineno=0):
self.terminal = Terminal() if not pterminal else pterminal
self.prefix = prefix
self.lineno = lineno
示例10: __init__
# 需要導入模塊: import blessed [as 別名]
# 或者: from blessed import Terminal [as 別名]
def __init__(self, event_generator=None, theme=None, *args, **kwargs):
super(ConsoleRender, self).__init__(*args, **kwargs)
self._event_gen = event_generator or events.KeyEventGenerator()
self.terminal = Terminal()
self._previous_error = None
self._position = 0
self._theme = theme or themes.Default()
示例11: __init__
# 需要導入模塊: import blessed [as 別名]
# 或者: from blessed import Terminal [as 別名]
def __init__(self, question, theme=None, terminal=None, show_default=False,
*args, **kwargs):
super(BaseConsoleRender, self).__init__(*args, **kwargs)
self.question = question
self.terminal = terminal or Terminal()
self.answers = {}
self.theme = theme
self.show_default = show_default
示例12: load_theme_from_dict
# 需要導入模塊: import blessed [as 別名]
# 或者: from blessed import Terminal [as 別名]
def load_theme_from_dict(dict_theme):
"""
Load a theme from a dict.
Expected format:
{
"Question": {
"mark_color": "yellow",
"brackets_color": "normal",
...
},
"List": {
"selection_color": "bold_blue",
"selection_cursor": "->"
}
}
Color values should be string representing valid blessings.Terminal colors.
"""
t = Default()
for question_type, settings in dict_theme.items():
if question_type not in vars(t):
raise ThemeError('Error while parsing theme. Question type '
'`{}` not found or not customizable.'
.format(question_type))
# calculating fields of namedtuple, hence the filtering
question_fields = list(filter(lambda x: not x.startswith('_'),
vars(getattr(t, question_type))))
for field, value in settings.items():
if field not in question_fields:
raise ThemeError('Error while parsing theme. Field '
'`{}` invalid for question type `{}`'
.format(field, question_type))
actual_value = getattr(term, value) or value
setattr(getattr(t, question_type), field, actual_value)
return t
示例13: test_win32_missing_tty_modules
# 需要導入模塊: import blessed [as 別名]
# 或者: from blessed import Terminal [as 別名]
def test_win32_missing_tty_modules(monkeypatch):
"Ensure dummy exception is used when io is without UnsupportedOperation."
@as_subprocess
def child():
OLD_STYLE = False
try:
original_import = getattr(__builtins__, '__import__')
OLD_STYLE = True
except AttributeError:
original_import = __builtins__['__import__']
tty_modules = ('termios', 'fcntl', 'tty')
def __import__(name, *args, **kwargs):
if name in tty_modules:
raise ImportError
return original_import(name, *args, **kwargs)
for module in tty_modules:
sys.modules.pop(module, None)
warnings.filterwarnings("error", category=UserWarning)
try:
if OLD_STYLE:
__builtins__.__import__ = __import__
else:
__builtins__['__import__'] = __import__
try:
import blessed.terminal
imp.reload(blessed.terminal)
except UserWarning:
err = sys.exc_info()[1]
assert err.args[0] == blessed.terminal._MSG_NOSUPPORT
warnings.filterwarnings("ignore", category=UserWarning)
import blessed.terminal
imp.reload(blessed.terminal)
assert not blessed.terminal.HAS_TTY
term = blessed.terminal.Terminal('ansi')
# https://en.wikipedia.org/wiki/VGA-compatible_text_mode
# see section '#PC_common_text_modes'
assert term.height == 25
assert term.width == 80
finally:
if OLD_STYLE:
setattr(__builtins__, '__import__', original_import)
else:
__builtins__['__import__'] = original_import
warnings.resetwarnings()
import blessed.terminal
imp.reload(blessed.terminal)
child()