當前位置: 首頁>>代碼示例>>Python>>正文


Python completion.Completer方法代碼示例

本文整理匯總了Python中prompt_toolkit.completion.Completer方法的典型用法代碼示例。如果您正苦於以下問題:Python completion.Completer方法的具體用法?Python completion.Completer怎麽用?Python completion.Completer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在prompt_toolkit.completion的用法示例。


在下文中一共展示了completion.Completer方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_completer

# 需要導入模塊: from prompt_toolkit import completion [as 別名]
# 或者: from prompt_toolkit.completion import Completer [as 別名]
def test_completer():
    class completer1(Completer):
        def get_completions(self, document, complete_event):
            yield Completion("before-%s-after" % document.text, -len(document.text))
            yield Completion("before-%s-after-B" % document.text, -len(document.text))

    class completer2(Completer):
        def get_completions(self, document, complete_event):
            yield Completion("before2-%s-after2" % document.text, -len(document.text))
            yield Completion("before2-%s-after2-B" % document.text, -len(document.text))

    # Create grammar.  "var1" + "whitespace" + "var2"
    g = compile(r"(?P<var1>[a-z]*) \s+ (?P<var2>[a-z]*)")

    # Test 'get_completions()'
    completer = GrammarCompleter(g, {"var1": completer1(), "var2": completer2()})
    completions = list(
        completer.get_completions(Document("abc def", len("abc def")), CompleteEvent())
    )

    assert len(completions) == 2
    assert completions[0].text == "before2-def-after2"
    assert completions[0].start_position == -3
    assert completions[1].text == "before2-def-after2-B"
    assert completions[1].start_position == -3 
開發者ID:prompt-toolkit,項目名稱:python-prompt-toolkit,代碼行數:27,代碼來源:test_regular_languages.py

示例2: __init__

# 需要導入模塊: from prompt_toolkit import completion [as 別名]
# 或者: from prompt_toolkit.completion import Completer [as 別名]
def __init__(self,
                 input_handler: Callable,
                 bindings: KeyBindings,
                 completer: Completer):
        self.search_field = create_search_field()
        self.input_field = create_input_field(completer=completer)
        self.output_field = create_output_field()
        self.log_field = create_log_field(self.search_field)
        self.layout = generate_layout(self.input_field, self.output_field, self.log_field, self.search_field)
        # add self.to_stop_config to know if cancel is triggered
        self.to_stop_config: bool = False

        self.bindings = bindings
        self.input_handler = input_handler
        self.input_field.accept_handler = self.accept
        self.app = Application(layout=self.layout, full_screen=True, key_bindings=self.bindings, style=load_style(),
                               mouse_support=True, clipboard=PyperclipClipboard())

        # settings
        self.prompt_text = ">>> "
        self.pending_input = None
        self.input_event = None
        self.hide_input = False 
開發者ID:CoinAlpha,項目名稱:hummingbot,代碼行數:25,代碼來源:hummingbot_cli.py

示例3: get_completions

# 需要導入模塊: from prompt_toolkit import completion [as 別名]
# 或者: from prompt_toolkit.completion import Completer [as 別名]
def get_completions(self, document, complete_event):
        """get_completion: main call from the abstract base class "Completer"
          in prompt_toolkit.
        """
        self.word_before_cursor = document.get_word_before_cursor(WORD=True)
        self.word_after_cursor = document.text_after_cursor

        if self.words_count(document.text) == 1:
            self.words = COMMANDS
        elif self.words_count(document.text) == 2:
            try:
                if COMMANDS[document.text[:-1].split()[0]][
                    'required_argument'
                ]:
                    self.words = self.torrents
                else:
                    self.words = list()
            except KeyError:
                self.words = list()
        elif self.words_count(document.text) == 3:
            self.words = self.word_command_flags(document.text)
        else:
            self.words = COMMANDS

        for word in self.words:
            if self.word_matches(word):
                yield Completion(word, -len(self.word_before_cursor)) 
開發者ID:rachmadaniHaryono,項目名稱:we-get,代碼行數:29,代碼來源:completer.py

示例4: __init__

# 需要導入模塊: from prompt_toolkit import completion [as 別名]
# 或者: from prompt_toolkit.completion import Completer [as 別名]
def __init__(self, options: Dict[str, Optional[Completer]],
                 ignore_case: bool = True) -> None:

        self.options = options
        self.ignore_case = ignore_case 
開發者ID:skelsec,項目名稱:msldap,代碼行數:7,代碼來源:nested_completer.py

示例5: from_nested_dict

# 需要導入模塊: from prompt_toolkit import completion [as 別名]
# 或者: from prompt_toolkit.completion import Completer [as 別名]
def from_nested_dict(cls, data: NestedDict) -> 'NestedCompleter':
        """
        Create a `NestedCompleter`, starting from a nested dictionary data
        structure, like this:
        .. code::
            data = {
                'show': {
                    'version': None,
                    'interfaces': None,
                    'clock': None,
                    'ip': {'interface': {'brief'}}
                },
                'exit': None
                'enable': None
            }
        The value should be `None` if there is no further completion at some
        point. If all values in the dictionary are None, it is also possible to
        use a set instead.
        Values in this data structure can be a completers as well.
        """
        options = {}
        for key, value in data.items():
            if isinstance(value, Completer):
                options[key] = value
            elif isinstance(value, dict):
                options[key] = cls.from_nested_dict(value)
            elif isinstance(value, set):
                options[key] = cls.from_nested_dict({item: None for item in value})
            else:
                assert value is None
                options[key] = None

        return cls(options) 
開發者ID:skelsec,項目名稱:msldap,代碼行數:35,代碼來源:nested_completer.py

示例6: __init__

# 需要導入模塊: from prompt_toolkit import completion [as 別名]
# 或者: from prompt_toolkit.completion import Completer [as 別名]
def __init__(self):
        # Completer for full command names.
        self._command_completer = WordCompleter(
            sorted(COMMANDS_TO_HANDLERS.keys()),
            ignore_case=True, WORD=True, match_middle=True)

        # Completer for aliases.
        self._aliases_completer = WordCompleter(
            sorted(ALIASES.keys()),
            ignore_case=True, WORD=True, match_middle=True) 
開發者ID:prompt-toolkit,項目名稱:pymux,代碼行數:12,代碼來源:completer.py

示例7: __init__

# 需要導入模塊: from prompt_toolkit import completion [as 別名]
# 或者: from prompt_toolkit.completion import Completer [as 別名]
def __init__(
        self, options: Dict[str, Optional[Completer]], ignore_case: bool = True
    ) -> None:

        self.options = options
        self.ignore_case = ignore_case 
開發者ID:prompt-toolkit,項目名稱:python-prompt-toolkit,代碼行數:8,代碼來源:nested.py

示例8: from_nested_dict

# 需要導入模塊: from prompt_toolkit import completion [as 別名]
# 或者: from prompt_toolkit.completion import Completer [as 別名]
def from_nested_dict(cls, data: NestedDict) -> "NestedCompleter":
        """
        Create a `NestedCompleter`, starting from a nested dictionary data
        structure, like this:

        .. code::

            data = {
                'show': {
                    'version': None,
                    'interfaces': None,
                    'clock': None,
                    'ip': {'interface': {'brief'}}
                },
                'exit': None
                'enable': None
            }

        The value should be `None` if there is no further completion at some
        point. If all values in the dictionary are None, it is also possible to
        use a set instead.

        Values in this data structure can be a completers as well.
        """
        options: Dict[str, Optional[Completer]] = {}
        for key, value in data.items():
            if isinstance(value, Completer):
                options[key] = value
            elif isinstance(value, dict):
                options[key] = cls.from_nested_dict(value)
            elif isinstance(value, set):
                options[key] = cls.from_nested_dict({item: None for item in value})
            else:
                assert value is None
                options[key] = None

        return cls(options) 
開發者ID:prompt-toolkit,項目名稱:python-prompt-toolkit,代碼行數:39,代碼來源:nested.py

示例9: input_dialog

# 需要導入模塊: from prompt_toolkit import completion [as 別名]
# 或者: from prompt_toolkit.completion import Completer [as 別名]
def input_dialog(
    title: AnyFormattedText = "",
    text: AnyFormattedText = "",
    ok_text: str = "OK",
    cancel_text: str = "Cancel",
    completer: Optional[Completer] = None,
    password: FilterOrBool = False,
    style: Optional[BaseStyle] = None,
) -> Application[str]:
    """
    Display a text input box.
    Return the given text, or None when cancelled.
    """

    def accept(buf: Buffer) -> bool:
        get_app().layout.focus(ok_button)
        return True  # Keep text.

    def ok_handler() -> None:
        get_app().exit(result=textfield.text)

    ok_button = Button(text=ok_text, handler=ok_handler)
    cancel_button = Button(text=cancel_text, handler=_return_none)

    textfield = TextArea(
        multiline=False, password=password, completer=completer, accept_handler=accept
    )

    dialog = Dialog(
        title=title,
        body=HSplit(
            [Label(text=text, dont_extend_height=True), textfield,],
            padding=D(preferred=1, max=1),
        ),
        buttons=[ok_button, cancel_button],
        with_background=True,
    )

    return _create_app(dialog, style) 
開發者ID:prompt-toolkit,項目名稱:python-prompt-toolkit,代碼行數:41,代碼來源:dialogs.py

示例10: __init__

# 需要導入模塊: from prompt_toolkit import completion [as 別名]
# 或者: from prompt_toolkit.completion import Completer [as 別名]
def __init__(
        self, compiled_grammar: _CompiledGrammar, completers: Dict[str, Completer]
    ) -> None:

        self.compiled_grammar = compiled_grammar
        self.completers = completers 
開發者ID:prompt-toolkit,項目名稱:python-prompt-toolkit,代碼行數:8,代碼來源:completion.py

示例11: __init__

# 需要導入模塊: from prompt_toolkit import completion [as 別名]
# 或者: from prompt_toolkit.completion import Completer [as 別名]
def __init__(self, command_completer: Completer):
        self._command_completer = command_completer
        self.service_command_map = {} 
開發者ID:benhoff,項目名稱:vexbot,代碼行數:5,代碼來源:completers.py

示例12: set_service_completer

# 需要導入模塊: from prompt_toolkit import completion [as 別名]
# 或者: from prompt_toolkit.completion import Completer [as 別名]
def set_service_completer(self, service: str, completer: Completer):
        self.service_command_map[service] = completer 
開發者ID:benhoff,項目名稱:vexbot,代碼行數:4,代碼來源:completers.py

示例13: create_input_field

# 需要導入模塊: from prompt_toolkit import completion [as 別名]
# 或者: from prompt_toolkit.completion import Completer [as 別名]
def create_input_field(lexer=None, completer: Completer = None):
    return TextArea(
        height=10,
        prompt='>>> ',
        style='class:input-field',
        multiline=False,
        focus_on_click=True,
        lexer=lexer,
        auto_suggest=AutoSuggestFromHistory(),
        completer=completer,
        complete_while_typing=True,
    ) 
開發者ID:CoinAlpha,項目名稱:hummingbot,代碼行數:14,代碼來源:layout.py


注:本文中的prompt_toolkit.completion.Completer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。