本文整理汇总了Python中prompt_toolkit.completion.DynamicCompleter方法的典型用法代码示例。如果您正苦于以下问题:Python completion.DynamicCompleter方法的具体用法?Python completion.DynamicCompleter怎么用?Python completion.DynamicCompleter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prompt_toolkit.completion
的用法示例。
在下文中一共展示了completion.DynamicCompleter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_default_buffer
# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import DynamicCompleter [as 别名]
def _create_default_buffer(self) -> Buffer:
"""
Create and return the default input buffer.
"""
dyncond = self._dyncond
# Create buffers list.
def accept(buff: Buffer) -> bool:
""" Accept the content of the default buffer. This is called when
the validation succeeds. """
cast(Application[str], get_app()).exit(result=buff.document.text)
return True # Keep text, we call 'reset' later on.
return Buffer(
name=DEFAULT_BUFFER,
# Make sure that complete_while_typing is disabled when
# enable_history_search is enabled. (First convert to Filter,
# to avoid doing bitwise operations on bool objects.)
complete_while_typing=Condition(
lambda: is_true(self.complete_while_typing)
and not is_true(self.enable_history_search)
and not self.complete_style == CompleteStyle.READLINE_LIKE
),
validate_while_typing=dyncond("validate_while_typing"),
enable_history_search=dyncond("enable_history_search"),
validator=DynamicValidator(lambda: self.validator),
completer=DynamicCompleter(
lambda: ThreadedCompleter(self.completer)
if self.complete_in_thread and self.completer
else self.completer
),
history=self.history,
auto_suggest=DynamicAutoSuggest(lambda: self.auto_suggest),
accept_handler=accept,
tempfile_suffix=lambda: to_str(self.tempfile_suffix or ""),
tempfile=lambda: to_str(self.tempfile or ""),
)
示例2: _build_prompt_app
# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import DynamicCompleter [as 别名]
def _build_prompt_app(self, history):
key_bindings = cli_bindings(self)
def get_message():
prompt = self.get_prompt(self.prompt)
if len(prompt) > self.MAX_LEN_PROMPT:
prompt = self.get_prompt('\\r:\\d> ')
return [('class:prompt', prompt)]
def get_continuation(width, line_number, is_soft_wrap):
continuation = ' ' * (width -1) + ' '
return [('class:continuation', continuation)]
def show_suggestion_tip():
return self.iterations < 2
get_toolbar_tokens = create_toolbar_tokens_func(
self, show_suggestion_tip)
with self._completer_lock:
if self.key_bindings == 'vi':
editing_mode = EditingMode.VI
else:
editing_mode = EditingMode.EMACS
self.prompt_app = PromptSession(
lexer=PygmentsLexer(Lexer),
reserve_space_for_menu=self.get_reserved_space(),
message=get_message,
prompt_continuation=get_continuation,
bottom_toolbar=get_toolbar_tokens,
complete_style=CompleteStyle.COLUMN,
input_processors=[ConditionalProcessor(
processor=HighlightMatchingBracketProcessor(
chars='[](){}'),
filter=HasFocus(DEFAULT_BUFFER) & ~IsDone()
)],
tempfile_suffix='.sql',
completer=DynamicCompleter(lambda: self.completer),
history=history,
auto_suggest=AutoSuggestFromHistory(),
complete_while_typing=True,
multiline=cli_is_multiline(self),
style=style_factory(self.syntax_style, self.cli_style),
include_default_pygments_style=False,
key_bindings=key_bindings,
enable_open_in_editor=True,
enable_system_prompt=True,
editing_mode=editing_mode,
search_ignore_case=True
)