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


Python interface.CommandLineInterface方法代码示例

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


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

示例1: find_window_for_buffer_name

# 需要导入模块: from prompt_toolkit import interface [as 别名]
# 或者: from prompt_toolkit.interface import CommandLineInterface [as 别名]
def find_window_for_buffer_name(cli, buffer_name):
    """
    Look for a :class:`~prompt_toolkit.layout.containers.Window` in the Layout
    that contains the :class:`~prompt_toolkit.layout.controls.BufferControl`
    for the given buffer and return it. If no such Window is found, return None.
    """
    from prompt_toolkit.interface import CommandLineInterface
    assert isinstance(cli, CommandLineInterface)

    from .containers import Window
    from .controls import BufferControl

    for l in cli.layout.walk(cli):
        if isinstance(l, Window) and isinstance(l.content, BufferControl):
            if l.content.buffer_name == buffer_name:
                return l 
开发者ID:chrisjim316,项目名称:Liljimbo-Chatbot,代码行数:18,代码来源:utils.py

示例2: create_application

# 需要导入模块: from prompt_toolkit import interface [as 别名]
# 或者: from prompt_toolkit.interface import CommandLineInterface [as 别名]
def create_application(self):
        self.window = ResourceWindow(self)
        application = Application(
            key_bindings_registry=self.bindings.registry,
            layout=self.window.get_layout(),
            style=style_from_dict(style),
            use_alternate_screen=True,
            buffers=BufferMapping(
                self._create_buffers(),
                initial="RESOURCES_BUFFER"
            )
        )

        self.cli = CommandLineInterface(application=application, eventloop=self.eventloop)
        self.window.refresh_resource_buffer()
        return self.cli 
开发者ID:joeyfeldberg,项目名称:ash,代码行数:18,代码来源:cli.py

示例3: __aenter__

# 需要导入模块: from prompt_toolkit import interface [as 别名]
# 或者: from prompt_toolkit.interface import CommandLineInterface [as 别名]
def __aenter__(self):
        self.eventloop = create_asyncio_eventloop()
        self.completer = WordCompleter(self.known_tokens())

        config = {
            'complete_while_typing': True,
            'enable_history_search': True,
            'history': self.cli_history,
            'auto_suggest': Suggestions(),
            'completer': self.completer,
            'lexer': prompt_toolkit.layout.lexers.SimpleLexer()
        }

        self.cli = CommandLineInterface(
            application=create_prompt_application(f'{self.name} >>> ', **config),
            eventloop=self.eventloop
        )
        return self 
开发者ID:eeue56,项目名称:slack-today-i-did,代码行数:20,代码来源:bot_repl.py

示例4: pt_init

# 需要导入模块: from prompt_toolkit import interface [as 别名]
# 或者: from prompt_toolkit.interface import CommandLineInterface [as 别名]
def pt_init(self):
        def get_prompt_tokens(cli):
            return [(Token.Prompt, self.prompt)]

        if self._ptcomp is None:
            compl = IPCompleter(shell=self.shell,
                                        namespace={},
                                        global_namespace={},
                                        use_readline=False,
                                        parent=self.shell,
                                       )
            self._ptcomp = IPythonPTCompleter(compl)

        self._pt_app = create_prompt_application(
                            editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()),
                            history=self.shell.debugger_history,
                            completer= self._ptcomp,
                            enable_history_search=True,
                            mouse_support=self.shell.mouse_support,
                            get_prompt_tokens=get_prompt_tokens
        )
        self.pt_cli = CommandLineInterface(self._pt_app, eventloop=self.shell._eventloop) 
开发者ID:gastrodia,项目名称:blender,代码行数:24,代码来源:debugger.py

示例5: create_interface

# 需要导入模块: from prompt_toolkit import interface [as 别名]
# 或者: from prompt_toolkit.interface import CommandLineInterface [as 别名]
def create_interface(self):
        """ instantiates the intereface """
        return CommandLineInterface(
            application=self.create_application(),
            eventloop=create_eventloop()) 
开发者ID:Azure,项目名称:azure-cli-shell,代码行数:7,代码来源:app.py

示例6: example_repl

# 需要导入模块: from prompt_toolkit import interface [as 别名]
# 或者: from prompt_toolkit.interface import CommandLineInterface [as 别名]
def example_repl(self, text, example, start_index, continue_flag):
        """ REPL for interactive tutorials """

        if start_index:
            start_index = start_index + 1
            cmd = ' '.join(text.split()[:start_index])
            example_cli = CommandLineInterface(
                application=self.create_application(
                    full_layout=False),
                eventloop=create_eventloop())
            example_cli.buffers['example_line'].reset(
                initial_document=Document(u'{}\n'.format(
                    add_random_new_lines(example)))
            )
            while start_index < len(text.split()):
                if self.default_command:
                    cmd = cmd.replace(self.default_command + ' ', '')
                example_cli.buffers[DEFAULT_BUFFER].reset(
                    initial_document=Document(
                        u'{}'.format(cmd),
                        cursor_position=len(cmd)))
                example_cli.request_redraw()
                answer = example_cli.run()
                if not answer:
                    return "", True
                answer = answer.text
                if answer.strip('\n') == cmd.strip('\n'):
                    continue
                else:
                    if len(answer.split()) > 1:
                        start_index += 1
                        cmd += " " + answer.split()[-1] + " " +\
                               u' '.join(text.split()[start_index:start_index + 1])
            example_cli.exit()
            del example_cli
        else:
            cmd = text

        return cmd, continue_flag

    # pylint: disable=too-many-branches 
开发者ID:Azure,项目名称:azure-cli-shell,代码行数:43,代码来源:app.py

示例7: feed_app_with_input

# 需要导入模块: from prompt_toolkit import interface [as 别名]
# 或者: from prompt_toolkit.interface import CommandLineInterface [as 别名]
def feed_app_with_input(type, message, text, **kwargs):
    """
    Create a CommandLineInterface, feed it with the given user input and return
    the CLI object.

    This returns a (result, CLI) tuple.
    note: this only works if you import your prompt and then this function!!
    """
    # If the given text doesn't end with a newline, the interface won't finish.
    assert text.endswith('\n')

    application = getattr(prompts, type).question(message, **kwargs)

    loop = PosixEventLoop()
    try:
        inp = PipeInput()
        inp.send_text(text)
        cli = CommandLineInterface(
            application=application,
            eventloop=loop,
            input=inp,
            output=DummyOutput())
        result = cli.run()
        return result, cli
    finally:
        loop.close()
        inp.close() 
开发者ID:finklabs,项目名称:whaaaaat,代码行数:29,代码来源:helpers.py

示例8: __init__

# 需要导入模块: from prompt_toolkit import interface [as 别名]
# 或者: from prompt_toolkit.interface import CommandLineInterface [as 别名]
def __init__(self, conn, addr, application, server, encoding):
        assert isinstance(addr, tuple)  # (addr, port) tuple
        assert isinstance(application, TelnetApplication)
        assert isinstance(server, TelnetServer)
        assert isinstance(encoding, text_type)  # e.g. 'utf-8'

        self.conn = conn
        self.addr = addr
        self.application = application
        self.closed = False
        self.handling_command = True
        self.server = server
        self.encoding = encoding
        self.callback = None  # Function that handles the CLI result.

        # Create "Output" object.
        self.size = Size(rows=40, columns=79)

        # Initialize.
        _initialize_telnet(conn)

        # Create output.
        def get_size():
            return self.size
        self.stdout = _ConnectionStdout(conn, encoding=encoding)
        self.vt100_output = Vt100_Output(self.stdout, get_size, write_binary=False)

        # Create an eventloop (adaptor) for the CommandLineInterface.
        self.eventloop = _TelnetEventLoopInterface(server)

        # Set default CommandLineInterface.
        self.set_application(create_prompt_application())

        # Call client_connected
        application.client_connected(self)

        # Draw for the first time.
        self.handling_command = False
        self.cli._redraw() 
开发者ID:chrisjim316,项目名称:Liljimbo-Chatbot,代码行数:41,代码来源:server.py

示例9: pt_init

# 需要导入模块: from prompt_toolkit import interface [as 别名]
# 或者: from prompt_toolkit.interface import CommandLineInterface [as 别名]
def pt_init(self):
        def get_prompt_tokens(cli):
            return [(Token.Prompt, self.prompt)]

        def patch_stdout(**kwargs):
            return self.pt_cli.patch_stdout_context(**kwargs)

        if self._ptcomp is None:
            compl = IPCompleter(shell=self.shell,
                                        namespace={},
                                        global_namespace={},
                                        parent=self.shell,
                                       )
            self._ptcomp = IPythonPTCompleter(compl, patch_stdout=patch_stdout)

        kbmanager = KeyBindingManager.for_prompt()
        supports_suspend = Condition(lambda cli: hasattr(signal, 'SIGTSTP'))
        kbmanager.registry.add_binding(Keys.ControlZ, filter=supports_suspend
                                      )(suspend_to_bg)

        if self.shell.display_completions == 'readlinelike':
            kbmanager.registry.add_binding(Keys.ControlI,
                                 filter=(HasFocus(DEFAULT_BUFFER)
                                         & ~HasSelection()
                                         & ViInsertMode() | EmacsInsertMode()
                                         & ~cursor_in_leading_ws
                                         ))(display_completions_like_readline)
        multicolumn = (self.shell.display_completions == 'multicolumn')

        self._pt_app = create_prompt_application(
                            editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()),
                            key_bindings_registry=kbmanager.registry,
                            history=self.shell.debugger_history,
                            completer= self._ptcomp,
                            enable_history_search=True,
                            mouse_support=self.shell.mouse_support,
                            get_prompt_tokens=get_prompt_tokens,
                            display_completions_in_columns=multicolumn,
                            style=self.shell.style
        )
        self.pt_cli = CommandLineInterface(self._pt_app, eventloop=self.shell._eventloop) 
开发者ID:thomasyimgit,项目名称:leetcode,代码行数:43,代码来源:debugger.py

示例10: _on_cli_initialize

# 需要导入模块: from prompt_toolkit import interface [as 别名]
# 或者: from prompt_toolkit.interface import CommandLineInterface [as 别名]
def _on_cli_initialize(self, cli):
        """
        Called when a CommandLineInterface has been created.
        """
        def synchronize(_=None):
            if self.vi_mode:
                cli.editing_mode = EditingMode.VI
            else:
                cli.editing_mode = EditingMode.EMACS

        cli.input_processor.beforeKeyPress += synchronize
        cli.input_processor.afterKeyPress += synchronize
        synchronize() 
开发者ID:jonathanslenders,项目名称:pypager,代码行数:15,代码来源:pager.py

示例11: run

# 需要导入模块: from prompt_toolkit import interface [as 别名]
# 或者: from prompt_toolkit.interface import CommandLineInterface [as 别名]
def run(self):
        """
        Create an event loop for the application and run it.
        """
        self.eventloop = create_eventloop()

        try:
            self.cli = CommandLineInterface(
                application=self.application,
                eventloop=self.eventloop,
                input=StdinInput(sys.stdout))

            # Hide message when a key is pressed.
            def key_pressed(_):
                self.message = None
            self.cli.input_processor.beforeKeyPress += key_pressed

            def pre_run():
                # Set search highlighting.
                if self.search_text:
                    self.cli.search_state.text = self.search_text

            with self.cli.patch_stdout_context():
                self.cli.run(reset_current_buffer=False, pre_run=pre_run)
        finally:
            # Close eventloop.
            self.eventloop.close()
            self.eventloop = None

            # XXX: Close all sources which are opened by the pager itself. 
开发者ID:jonathanslenders,项目名称:pypager,代码行数:32,代码来源:pager.py

示例12: example_repl

# 需要导入模块: from prompt_toolkit import interface [as 别名]
# 或者: from prompt_toolkit.interface import CommandLineInterface [as 别名]
def example_repl(self, text, example, start_index, continue_flag):
        """ REPL for interactive tutorials """

        if start_index:
            start_index = start_index + 1
            cmd = ' '.join(text.split()[:start_index])
            example_cli = CommandLineInterface(
                application=self.create_application(
                    full_layout=False),
                eventloop=create_eventloop())
            example_cli.buffers['example_line'].reset(
                initial_document=Document(u'{}\n'.format(
                    add_new_lines(example)))
            )
            while start_index < len(text.split()):
                if self.default_command:
                    cmd = cmd.replace(self.default_command + ' ', '')
                example_cli.buffers[DEFAULT_BUFFER].reset(
                    initial_document=Document(
                        u'{}'.format(cmd),
                        cursor_position=len(cmd)))
                example_cli.request_redraw()
                answer = example_cli.run()
                if not answer:
                    return "", True
                answer = answer.text
                if answer.strip('\n') == cmd.strip('\n'):
                    continue
                else:
                    if len(answer.split()) > 1:
                        start_index += 1
                        cmd += " " + answer.split()[-1] + " " +\
                               u' '.join(text.split()[start_index:start_index + 1])
            example_cli.exit()
            del example_cli
        else:
            cmd = text

        return cmd, continue_flag

    # pylint: disable=too-many-branches 
开发者ID:Azure,项目名称:azure-cli,代码行数:43,代码来源:app.py

示例13: pt_init

# 需要导入模块: from prompt_toolkit import interface [as 别名]
# 或者: from prompt_toolkit.interface import CommandLineInterface [as 别名]
def pt_init(self):
        def get_prompt_tokens(cli):
            return [(Token.Prompt, self.prompt)]

        def patch_stdout(**kwargs):
            return self.pt_cli.patch_stdout_context(**kwargs)

        if self._ptcomp is None:
            compl = IPCompleter(shell=self.shell,
                                        namespace={},
                                        global_namespace={},
                                        use_readline=False,
                                        parent=self.shell,
                                       )
            self._ptcomp = IPythonPTCompleter(compl, patch_stdout=patch_stdout)

        kbmanager = KeyBindingManager.for_prompt()
        supports_suspend = Condition(lambda cli: hasattr(signal, 'SIGTSTP'))
        kbmanager.registry.add_binding(Keys.ControlZ, filter=supports_suspend
                                      )(suspend_to_bg)

        if self.shell.display_completions == 'readlinelike':
            kbmanager.registry.add_binding(Keys.ControlI,
                                 filter=(HasFocus(DEFAULT_BUFFER)
                                         & ~HasSelection()
                                         & ViInsertMode() | EmacsInsertMode()
                                         & ~cursor_in_leading_ws
                                         ))(display_completions_like_readline)
        multicolumn = (self.shell.display_completions == 'multicolumn')

        self._pt_app = create_prompt_application(
                            editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()),
                            key_bindings_registry=kbmanager.registry,
                            history=self.shell.debugger_history,
                            completer= self._ptcomp,
                            enable_history_search=True,
                            mouse_support=self.shell.mouse_support,
                            get_prompt_tokens=get_prompt_tokens,
                            display_completions_in_columns=multicolumn,
        )
        self.pt_cli = CommandLineInterface(self._pt_app, eventloop=self.shell._eventloop) 
开发者ID:Desgard,项目名称:Repobot,代码行数:43,代码来源:debugger.py

示例14: run

# 需要导入模块: from prompt_toolkit import interface [as 别名]
# 或者: from prompt_toolkit.interface import CommandLineInterface [as 别名]
def run(app):
    eventloop = shortcuts.create_eventloop()

    try:
        cli = interface.CommandLineInterface(application=app,
                                             eventloop=eventloop)
        cli.run(reset_current_buffer=False)
    finally:
        eventloop.close() 
开发者ID:yittg,项目名称:Snipping,代码行数:11,代码来源:__init__.py

示例15: set_application

# 需要导入模块: from prompt_toolkit import interface [as 别名]
# 或者: from prompt_toolkit.interface import CommandLineInterface [as 别名]
def set_application(self, app, callback=None):
        """
        Set ``CommandLineInterface`` instance for this connection.
        (This can be replaced any time.)

        :param cli: CommandLineInterface instance.
        :param callback: Callable that takes the result of the CLI.
        """
        assert isinstance(app, Application)
        assert callback is None or callable(callback)

        self.cli = CommandLineInterface(
            application=app,
            eventloop=self.eventloop,
            output=self.vt100_output)
        self.callback = callback

        # Create a parser, and parser callbacks.
        cb = self.cli.create_eventloop_callbacks()
        inputstream = InputStream(cb.feed_key)

        # Input decoder for stdin. (Required when working with multibyte
        # characters, like chinese input.)
        stdin_decoder_cls = getincrementaldecoder(self.encoding)
        stdin_decoder = [stdin_decoder_cls()]  # nonlocal

        # Tell the CLI that it's running. We don't start it through the run()
        # call, but will still want _redraw() to work.
        self.cli._is_running = True

        def data_received(data):
            """ TelnetProtocolParser 'data_received' callback """
            assert isinstance(data, binary_type)

            try:
                result = stdin_decoder[0].decode(data)
                inputstream.feed(result)
            except UnicodeDecodeError:
                stdin_decoder[0] = stdin_decoder_cls()
                return ''

        def size_received(rows, columns):
            """ TelnetProtocolParser 'size_received' callback """
            self.size = Size(rows=rows, columns=columns)
            cb.terminal_size_changed()

        self.parser = TelnetProtocolParser(data_received, size_received) 
开发者ID:chrisjim316,项目名称:Liljimbo-Chatbot,代码行数:49,代码来源:server.py


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