Python prompt_toolkit.completion.DynamicCompleter() Examples
The following are 2
code examples of prompt_toolkit.completion.DynamicCompleter().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
prompt_toolkit.completion
, or try the search function
.
Example #1
Source File: prompt.py From python-prompt-toolkit with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 ""), )
Example #2
Source File: main.py From athenacli with BSD 3-Clause "New" or "Revised" License | 4 votes |
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 )