本文整理汇总了Python中prompt_toolkit.CommandLineInterface.add_buffer方法的典型用法代码示例。如果您正苦于以下问题:Python CommandLineInterface.add_buffer方法的具体用法?Python CommandLineInterface.add_buffer怎么用?Python CommandLineInterface.add_buffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prompt_toolkit.CommandLineInterface
的用法示例。
在下文中一共展示了CommandLineInterface.add_buffer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PythonCommandLineInterface
# 需要导入模块: from prompt_toolkit import CommandLineInterface [as 别名]
# 或者: from prompt_toolkit.CommandLineInterface import add_buffer [as 别名]
class PythonCommandLineInterface(object):
def __init__(self,
get_globals=None, get_locals=None,
stdin=None, stdout=None,
vi_mode=False, history_filename=None,
style=PythonStyle,
# For internal use.
_completer=None,
_validator=None,
_lexer=None,
_python_prompt_control=None,
_extra_buffers=None,
_extra_buffer_processors=None,
_extra_sidebars=None):
self.settings = PythonCLISettings()
self.get_globals = get_globals or (lambda: {})
self.get_locals = get_locals or self.get_globals
self.completer = _completer or PythonCompleter(self.get_globals, self.get_locals)
self.validator = _validator or PythonValidator()
self.history = FileHistory(history_filename) if history_filename else History()
self.python_prompt_control = _python_prompt_control or PythonPrompt(self.settings)
self._extra_sidebars = _extra_sidebars or []
self._extra_buffer_processors = _extra_buffer_processors or []
self._lexer = _lexer or PythonLexer
# Use a KeyBindingManager for loading the key bindings.
self.key_bindings_manager = KeyBindingManager(enable_vi_mode=vi_mode,
enable_open_in_editor=True,
enable_system_prompt=True)
load_python_bindings(self.key_bindings_manager, self.settings,
add_buffer=self.add_new_python_buffer,
close_current_buffer=self.close_current_python_buffer)
self.get_signatures_thread_running = False
buffers = {
'default': Buffer(focussable=Never()), # Never use or focus the default buffer.
'docstring': Buffer(focussable=HasSignature(self.settings) & ShowDocstring(self.settings)),
# XXX: also make docstring read only.
}
buffers.update(_extra_buffers or {})
self.cli = CommandLineInterface(
style=style,
key_bindings_registry=self.key_bindings_manager.registry,
buffers=buffers,
complete_while_typing=Always(),
on_abort=AbortAction.RETRY,
on_exit=AbortAction.RAISE_EXCEPTION)
def on_input_timeout():
"""
When there is no input activity,
in another thread, get the signature of the current code.
"""
if not self.cli.focus_stack.current.startswith('python-'):
return
# Never run multiple get-signature threads.
if self.get_signatures_thread_running:
return
self.get_signatures_thread_running = True
buffer = self.cli.current_buffer
document = buffer.document
def run():
script = get_jedi_script_from_document(document, self.get_locals(), self.get_globals())
# Show signatures in help text.
if script:
try:
signatures = script.call_signatures()
except ValueError:
# e.g. in case of an invalid \\x escape.
signatures = []
except Exception:
# Sometimes we still get an exception (TypeError), because
# of probably bugs in jedi. We can silence them.
# See: https://github.com/davidhalter/jedi/issues/492
signatures = []
else:
signatures = []
self.get_signatures_thread_running = False
# Set signatures and redraw if the text didn't change in the
# meantime. Otherwise request new signatures.
if buffer.text == document.text:
buffer.signatures = signatures
# Set docstring in docstring buffer.
if signatures:
string = signatures[0].docstring()
if not isinstance(string, six.text_type):
string = string.decode('utf-8')
#.........这里部分代码省略.........