當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。