本文整理汇总了Python中prompt_toolkit.interface.Application方法的典型用法代码示例。如果您正苦于以下问题:Python interface.Application方法的具体用法?Python interface.Application怎么用?Python interface.Application使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prompt_toolkit.interface
的用法示例。
在下文中一共展示了interface.Application方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_application
# 需要导入模块: from prompt_toolkit import interface [as 别名]
# 或者: from prompt_toolkit.interface import Application [as 别名]
def create_application(self, full_layout=True):
""" makes the application object and the buffers """
if full_layout:
layout = create_layout(self.lexer, ExampleLexer, ToolbarLexer)
else:
layout = create_tutorial_layout(self.lexer)
buffers = {
DEFAULT_BUFFER: Buffer(is_multiline=True),
'description': Buffer(is_multiline=True, read_only=True),
'parameter' : Buffer(is_multiline=True, read_only=True),
'examples' : Buffer(is_multiline=True, read_only=True),
'bottom_toolbar' : Buffer(is_multiline=True),
'example_line' : Buffer(is_multiline=True),
'default_values' : Buffer(),
'symbols' : Buffer()
}
writing_buffer = Buffer(
history=self.history,
auto_suggest=AutoSuggestFromHistory(),
enable_history_search=True,
completer=self.completer,
complete_while_typing=Always()
)
return Application(
mouse_support=False,
style=self.styles,
buffer=writing_buffer,
on_input_timeout=self.on_input_timeout,
key_bindings_registry=registry,
layout=layout,
buffers=buffers,
)
示例2: create_application
# 需要导入模块: from prompt_toolkit import interface [as 别名]
# 或者: from prompt_toolkit.interface import Application [as 别名]
def create_application(self, full_layout=True):
""" makes the application object and the buffers """
if full_layout:
layout = create_layout(self.lexer, ExampleLexer, ToolbarLexer)
else:
layout = create_tutorial_layout(self.lexer)
buffers = {
DEFAULT_BUFFER: Buffer(is_multiline=True),
'description': Buffer(is_multiline=True, read_only=True),
'parameter': Buffer(is_multiline=True, read_only=True),
'examples': Buffer(is_multiline=True, read_only=True),
'bottom_toolbar': Buffer(is_multiline=True),
'example_line': Buffer(is_multiline=True),
'default_values': Buffer(),
'symbols': Buffer(),
'progress': Buffer(is_multiline=False)
}
writing_buffer = Buffer(
history=self.history,
auto_suggest=AutoSuggestFromHistory(),
enable_history_search=True,
completer=self.completer,
complete_while_typing=Always()
)
return Application(
mouse_support=False,
style=self.styles,
buffer=writing_buffer,
on_input_timeout=self.on_input_timeout,
key_bindings_registry=registry,
layout=layout,
buffers=buffers,
)
示例3: set_application
# 需要导入模块: from prompt_toolkit import interface [as 别名]
# 或者: from prompt_toolkit.interface import Application [as 别名]
def set_application(self, app, callback=None):
"""
Set ``CommandLineInterface`` instance for this connection.
(This can be replaced any time.)
:param cli: CommandLineInterface instance.
:param callback: Callable that takes the result of the CLI.
"""
assert isinstance(app, Application)
assert callback is None or callable(callback)
self.cli = CommandLineInterface(
application=app,
eventloop=self.eventloop,
output=self.vt100_output)
self.callback = callback
# Create a parser, and parser callbacks.
cb = self.cli.create_eventloop_callbacks()
inputstream = InputStream(cb.feed_key)
# Input decoder for stdin. (Required when working with multibyte
# characters, like chinese input.)
stdin_decoder_cls = getincrementaldecoder(self.encoding)
stdin_decoder = [stdin_decoder_cls()] # nonlocal
# Tell the CLI that it's running. We don't start it through the run()
# call, but will still want _redraw() to work.
self.cli._is_running = True
def data_received(data):
""" TelnetProtocolParser 'data_received' callback """
assert isinstance(data, binary_type)
try:
result = stdin_decoder[0].decode(data)
inputstream.feed(result)
except UnicodeDecodeError:
stdin_decoder[0] = stdin_decoder_cls()
return ''
def size_received(rows, columns):
""" TelnetProtocolParser 'size_received' callback """
self.size = Size(rows=rows, columns=columns)
cb.terminal_size_changed()
self.parser = TelnetProtocolParser(data_received, size_received)
示例4: create_cli
# 需要导入模块: from prompt_toolkit import interface [as 别名]
# 或者: from prompt_toolkit.interface import Application [as 别名]
def create_cli(self):
## KeyBindings configuration
key_binding = KeyBindingManager(
enable_search=True,
enable_abort_and_exit_bindings=True,
enable_system_bindings=True,
enable_auto_suggest_bindings=True,
enable_open_in_editor=False)
## Buffer configuration
default_buffer= Buffer(
history=self.file_history,
auto_suggest=AutoSuggestFromHistory(),
enable_history_search=True,
completer=self.completer,
complete_while_typing=Always(),
accept_action=AcceptAction.RETURN_DOCUMENT)
## Style configuration
try:
style = get_style_by_name(self._config.highlighter_style)
except ClassNotFound:
style = get_style_by_name('native')
styles = {}
styles.update(style.styles)
styles.update(default_style_extensions)
styles.update({
Token.Menu.Completions.Completion: 'bg:#003fff #ffffff',
Token.Menu.Completions.Completion.Current: 'bg:#5ab300 #000000',
Token.Menu.Completions.Meta.Current: 'bg:#5ab300 #ffffff',
Token.Menu.Completions.Meta: 'bg:#ffffff #000000',
Token.Scrollbar: 'bg:#003fff',
Token.Scrollbar.Button: 'bg:#003333',
})
prompt_style = style_from_dict(styles)
## Application
application = Application(
layout=self.create_cli_layout(),
mouse_support=False,
style=prompt_style,
buffer=default_buffer,
on_abort=AbortAction.RETRY,
on_exit=AbortAction.RAISE_EXCEPTION,
on_input_timeout=self.on_input_timeout,
key_bindings_registry=key_binding.registry,
)
cli = CommandLineInterface(application=application,
eventloop=create_eventloop())
return cli