当前位置: 首页>>代码示例>>Python>>正文


Python document.Document方法代码示例

本文整理汇总了Python中prompt_toolkit.document.Document方法的典型用法代码示例。如果您正苦于以下问题:Python document.Document方法的具体用法?Python document.Document怎么用?Python document.Document使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在prompt_toolkit.document的用法示例。


在下文中一共展示了document.Document方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_completion

# 需要导入模块: from prompt_toolkit import document [as 别名]
# 或者: from prompt_toolkit.document import Document [as 别名]
def test_completion():
    @click.group()
    def foo_group():
        pass

    @foo_group.command()
    def foo_cmd():
        pass

    @click.group()
    def foobar_group():
        pass

    @foobar_group.command()
    def foobar_cmd():
        pass

    c = ClickCompleter(click.CommandCollection(sources=[foo_group, foobar_group]))
    completions = list(c.get_completions(Document(u"foo")))

    assert set(x.text for x in completions) == set([u"foo_cmd", u"foobar_cmd"]) 
开发者ID:click-contrib,项目名称:click-repl,代码行数:23,代码来源:test_command_collection.py

示例2: test_completion

# 需要导入模块: from prompt_toolkit import document [as 别名]
# 或者: from prompt_toolkit.document import Document [as 别名]
def test_completion():
    @click.group()
    def root_command():
        pass

    @root_command.group()
    def first_level_command():
        pass

    @first_level_command.command()
    def second_level_command_one():
        pass

    @first_level_command.command()
    def second_level_command_two():
        pass

    c = ClickCompleter(root_command)
    completions = list(c.get_completions(Document(u"first_level_command ")))

    assert set(x.text for x in completions) == set(
        [u"second_level_command_one", u"second_level_command_two"]
    ) 
开发者ID:click-contrib,项目名称:click-repl,代码行数:25,代码来源:test_basic.py

示例3: get_new_document

# 需要导入模块: from prompt_toolkit import document [as 别名]
# 或者: from prompt_toolkit.document import Document [as 别名]
def get_new_document(self, cursor_pos=None):
        """
        Create a `Document` instance that contains the resulting text.
        """
        lines = []

        # Original text, before cursor.
        if self.original_document.text_before_cursor:
            lines.append(self.original_document.text_before_cursor)

        # Selected entries from the history.
        for line_no in sorted(self.selected_lines):
            lines.append(self.history_lines[line_no])

        # Original text, after cursor.
        if self.original_document.text_after_cursor:
            lines.append(self.original_document.text_after_cursor)

        # Create `Document` with cursor at the right position.
        text = "\n".join(lines)
        if cursor_pos is not None and cursor_pos > len(text):
            cursor_pos = len(text)
        return Document(text, cursor_pos) 
开发者ID:prompt-toolkit,项目名称:ptpython,代码行数:25,代码来源:history_browser.py

示例4: _get_expression_completions

# 需要导入模块: from prompt_toolkit import document [as 别名]
# 或者: from prompt_toolkit.document import Document [as 别名]
def _get_expression_completions(
        self,
        document: Document,
        complete_event: CompleteEvent,
        temp_locals: Dict[str, Any],
    ) -> Iterable[Completion]:
        """
        Complete the [ or . operator after an object.
        """
        match = self.expression_pattern.search(document.text_before_cursor)
        if match is not None:
            object_var = match.groups()[0]
            result = self._lookup(object_var, temp_locals)

            if isinstance(result, (list, tuple, dict)):
                yield Completion("[", 0)
            elif result:
                yield Completion(".", 0) 
开发者ID:prompt-toolkit,项目名称:ptpython,代码行数:20,代码来源:completer.py

示例5: _get_attribute_completions

# 需要导入模块: from prompt_toolkit import document [as 别名]
# 或者: from prompt_toolkit.document import Document [as 别名]
def _get_attribute_completions(
        self,
        document: Document,
        complete_event: CompleteEvent,
        temp_locals: Dict[str, Any],
    ) -> Iterable[Completion]:
        """
        Complete attribute names.
        """
        match = self.attribute_lookup_pattern.search(document.text_before_cursor)
        if match is not None:
            object_var, attr_name = match.groups()

            # Do lookup of `object_var` in the context.
            result = self._lookup(object_var, temp_locals)

            for name in dir(result):
                if name.startswith(attr_name):
                    yield Completion(
                        name, -len(attr_name),
                    ) 
开发者ID:prompt-toolkit,项目名称:ptpython,代码行数:23,代码来源:completer.py

示例6: test_cursor_position

# 需要导入模块: from prompt_toolkit import document [as 别名]
# 或者: from prompt_toolkit.document import Document [as 别名]
def test_cursor_position(self, mock_session):
        mock_document = Document(text='cat bar --foo bar', cursor_position=6)
        comp = ShellCompleter()
        Resource('bar', uuid='4c6d3711-61f1-4505-b8df-189d32b52872')
        Resource('foo', uuid='7413a49b-4f17-4340-b93f-7e03b29b5a9d')
        completions = comp.get_completions(mock_document, None)
        self.assertEqual(len(list(completions)), 1)

        mock_document = Document(text='ls -P  foo', cursor_position=6)
        completions = comp.get_completions(mock_document, None)
        self.assertEqual(len(list(completions)), 2)

        mock_document = Document(text='ln  foo', cursor_position=3)
        completions = comp.get_completions(mock_document, None)
        self.assertEqual(len(list(completions)), 2)

        mock_document = Document(text='ln  foo bar', cursor_position=3)
        completions = comp.get_completions(mock_document, None)
        self.assertEqual(len(list(completions)), 0)

        mock_document = Document(text='ln foo bar', cursor_position=6)
        completions = comp.get_completions(mock_document, None)
        self.assertEqual(len(list(completions)), 1) 
开发者ID:eonpatapon,项目名称:contrail-api-cli,代码行数:25,代码来源:test_completer.py

示例7: test_fq_name_completion

# 需要导入模块: from prompt_toolkit import document [as 别名]
# 或者: from prompt_toolkit.document import Document [as 别名]
def test_fq_name_completion(self, mock_session):
        mock_document = Document(text='cat bar/default-dom')

        comp = ShellCompleter()
        r1 = Resource('bar', fq_name='default-domain:project:resource')
        r2 = Resource('bar', fq_name='foo:foo:foo')

        completions = list(comp.get_completions(mock_document, None))
        self.assertEqual(len(completions), 1)
        self.assertTrue(str(r1.path.relative_to(Context().shell.current_path)) in
                        [c.text for c in completions])

        r1.delete()
        r2.delete()
        completions = comp.get_completions(mock_document, None)
        self.assertEqual(len(list(completions)), 0) 
开发者ID:eonpatapon,项目名称:contrail-api-cli,代码行数:18,代码来源:test_completer.py

示例8: get_completions

# 需要导入模块: from prompt_toolkit import document [as 别名]
# 或者: from prompt_toolkit.document import Document [as 别名]
def get_completions(self, document, complete_event):
        """Yield completions"""
        # Detect a file handle
        m = HSYM_RE.match(document.text_before_cursor)
        if m:
            text = m.group(1)
            doc = Document(text, len(text))
            for c in self.path_completer.get_completions(doc, complete_event):
                yield c
        else:
            # Get word/text before cursor.
            word_before_cursor = document.get_word_before_cursor(False)
            for words, meta in self.words_info:
                for a in words:
                    if a.startswith(word_before_cursor):
                        yield Completion(a, -len(word_before_cursor),
                                         display_meta=meta) 
开发者ID:KxSystems,项目名称:pyq,代码行数:19,代码来源:ptk.py

示例9: test_undo_capitalize

# 需要导入模块: from prompt_toolkit import document [as 别名]
# 或者: from prompt_toolkit.document import Document [as 别名]
def test_undo_capitalize(self):
        buffer = Buffer()

        text = 'Selec'
        buffer.set_document(Document(text, len(text)))
        self.capitalizer.apply_capitalization(buffer)
        self.assertEqual('Selec', buffer.text)

        text = buffer.text + 't'
        buffer.set_document(Document(text, len(text)))
        self.capitalizer.apply_capitalization(buffer)
        self.assertEqual('SELECT', buffer.text)

        text = buffer.text + 'i'
        buffer.set_document(Document(text, len(text)))
        self.capitalizer.apply_capitalization(buffer)
        self.assertEqual('Selecti', buffer.text)

        text = buffer.text + 'on'
        buffer.set_document(Document(text, len(text)))
        self.capitalizer.apply_capitalization(buffer)
        self.assertEqual('Selection', buffer.text) 
开发者ID:crate,项目名称:crash,代码行数:24,代码来源:test_repl.py

示例10: test_second_completion

# 需要导入模块: from prompt_toolkit import document [as 别名]
# 或者: from prompt_toolkit.document import Document [as 别名]
def test_second_completion(self):
        self.init3()
        doc = Document(u'crea ')
        gen = self.completer.get_completions(doc, None)
        with self.assertRaises(StopIteration):
            six.next(gen)

        doc = Document(u'create --fun ')
        gen = self.completer.get_completions(doc, None)
        with self.assertRaises(StopIteration):
            six.next(gen)

        doc = Document(u'command d ')
        gen = self.completer.get_completions(doc, None)
        with self.assertRaises(StopIteration):
            six.next(gen)

        doc = Document(u'create --funtimes "life" --hello')
        gen = self.completer.get_completions(doc, None)
        self.assertEqual(six.next(gen), Completion(
            "--helloworld", -7)) 
开发者ID:Azure,项目名称:azure-cli-shell,代码行数:23,代码来源:test_completion.py

示例11: command_prompt

# 需要导入模块: from prompt_toolkit import document [as 别名]
# 或者: from prompt_toolkit.document import Document [as 别名]
def command_prompt(pymux, variables):
    """
    Enter command prompt.
    """
    client_state = pymux.get_client_state()

    if variables['<command>']:
        # When a 'command' has been given.
        client_state.prompt_text = variables['<message>'] or '(%s)' % variables['<command>'].split()[0]
        client_state.prompt_command = variables['<command>']

        client_state.prompt_mode = True
        client_state.prompt_buffer.reset(Document(
            format_pymux_string(pymux, variables['<default>'] or '')))

        get_app().layout.focus(client_state.prompt_buffer)
    else:
        # Show the ':' prompt.
        client_state.prompt_text = ''
        client_state.prompt_command = ''

        get_app().layout.focus(client_state.command_buffer)

    # Go to insert mode.
    get_app().vi_state.input_mode = InputMode.INSERT 
开发者ID:prompt-toolkit,项目名称:pymux,代码行数:27,代码来源:commands.py

示例12: get_completions

# 需要导入模块: from prompt_toolkit import document [as 别名]
# 或者: from prompt_toolkit.document import Document [as 别名]
def get_completions(
        self, document: Document, complete_event: CompleteEvent
    ) -> Iterable[Completion]:
        """
        This should be a generator that yields :class:`.Completion` instances.

        If the generation of completions is something expensive (that takes a
        lot of time), consider wrapping this `Completer` class in a
        `ThreadedCompleter`. In that case, the completer algorithm runs in a
        background thread and completions will be displayed as soon as they
        arrive.

        :param document: :class:`~prompt_toolkit.document.Document` instance.
        :param complete_event: :class:`.CompleteEvent` instance.
        """
        while False:
            yield 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:19,代码来源:base.py

示例13: get_common_complete_suffix

# 需要导入模块: from prompt_toolkit import document [as 别名]
# 或者: from prompt_toolkit.document import Document [as 别名]
def get_common_complete_suffix(
    document: Document, completions: Sequence[Completion]
) -> str:
    """
    Return the common prefix for all completions.
    """
    # Take only completions that don't change the text before the cursor.
    def doesnt_change_before_cursor(completion: Completion) -> bool:
        end = completion.text[: -completion.start_position]
        return document.text_before_cursor.endswith(end)

    completions2 = [c for c in completions if doesnt_change_before_cursor(c)]

    # When there is at least one completion that changes the text before the
    # cursor, don't return any common part.
    if len(completions2) != len(completions):
        return ""

    # Return the common prefix.
    def get_suffix(completion: Completion) -> str:
        return completion.text[-completion.start_position :]

    return _commonprefix([get_suffix(c) for c in completions2]) 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:25,代码来源:base.py

示例14: insert_comment

# 需要导入模块: from prompt_toolkit import document [as 别名]
# 或者: from prompt_toolkit.document import Document [as 别名]
def insert_comment(event: E) -> None:
    """
    Without numeric argument, comment all lines.
    With numeric argument, uncomment all lines.
    In any case accept the input.
    """
    buff = event.current_buffer

    # Transform all lines.
    if event.arg != 1:

        def change(line: str) -> str:
            return line[1:] if line.startswith("#") else line

    else:

        def change(line: str) -> str:
            return "#" + line

    buff.document = Document(
        text="\n".join(map(change, buff.text.splitlines())), cursor_position=0
    )

    # Accept input.
    buff.validate_and_handle() 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:27,代码来源:named_commands.py

示例15: get_sync_start_position

# 需要导入模块: from prompt_toolkit import document [as 别名]
# 或者: from prompt_toolkit.document import Document [as 别名]
def get_sync_start_position(
        self, document: Document, lineno: int
    ) -> Tuple[int, int]:
        """
        Scan backwards, and find a possible position to start.
        """
        pattern = self._compiled_pattern
        lines = document.lines

        # Scan upwards, until we find a point where we can start the syntax
        # synchronisation.
        for i in range(lineno, max(-1, lineno - self.MAX_BACKWARDS), -1):
            match = pattern.match(lines[i])
            if match:
                return i, match.start()

        # No synchronisation point found. If we aren't that far from the
        # beginning, start at the very beginning, otherwise, just try to start
        # at the current line.
        if lineno < self.FROM_START_IF_NO_SYNC_POS_FOUND:
            return 0, 0
        else:
            return lineno, 0 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:25,代码来源:pygments.py


注:本文中的prompt_toolkit.document.Document方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。