def _CreatePromptApplication(self, config, multiline):
        """Creates a shell prompt Application."""

        return pt_application.Application(
            layout=layout.CreatePromptLayout(
                config=config,
                extra_input_processors=[Context()],
                get_bottom_status_tokens=self._GetBottomStatusTokens,
                get_bottom_toolbar_tokens=self._GetBottomToolbarTokens,
                get_continuation_tokens=None,
                get_prompt_tokens=None,
                is_password=False,
                lexer=None,
                multiline=filters.Condition(lambda cli: multiline()),
                show_help=filters.Condition(
                    lambda _: self.key_bindings.help_key.toggle),
                wrap_lines=True,
            ),
            buffer=self.default_buffer,
            clipboard=None,
            erase_when_done=False,
            get_title=None,
            key_bindings_registry=self.key_bindings.MakeRegistry(),
            mouse_support=False,
            reverse_vi_search_direction=True,
            style=shell_style.GetDocumentStyle(),
        )
Пример #2
0
def Prompt(history):
    """Show the shell prompt to the user."""
    app = CreatePromptApplication(
        'gcloud> ',
        get_bottom_toolbar_tokens=GetBottomToolbarTokens,
        style=shell_style.GetDocumentStyle(),
        key_bindings_registry=CreateKeyBindingRegistry(),
        get_help_tokens=GetHelpTokens,
        completer=shell_completer.ShellCliCompleter(),
        history=history)

    return RunApplication(app)
Пример #3
0
    def _CreatePromptApplication(self):
        """Creates a shell prompt Application."""

        # Make sure that complete_while_typing is disabled when
        # enable_history_search is enabled. (First convert to SimpleFilter, to
        # avoid doing bitwise operations on bool objects.)
        complete_while_typing = shortcuts.to_simple_filter(True)
        enable_history_search = shortcuts.to_simple_filter(False)
        multiline = shortcuts.to_simple_filter(False)

        complete_while_typing &= ~enable_history_search

        return application.Application(
            layout=layout.CreatePromptLayout(
                message=self.prompt,
                lexer=None,
                is_password=False,
                reserve_space_for_menu=self.MENU_RESERVE_SPACE,
                multiline=filters.Condition(lambda cli: multiline()),
                get_prompt_tokens=None,
                get_continuation_tokens=None,
                get_bottom_toolbar_tokens=self._GetBottomToolbarTokens,
                display_completions_in_columns=False,
                extra_input_processors=None,
                wrap_lines=True,
                show_help=filters.Condition(
                    lambda _: self.key_bindings.help_key.toggle)),
            buffer=pt_buffer.Buffer(
                enable_history_search=enable_history_search,
                complete_while_typing=complete_while_typing,
                is_multiline=multiline,
                history=pt_history.InMemoryHistory(),
                validator=None,
                completer=shell_completer.ShellCliCompleter(),
                auto_suggest=None,
                accept_action=pt_buffer.AcceptAction.RETURN_DOCUMENT,
                initial_document=document.Document(''),
            ),
            style=shell_style.GetDocumentStyle(),
            clipboard=None,
            key_bindings_registry=self.key_bindings.MakeRegistry(),
            get_title=None,
            mouse_support=False,
            erase_when_done=False,
            on_abort=application.AbortAction.RAISE_EXCEPTION,
            on_exit=application.AbortAction.RAISE_EXCEPTION)