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) >= 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.append( ('class:completion-toolbar.completion.current' if i == index else 'class:completion-toolbar.completion', c.display)) 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 apply_transformation(self, ti): main_control = self._get_main_buffer(ti.buffer_control) if ti.lineno == 0 and main_control: content = self._content(main_control, ti) # Get the line from the original document for this search. line_fragments = content.get_line(content.cursor_position.y) if main_control.search_state.direction == SearchDirection.FORWARD: direction_text = 'i-search' else: direction_text = 'reverse-i-search' fragments_before = [ ('class:prompt.search', '('), ('class:prompt.search', direction_text), ('class:prompt.search', ')`'), ] fragments = fragments_before + [ ('class:prompt.search.text', fragment_list_to_text(ti.fragments)), ('', "': "), ] + line_fragments shift_position = fragment_list_len(fragments_before) source_to_display = lambda i: i + shift_position display_to_source = lambda i: i - shift_position else: source_to_display = None display_to_source = None fragments = ti.fragments return Transformation(fragments, source_to_display=source_to_display, display_to_source=display_to_source)
def apply_transformation(self, ti: TransformationInput) -> Transformation: from .controls import SearchBufferControl assert isinstance( ti.buffer_control, SearchBufferControl ), "`ReverseSearchProcessor` should be applied to a `SearchBufferControl` only." source_to_display: Optional[SourceToDisplay] display_to_source: Optional[DisplayToSource] main_control = self._get_main_buffer(ti.buffer_control) if ti.lineno == 0 and main_control: content = self._content(main_control, ti) # Get the line from the original document for this search. line_fragments = content.get_line(content.cursor_position.y) if main_control.search_state.direction == SearchDirection.FORWARD: direction_text = "i-search" else: direction_text = "reverse-i-search" fragments_before: StyleAndTextTuples = [ ("class:prompt.search", "("), ("class:prompt.search", direction_text), ("class:prompt.search", ")`"), ] fragments = ( fragments_before + [ ("class:prompt.search.text", fragment_list_to_text(ti.fragments)), ("", "': "), ] + line_fragments ) shift_position = fragment_list_len(fragments_before) source_to_display = lambda i: i + shift_position display_to_source = lambda i: i - shift_position else: source_to_display = None display_to_source = None fragments = ti.fragments return Transformation( fragments, source_to_display=source_to_display, display_to_source=display_to_source, )
def apply_transformation(self, ti): if ti.lineno == 0: # Get fragments. fragments_before = to_formatted_text(self.text, self.style) fragments = fragments_before + ti.fragments shift_position = fragment_list_len(fragments_before) source_to_display = lambda i: i + shift_position display_to_source = lambda i: i - shift_position else: fragments = ti.fragments source_to_display = None display_to_source = None return Transformation(fragments, source_to_display=source_to_display, display_to_source=display_to_source)
def apply_transformation(self, ti: TransformationInput) -> Transformation: source_to_display: Optional[SourceToDisplay] display_to_source: Optional[DisplayToSource] if ti.lineno == 0: # Get fragments. fragments_before = to_formatted_text(self.text, self.style) fragments = fragments_before + ti.fragments shift_position = fragment_list_len(fragments_before) source_to_display = lambda i: i + shift_position display_to_source = lambda i: i - shift_position else: fragments = ti.fragments source_to_display = None display_to_source = None return Transformation(fragments, source_to_display=source_to_display, display_to_source=display_to_source)
def apply_transformation(self, ti: TransformationInput) -> Transformation: from .controls import SearchBufferControl assert isinstance(ti.buffer_control, SearchBufferControl), \ '`ReverseSearchProcessor` should be applied to a `SearchBufferControl` only.' source_to_display: Optional[SourceToDisplay] display_to_source: Optional[DisplayToSource] main_control = self._get_main_buffer(ti.buffer_control) if ti.lineno == 0 and main_control: content = self._content(main_control, ti) # Get the line from the original document for this search. line_fragments = content.get_line(content.cursor_position.y) if main_control.search_state.direction == SearchDirection.FORWARD: direction_text = 'i-search' else: direction_text = 'reverse-i-search' fragments_before: StyleAndTextTuples = [ ('class:prompt.search', '('), ('class:prompt.search', direction_text), ('class:prompt.search', ')`'), ] fragments = fragments_before + [ ('class:prompt.search.text', fragment_list_to_text(ti.fragments)), ('', "': "), ] + line_fragments shift_position = fragment_list_len(fragments_before) source_to_display = lambda i: i + shift_position display_to_source = lambda i: i - shift_position else: source_to_display = None display_to_source = None fragments = ti.fragments return Transformation(fragments, source_to_display=source_to_display, display_to_source=display_to_source)
def apply_transformation(self, ti: TransformationInput) -> Transformation: source_to_display: Optional[SourceToDisplay] display_to_source: Optional[DisplayToSource] if ti.lineno == 0: # Get fragments. fragments_before = to_formatted_text(self.text, self.style) fragments = fragments_before + ti.fragments shift_position = fragment_list_len(fragments_before) source_to_display = lambda i: i + shift_position display_to_source = lambda i: i - shift_position else: fragments = ti.fragments source_to_display = None display_to_source = None return Transformation( fragments, source_to_display=source_to_display, display_to_source=display_to_source, )