def create_content(self, width, height):
        complete_state = get_app().current_buffer.complete_state
        if complete_state:
            completions = complete_state.completions
            index = complete_state.complete_index  # Can be None!

            # Width of the completions without the left/right arrows in the margins.
            content_width = width - 6

            # Booleans indicating whether we stripped from the left/right
            cut_left = False
            cut_right = False

            # Create Menu content.
            fragments = []

            for i, c in enumerate(completions):
                # When there is no more place for the next completion
                if fragment_list_len(fragments) + len(
                        c.display_text) >= content_width:
                    # If the current one was not yet displayed, page to the next sequence.
                    if i <= (index or 0):
                        fragments = []
                        cut_left = True
                    # If the current one is visible, stop here.
                    else:
                        cut_right = True
                        break

                fragments.extend(
                    to_formatted_text(
                        c.display_text,
                        style=('class:completion-toolbar.completion.current'
                               if i == index else
                               'class:completion-toolbar.completion')))
                fragments.append(('', ' '))

            # Extend/strip until the content width.
            fragments.append(
                ('', ' ' * (content_width - fragment_list_len(fragments))))
            fragments = fragments[:content_width]

            # Return fragments
            all_fragments = [
                ('', ' '),
                ('class:completion-toolbar.arrow', '<' if cut_left else ' '),
                ('', ' '),
            ] + fragments + [
                ('', ' '),
                ('class:completion-toolbar.arrow', '>' if cut_right else ' '),
                ('', ' '),
            ]
        else:
            all_fragments = []

        def get_line(i):
            return all_fragments

        return UIContent(get_line=get_line, line_count=1)
    def create_content(self, width, height):
        complete_state = get_app().current_buffer.complete_state
        if complete_state:
            completions = complete_state.completions
            index = complete_state.complete_index  # Can be None!

            # Width of the completions without the left/right arrows in the margins.
            content_width = width - 6

            # Booleans indicating whether we stripped from the left/right
            cut_left = False
            cut_right = False

            # Create Menu content.
            fragments = []

            for i, c in enumerate(completions):
                # When there is no more place for the next completion
                if fragment_list_len(fragments) + len(c.display_text) >= content_width:
                    # If the current one was not yet displayed, page to the next sequence.
                    if i <= (index or 0):
                        fragments = []
                        cut_left = True
                    # If the current one is visible, stop here.
                    else:
                        cut_right = True
                        break

                fragments.extend(to_formatted_text(
                    c.display_text,
                    style=('class:completion-toolbar.completion.current'
                           if i == index else 'class:completion-toolbar.completion')
                ))
                fragments.append(('', ' '))

            # Extend/strip until the content width.
            fragments.append(('', ' ' * (content_width - fragment_list_len(fragments))))
            fragments = fragments[:content_width]

            # Return fragments
            all_fragments = [
                ('', ' '),
                ('class:completion-toolbar.arrow', '<' if cut_left else ' '),
                ('', ' '),
            ] + fragments + [
                ('', ' '),
                ('class:completion-toolbar.arrow', '>' if cut_right else ' '),
                ('', ' '),
            ]
        else:
            all_fragments = []

        def get_line(i):
            return all_fragments

        return UIContent(get_line=get_line, line_count=1)
Beispiel #3
0
def with_gutter(lines, start_line_idx: int, focus_line_idx: int,
                secondary_focus_idx: int):
    start_line_num = start_line_idx + 1
    updated_lines = []
    gutter_padding = 5  # Not ideal manually maintaining this
    term_width = get_terminal_size().cols
    for i, line in enumerate(lines):
        max_line_number_width = len(str(start_line_num + len(lines)))
        g_width = max_line_number_width + gutter_padding
        rpad_amount = term_width - g_width - fragment_list_len(line)
        line = line + [formatted_padding(rpad_amount)]
        if i == focus_line_idx:
            bg = "bg:#313131 bold"
            gutter_fg = "greenyellow"
        elif i == secondary_focus_idx and focus_line_idx != secondary_focus_idx:
            bg = "bg:#313131 bold"
            gutter_fg = "coral"
        else:
            bg = None
            gutter_fg = "slategray"

        gutter_tokens = to_formatted_text(
            HTML(
                f"<span fg='{gutter_fg}'> {start_line_num + i:>{max_line_number_width}}  </span>  "
            ))
        line = to_formatted_text(line)
        full_line = to_formatted_text(gutter_tokens + line, style=bg)
        updated_lines.append(full_line)

    return updated_lines
Beispiel #4
0
    def apply_transformation(self, ti):
        len_frag = fragment_list_len(ti.fragments)
        if len_frag >= 2:
            fragments_before = to_formatted_text(ti.fragments[0][1][:2],
                                                 self.style)

            fragments = fragments_before
            fragments += [(ti.fragments[0][0], ti.fragments[0][1][2:])]
            fragments += ti.fragments[1:]
        else:
            fragments = ti.fragments

        source_to_display = lambda i: i
        display_to_source = lambda i: i

        return Transformation(fragments,
                              source_to_display=source_to_display,
                              display_to_source=display_to_source)