Beispiel #1
0
    def _content(self, main_control: "BufferControl",
                 ti: TransformationInput) -> "UIContent":
        from prompt_toolkit.layout.controls import BufferControl

        # Emulate the BufferControl through which we are searching.
        # For this we filter out some of the input processors.
        excluded_processors = tuple(self._excluded_input_processors)

        def filter_processor(item: Processor) -> Optional[Processor]:
            """Filter processors from the main control that we want to disable
            here. This returns either an accepted processor or None."""
            # For a `_MergedProcessor`, check each individual processor, recursively.
            if isinstance(item, _MergedProcessor):
                accepted_processors = [
                    filter_processor(p) for p in item.processors
                ]
                return merge_processors(
                    [p for p in accepted_processors if p is not None])

            # For a `ConditionalProcessor`, check the body.
            elif isinstance(item, ConditionalProcessor):
                p = filter_processor(item.processor)
                if p:
                    return ConditionalProcessor(p, item.filter)

            # Otherwise, check the processor itself.
            else:
                if not isinstance(item, excluded_processors):
                    return item

            return None

        filtered_processor = filter_processor(
            merge_processors(main_control.input_processors or []))
        highlight_processor = HighlightIncrementalSearchProcessor()

        if filtered_processor:
            new_processors = [filtered_processor, highlight_processor]
        else:
            new_processors = [highlight_processor]

        from .controls import SearchBufferControl

        assert isinstance(ti.buffer_control, SearchBufferControl)

        buffer_control = BufferControl(
            buffer=main_control.buffer,
            input_processors=new_processors,
            include_default_input_processors=False,
            lexer=main_control.lexer,
            preview_search=True,
            search_buffer_control=cast(SearchBufferControl, ti.buffer_control),
        )

        return buffer_control.create_content(ti.width,
                                             ti.height,
                                             preview_search=True)
Beispiel #2
0
    def _content(self, main_control, ti):
        from prompt_toolkit.layout.controls import BufferControl

        # Emulate the BufferControl through which we are searching.
        # For this we filter out some of the input processors.
        excluded_processors = tuple(self._excluded_input_processors)

        def filter_processor(item):
            """ Filter processors from the main control that we want to disable
            here. This returns either an accepted processor or None. """
            # For a `_MergedProcessor`, check each individual processor, recursively.
            if isinstance(item, _MergedProcessor):
                accepted_processors = [
                    filter_processor(p) for p in item.processors
                ]
                accepted_processors = [
                    p for p in accepted_processors if p is not None
                ]

                if len(accepted_processors) > 1:
                    return _MergedProcessor(accepted_processors)
                elif accepted_processors == 1:
                    return accepted_processors[0]

            # For a `ConditionalProcessor`, check the body.
            elif isinstance(item, ConditionalProcessor):
                p = filter_processor(item.processor)
                if p:
                    return ConditionalProcessor(p, item.filter)

            # Otherwise, check the processor itself.
            else:
                if not isinstance(item, excluded_processors):
                    return item

        filtered_processor = filter_processor(main_control.input_processor)
        highlight_processor = HighlightSearchProcessor(preview_search=True)

        if filtered_processor:
            new_processor = _MergedProcessor(
                [filtered_processor, highlight_processor])
        else:
            new_processor = highlight_processor

        buffer_control = BufferControl(buffer=main_control.buffer,
                                       input_processor=new_processor,
                                       lexer=main_control.lexer,
                                       preview_search=True,
                                       search_buffer_control=ti.buffer_control)

        return buffer_control.create_content(ti.width, ti.height)
    def _content(self, main_control: 'BufferControl', ti: TransformationInput) -> 'UIContent':
        from prompt_toolkit.layout.controls import BufferControl

        # Emulate the BufferControl through which we are searching.
        # For this we filter out some of the input processors.
        excluded_processors = tuple(self._excluded_input_processors)

        def filter_processor(item: Processor) -> Optional[Processor]:
            """ Filter processors from the main control that we want to disable
            here. This returns either an accepted processor or None. """
            # For a `_MergedProcessor`, check each individual processor, recursively.
            if isinstance(item, _MergedProcessor):
                accepted_processors = [filter_processor(p) for p in item.processors]
                return merge_processors(
                    [p for p in accepted_processors if p is not None])

            # For a `ConditionalProcessor`, check the body.
            elif isinstance(item, ConditionalProcessor):
                p = filter_processor(item.processor)
                if p:
                    return ConditionalProcessor(p, item.filter)

            # Otherwise, check the processor itself.
            else:
                if not isinstance(item, excluded_processors):
                    return item

            return None

        filtered_processor = filter_processor(
            merge_processors(main_control.input_processors or []))
        highlight_processor = HighlightIncrementalSearchProcessor()

        if filtered_processor:
            new_processors = [filtered_processor, highlight_processor]
        else:
            new_processors = [highlight_processor]

        from .controls import SearchBufferControl
        assert isinstance(ti.buffer_control, SearchBufferControl)

        buffer_control = BufferControl(
             buffer=main_control.buffer,
             input_processors=new_processors,
             include_default_input_processors=False,
             lexer=main_control.lexer,
             preview_search=True,
             search_buffer_control=cast(SearchBufferControl, ti.buffer_control))

        return buffer_control.create_content(ti.width, ti.height, preview_search=True)