Python prompt_toolkit.layout.controls.FormattedTextControl() Examples

The following are 10 code examples of prompt_toolkit.layout.controls.FormattedTextControl(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module prompt_toolkit.layout.controls , or try the search function .
Example #1
Source File: layout.py    From ptpython with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def python_sidebar_navigation(python_input):
    """
    Create the `Layout` showing the navigation information for the sidebar.
    """

    def get_text_fragments():
        # Show navigation info.
        return [
            ("class:sidebar", "    "),
            ("class:sidebar.key", "[Arrows]"),
            ("class:sidebar", " "),
            ("class:sidebar.description", "Navigate"),
            ("class:sidebar", " "),
            ("class:sidebar.key", "[Enter]"),
            ("class:sidebar", " "),
            ("class:sidebar.description", "Hide menu"),
        ]

    return Window(
        FormattedTextControl(get_text_fragments),
        style="class:sidebar",
        width=Dimension.exact(43),
        height=Dimension.exact(1),
    ) 
Example #2
Source File: layout.py    From ptpython with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def exit_confirmation(
    python_input: "PythonInput", style="class:exit-confirmation"
) -> Container:
    """
    Create `Layout` for the exit message.
    """

    def get_text_fragments() -> StyleAndTextTuples:
        # Show "Do you really want to exit?"
        return [
            (style, "\n %s ([y]/n)" % python_input.exit_message),
            ("[SetCursorPosition]", ""),
            (style, "  \n"),
        ]

    visible = ~is_done & Condition(lambda: python_input.show_exit_confirmation)

    return ConditionalContainer(
        content=Window(
            FormattedTextControl(get_text_fragments), style=style
        ),  # , has_focus=visible)),
        filter=visible,
    ) 
Example #3
Source File: layout.py    From pymux with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def __init__(self, pymux, client_state):
        self.pymux = pymux
        self.client_state = client_state

        # Popup dialog for displaying keys, etc...
        search_textarea = SearchToolbar()
        self._popup_textarea = TextArea(scrollbar=True, read_only=True, search_field=search_textarea)
        self.popup_dialog = Dialog(
            title='Keys',
            body=HSplit([
                Window(FormattedTextControl(text=''), height=1),  # 1 line margin.
                self._popup_textarea,
                search_textarea,
                Window(
                    FormattedTextControl(
                        text=HTML('Press [<b>q</b>] to quit or [<b>/</b>] for searching.')),
                    align=WindowAlign.CENTER,
                    height=1)
                ])
            )

        self.layout = self._create_layout()

        # Keep track of render information.
        self.pane_write_positions = {} 
Example #4
Source File: layout.py    From pyvim with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def __init__(self, editor):
        once_hidden = [False]  # Nonlocal

        def condition():
            # Get editor buffers
            buffers = editor.window_arrangement.editor_buffers

            # Only show when there is only one empty buffer, but once the
            # welcome message has been hidden, don't show it again.
            result = (len(buffers) == 1 and buffers[0].buffer.text == '' and
                      buffers[0].location is None and not once_hidden[0])
            if not result:
                once_hidden[0] = True
            return result

        super(WelcomeMessageWindow, self).__init__(
            Window(
                FormattedTextControl(lambda: WELCOME_MESSAGE_TOKENS),
                align=WindowAlign.CENTER,
                style="class:welcome"),
            filter=Condition(condition)) 
Example #5
Source File: layout.py    From ptpython with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def python_sidebar_help(python_input):
    """
    Create the `Layout` for the help text for the current item in the sidebar.
    """
    token = "class:sidebar.helptext"

    def get_current_description():
        """
        Return the description of the selected option.
        """
        i = 0
        for category in python_input.options:
            for option in category.options:
                if i == python_input.selected_option_index:
                    return option.description
                i += 1
        return ""

    def get_help_text():
        return [(token, get_current_description())]

    return ConditionalContainer(
        content=Window(
            FormattedTextControl(get_help_text), style=token, height=Dimension(min=3)
        ),
        filter=ShowSidebar(python_input)
        & Condition(lambda: python_input.show_sidebar_help)
        & ~is_done,
    ) 
Example #6
Source File: layout.py    From ptpython with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def meta_enter_message(python_input: "PythonInput") -> Container:
    """
    Create the `Layout` for the 'Meta+Enter` message.
    """

    def get_text_fragments() -> StyleAndTextTuples:
        return [("class:accept-message", " [Meta+Enter] Execute ")]

    @Condition
    def extra_condition() -> bool:
        " Only show when... "
        b = python_input.default_buffer

        return (
            python_input.show_meta_enter_message
            and (
                not b.document.is_cursor_at_the_end
                or python_input.accept_input_on_enter is None
            )
            and "\n" in b.text
        )

    visible = ~is_done & has_focus(DEFAULT_BUFFER) & extra_condition

    return ConditionalContainer(
        content=Window(FormattedTextControl(get_text_fragments)), filter=visible
    ) 
Example #7
Source File: layout.py    From pyvim with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, editor, buffer_window, buffer):
        def get_scroll_text():
            info = buffer_window.render_info

            if info:
                if info.full_height_visible:
                    return 'All'
                elif info.top_visible:
                    return 'Top'
                elif info.bottom_visible:
                    return 'Bot'
                else:
                    percentage = info.vertical_scroll_percentage
                    return '%2i%%' % percentage

            return ''

        def get_tokens():
            main_document = buffer.document

            return [
                ('class:cursorposition', '(%i,%i)' % (main_document.cursor_position_row + 1,
                                                      main_document.cursor_position_col + 1)),
                ('', ' - '),
                ('class:percentage', get_scroll_text()),
                ('', ' '),
            ]

        super(WindowStatusBarRuler, self).__init__(
            Window(
                FormattedTextControl(get_tokens),
                char=' ',
                align=WindowAlign.RIGHT,
                style='class:toolbar.status',
                height=1,
            ),
            filter=Condition(lambda: editor.show_ruler)) 
Example #8
Source File: layout.py    From pyvim with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self):
        def get_tokens():
            arg = get_app().key_processor.arg
            if arg is not None:
                return [('class:arg', ' %s ' % arg)]
            else:
                return []

        super(SimpleArgToolbar, self).__init__(
            Window(FormattedTextControl(get_tokens), align=WindowAlign.RIGHT),
            filter=has_arg), 
Example #9
Source File: layout.py    From hummingbot with Apache License 2.0 5 votes vote down vote up
def generate_layout(input_field: TextArea,
                    output_field: TextArea,
                    log_field: TextArea,
                    search_field: SearchToolbar):
    root_container = HSplit([
        VSplit([
            Window(FormattedTextControl(get_version), style="class:title"),
            Window(FormattedTextControl(get_paper_trade_status), style="class:title"),
            Window(FormattedTextControl(get_title_bar_right_text), align=WindowAlign.RIGHT, style="class:title"),
        ], height=1),
        VSplit([
            FloatContainer(
                HSplit([
                    output_field,
                    Window(height=1, char='-', style='class:primary'),
                    input_field,
                ]),
                [
                    # Completion menus.
                    Float(xcursor=True,
                          ycursor=True,
                          transparent=True,
                          content=CompletionsMenu(
                              max_height=16,
                              scroll_offset=1)),
                ]
            ),
            Window(width=1, char='|', style='class:primary'),
            HSplit([
                log_field,
                search_field,
            ]),
        ]),

    ])
    return Layout(root_container, focused_element=input_field) 
Example #10
Source File: layout.py    From ptpython with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def show_sidebar_button_info(python_input: "PythonInput") -> Container:
    """
    Create `Layout` for the information in the right-bottom corner.
    (The right part of the status bar.)
    """

    @if_mousedown
    def toggle_sidebar(mouse_event: MouseEvent) -> None:
        " Click handler for the menu. "
        python_input.show_sidebar = not python_input.show_sidebar

    version = sys.version_info
    tokens: StyleAndTextTuples = [
        ("class:status-toolbar.key", "[F2]", toggle_sidebar),
        ("class:status-toolbar", " Menu", toggle_sidebar),
        ("class:status-toolbar", " - "),
        (
            "class:status-toolbar.python-version",
            "%s %i.%i.%i"
            % (platform.python_implementation(), version[0], version[1], version[2]),
        ),
        ("class:status-toolbar", " "),
    ]
    width = fragment_list_width(tokens)

    def get_text_fragments() -> StyleAndTextTuples:
        # Python version
        return tokens

    return ConditionalContainer(
        content=Window(
            FormattedTextControl(get_text_fragments),
            style="class:status-toolbar",
            height=Dimension.exact(1),
            width=Dimension.exact(width),
        ),
        filter=~is_done
        & renderer_height_is_known
        & Condition(
            lambda: python_input.show_status_bar
            and not python_input.show_exit_confirmation
        ),
    )