a
    lcV                     @   sj  d Z ddlZddlmZmZ ddlmZmZmZm	Z	m
Z
mZmZmZmZ ddlmZ ddlmZ ddlmZ ddlmZmZmZ dd	lmZmZmZ dd
lmZmZ ddl m!Z! ddl"m#Z#m$Z$ ddl%m&Z& erddl'm(Z(m)Z) g dZ*G dd dedZ+ee,ge,f Z-ee,ge,f Z.G dd dZ/G dd dZ0G dd de+Z1G dd de+Z2G dd de2Z3G dd de+Z4G d d! d!e+Z5G d"d# d#e+Z6G d$d% d%e+Z7G d&d' d'e+Z8G d(d) d)e8Z9G d*d+ d+e+Z:G d,d- d-e+Z;G d.d/ d/e+Z<G d0d1 d1e+Z=G d2d3 d3e+Z>G d4d5 d5e+Z?G d6d7 d7e+Z@G d8d9 d9e+ZAe	e+ e+d:d;d<ZBG d=d> d>e+ZCdS )?z
Processors are little transformation blocks that transform the fragments list
from a buffer before the BufferControl will render it to the screen.

They can insert fragments before or after, or highlight fragments by replacing the
fragment types.
    N)ABCMetaabstractmethod)	TYPE_CHECKINGCallableHashableListOptionalTupleTypeUnioncast)get_app)SimpleCache)Document)FilterOrBool	to_filtervi_insert_multiple_mode)AnyFormattedTextStyleAndTextTuplesto_formatted_text)fragment_list_lenfragment_list_to_text)SearchDirection)to_intto_str   )explode_text_fragments)BufferControl	UIContent)	ProcessorTransformationInputTransformationDummyProcessorHighlightSearchProcessor#HighlightIncrementalSearchProcessorHighlightSelectionProcessorPasswordProcessor!HighlightMatchingBracketProcessorDisplayMultipleCursorsBeforeInputShowArg
AfterInputAppendAutoSuggestionConditionalProcessorShowLeadingWhiteSpaceProcessorShowTrailingWhiteSpaceProcessorTabsProcessorReverseSearchProcessorDynamicProcessormerge_processorsc                   @   s$   e Zd ZdZedddddZdS )r   zt
    Manipulate the fragments for a given line in a
    :class:`~prompt_toolkit.layout.controls.BufferControl`.
    r    r!   transformation_inputreturnc                 C   s
   t |jS )z
        Apply transformation. Returns a :class:`.Transformation` instance.

        :param transformation_input: :class:`.TransformationInput` object.
        r!   	fragmentsselfr5    r;   \/var/www/html/django/DPS/env/lib/python3.9/site-packages/prompt_toolkit/layout/processors.pyapply_transformationG   s    	zProcessor.apply_transformationN)__name__
__module____qualname____doc__r   r=   r;   r;   r;   r<   r   A   s
   r   )	metaclassc                	   @   sL   e Zd ZdZdeeeeeeddddZe	deeeeeef ddd	Z
dS )
r    a  
    :param buffer_control: :class:`.BufferControl` instance.
    :param lineno: The number of the line to which we apply the processor.
    :param source_to_display: A function that returns the position in the
        `fragments` for any position in the source string. (This takes
        previous processors into account.)
    :param fragments: List of fragments that we can transform. (Received from the
        previous processor.)
    r   N)buffer_controldocumentlinenosource_to_displayr8   widthheightr6   c                 C   s.   || _ || _|| _|| _|| _|| _|| _d S NrC   rD   rE   rF   r8   rG   rH   )r:   rC   rD   rE   rF   r8   rG   rH   r;   r;   r<   __init__b   s    zTransformationInput.__init__r6   c                 C   s    | j | j| j| j| j| j| jfS rI   rJ   r:   r;   r;   r<   unpacku   s    zTransformationInput.unpack)r>   r?   r@   rA   r   intSourceToDisplayr   rK   r	   rN   r;   r;   r;   r<   r    W   s   r    c                   @   s.   e Zd ZdZdeee ee ddddZdS )r!   a)  
    Transformation result, as returned by :meth:`.Processor.apply_transformation`.

    Important: Always make sure that the length of `document.text` is equal to
               the length of all the text in `fragments`!

    :param fragments: The transformed fragments. To be displayed, or to pass to
        the next processor.
    :param source_to_display: Cursor position transformation from original
        string to transformed string.
    :param display_to_source: Cursor position transformed from source string to
        original string.
    N)r8   rF   display_to_sourcer6   c                 C   s&   || _ |pdd | _|pdd | _d S )Nc                 S   s   | S rI   r;   ir;   r;   r<   <lambda>       z)Transformation.__init__.<locals>.<lambda>c                 S   s   | S rI   r;   rR   r;   r;   r<   rT      rU   )r8   rF   rQ   )r:   r8   rF   rQ   r;   r;   r<   rK      s    zTransformation.__init__)NN)	r>   r?   r@   rA   r   r   rP   DisplayToSourcerK   r;   r;   r;   r<   r!      s     r!   c                   @   s    e Zd ZdZeedddZdS )r"   z1
    A `Processor` that doesn't do anything.
    r4   c                 C   s
   t |jS rI   r7   r9   r;   r;   r<   r=      s    z#DummyProcessor.apply_transformationNr>   r?   r@   rA   r    r!   r=   r;   r;   r;   r<   r"      s   r"   c                   @   s8   e Zd ZdZdZdZdedddZee	dd	d
Z
dS )r#   z
    Processor that highlights search matches in the document.
    Note that this doesn't support multiline search matches yet.

    The style classes 'search' and 'search.current' will be applied to the
    content.
    searchzsearch.currentr   rC   r6   c                 C   s   |j jS )0
        The text we are searching for.
        )search_statetext)r:   rC   r;   r;   r<   _get_search_text   s    z)HighlightSearchProcessor._get_search_textr4   c                 C   sB  |  \}}}}}}}| |}d| j d}	d| j d}
|r:t js:t|}t|}|j	 rnt
j}n
t
d}|j|kr||j}nd }t
jt
|||dD ]}|d ur| |  ko| k n  }nd}t| | D ]J}|| ^}}}|r||
 || d f||< q||	 || d f||< qqt|S )Nz class: r   )flagsFr   )rN   r]   
_classname_classname_currentr   is_doner   r   r[   Zignore_casere
IGNORECASE	RegexFlagcursor_position_rowcursor_position_colfinditerescapestartendranger!   )r:   r5   rC   rD   rE   rF   r8   _Zsearch_textZsearchmatch_fragmentZsearchmatch_current_fragmentZ	line_textr_   Zcursor_columnmatchZ	on_cursorrS   old_fragmentr\   r;   r;   r<   r=      sF    



"


z-HighlightSearchProcessor.apply_transformationN)r>   r?   r@   rA   r`   ra   strr]   r    r!   r=   r;   r;   r;   r<   r#      s   r#   c                   @   s(   e Zd ZdZdZdZdedddZdS )	r$   ai  
    Highlight the search terms that are used for highlighting the incremental
    search. The style class 'incsearch' will be applied to the content.

    Important: this requires the `preview_search=True` flag to be set for the
    `BufferControl`. Otherwise, the cursor position won't be set to the search
    match while searching, and nothing happens.
    Z	incsearchzincsearch.currentr   rY   c                 C   s   |j }|dur|jr|jS dS )rZ   N )search_bufferr\   )r:   rC   rr   r;   r;   r<   r]     s    z4HighlightIncrementalSearchProcessor._get_search_textN)r>   r?   r@   rA   r`   ra   rp   r]   r;   r;   r;   r<   r$      s   	r$   c                   @   s    e Zd ZdZeedddZdS )r%   zB
    Processor that highlights the selection in the document.
    r4   c                 C   s   |  \}}}}}}}d}||}	|	r|	\}
}||
}
||}t|}|
dkrr|dkrrt|dkrrt|dfgS t|
|D ]J}|t|k r|| ^}}}|| |f||< q||t|kr|||df q|t|S )Nz class:selected r   r^   )rN   Zselection_range_at_liner   lenr!   rl   append)r:   r5   rC   rD   rE   rF   r8   rm   Zselected_fragmentZselection_at_lineZfrom_torS   ro   Zold_textr;   r;   r<   r=     s2    
z0HighlightSelectionProcessor.apply_transformationNrW   r;   r;   r;   r<   r%     s   r%   c                   @   s2   e Zd ZdZd
eddddZeeddd	ZdS )r&   z{
    Processor that masks the input. (For passwords.)

    :param char: (string) Character to be used. "*" by default.
    *N)charr6   c                 C   s
   || _ d S rI   )rw   )r:   rw   r;   r;   r<   rK   B  s    zPasswordProcessor.__init__tir6   c                    s"   t t fdd|jD }t|S )Nc                    s*   g | ]"^}}}| j t| g|R qS r;   )rw   rs   ).0styler\   handlerrM   r;   r<   
<listcomp>H  s   z:PasswordProcessor.apply_transformation.<locals>.<listcomp>)r   r   r8   r!   )r:   ry   r8   r;   rM   r<   r=   E  s    
z&PasswordProcessor.apply_transformation)rv   	r>   r?   r@   rA   rp   rK   r    r!   r=   r;   r;   r;   r<   r&   ;  s   r&   c                   @   sT   e Zd ZdZdZdeeddddZee	e
eef  d	d
dZeedddZdS )r'   a  
    When the cursor is on or right after a bracket, it highlights the matching
    bracket.

    :param max_cursor_distance: Only highlight matching brackets when the
        cursor is within this distance. (From inside a `Processor`, we can't
        know which lines will be visible on the screen. But we also don't want
        to scan the whole document for matching brackets on each key press, so
        we limit to this value.)
    z])}>[](){}<>  N)charsmax_cursor_distancer6   c                 C   s   || _ || _tdd| _d S )N   )maxsize)r   r   r   _positions_cache)r:   r   r   r;   r;   r<   rK   _  s    z*HighlightMatchingBracketProcessor.__init__)rD   r6   c                 C   s   |j r2|j | jv r2|j|j| j |j| j d}nT|jr|j| jv r|j| jv rt|j|jd }|j|j| j |j| j d}nd}|r||j7 }|	|\}}||f|j
|jfgS g S dS )zQ
        Return a list of (row, col) tuples that need to be highlighted.
        )	start_posend_posr   N)Zcurrent_charr   Zfind_matching_bracket_positioncursor_positionr   Zchar_before_cursor_closing_bracesr   r\   Ztranslate_index_to_positionrf   rg   )r:   rD   posrowcolr;   r;   r<   _get_positions_to_highlighti  s0    







z=HighlightMatchingBracketProcessor._get_positions_to_highlightr4   c                    s   |  \} }}}}}t jr&t|S t j j jf}j| fdd}|r|D ]V\}	}
|	|krX||
}
t	|}||
 ^}}}|
 j
kr|d7 }n|d7 }||f||
< qXt|S )Nc                      s
     S rI   )r   r;   rD   r:   r;   r<   rT     rU   zHHighlightMatchingBracketProcessor.apply_transformation.<locals>.<lambda>z class:matching-bracket.cursor z class:matching-bracket.other )rN   r   rb   r!   Zrender_counterr\   r   r   getr   rg   )r:   r5   rC   rE   rF   r8   rm   keyZ	positionsr   r   r{   r\   r;   r   r<   r=     s4    

z6HighlightMatchingBracketProcessor.apply_transformation)r   r   )r>   r?   r@   rA   r   rp   rO   rK   r   r   r	   r   r    r!   r=   r;   r;   r;   r<   r'   Q  s    
(r'   c                   @   s    e Zd ZdZeedddZdS )r(   zF
    When we're in Vi block insert mode, display all the cursors.
    r4   c              	   C   s   |  \}}}}}}}|j}t r|j}	t|}||d}
|
t|j|  }d}|	D ]p}|
|  krn|krVn qV|||
 }z|| ^}}}W n  ty   |	|df Y qV0 ||7 }||f||< qVt
|S t
|S d S )Nr   z class:multiple-cursorsr^   )rN   bufferr   Zmultiple_cursor_positionsr   Ztranslate_row_col_to_indexrs   lines
IndexErrorrt   r!   )r:   r5   rC   rD   rE   rF   r8   rm   ZbuffZcursor_positionsr   r   Zfragment_suffixpcolumnr{   r\   r;   r;   r<   r=     s6    z+DisplayMultipleCursors.apply_transformationNrW   r;   r;   r;   r<   r(     s   r(   c                   @   sB   e Zd ZdZdeeddddZeeddd	Z	ed
ddZ
dS )r)   z
    Insert text before the input.

    :param text: This can be either plain text or formatted text
        (or a callable that returns any of those).
    :param style: style to be applied to this prompt/prefix.
    rq   Nr\   r{   r6   c                 C   s   || _ || _d S rI   r\   r{   r:   r\   r{   r;   r;   r<   rK     s    zBeforeInput.__init__rx   c                    s`   |j dkrDt| j| j}||j }t|  fdd} fdd}n|j}d }d }t|||dS )Nr   c                    s   |   S rI   r;   rR   Zshift_positionr;   r<   rT     rU   z2BeforeInput.apply_transformation.<locals>.<lambda>c                    s   |   S rI   r;   rR   r   r;   r<   rT     rU   rF   rQ   )rE   r   r\   r{   r8   r   r!   )r:   ry   fragments_beforer8   rF   rQ   r;   r   r<   r=     s    

z BeforeInput.apply_transformationrL   c                 C   s   d| j d| jdS )NzBeforeInput(z, )r   rM   r;   r;   r<   __repr__  s    zBeforeInput.__repr__)rq   r>   r?   r@   rA   r   rp   rK   r    r!   r=   r   r;   r;   r;   r<   r)     s   r)   c                       sB   e Zd ZdZdd fddZedddZeddd	Z  Z	S )
r*   z
    Display the 'arg' in front of the input.

    This was used by the `PromptSession`, but now it uses the
    `Window.get_line_prefix` function instead.
    NrL   c                    s   t  | j d S rI   )superrK   _get_text_fragmentsrM   	__class__r;   r<   rK     s    zShowArg.__init__c                 C   s4   t  }|jjd u rg S |jj}ddt|fdgS d S )N)class:prompt.argz(arg: zclass:prompt.arg.text)r   z) )r   Zkey_processorargrp   )r:   Zappr   r;   r;   r<   r     s    
zShowArg._get_text_fragmentsc                 C   s   dS )Nz	ShowArg()r;   rM   r;   r;   r<   r   ,  s    zShowArg.__repr__)
r>   r?   r@   rA   rK   r   r   rp   r   __classcell__r;   r;   r   r<   r*     s   r*   c                   @   sB   e Zd ZdZdeeddddZeeddd	Z	ed
ddZ
dS )r+   z
    Insert text after the input.

    :param text: This can be either plain text or formatted text
        (or a callable that returns any of those).
    :param style: style to be applied to this prompt/prefix.
    rq   Nr   c                 C   s   || _ || _d S rI   r   r   r;   r;   r<   rK   9  s    zAfterInput.__init__rx   c                 C   s@   |j |jjd kr0t| j| j}t|j| dS t|jdS d S )Nr   r8   )rE   rD   
line_countr   r\   r{   r!   r8   )r:   ry   Zfragments_afterr;   r;   r<   r=   =  s    zAfterInput.apply_transformationrL   c                 C   s   | j j d| jd| jdS )N(z, style=r   )r   r>   r\   r{   rM   r;   r;   r<   r   F  s    zAfterInput.__repr__)rq   r   r;   r;   r;   r<   r+   0  s   	r+   c                   @   s2   e Zd ZdZd
eddddZeeddd	ZdS )r,   z{
    Append the auto suggestion to the input.
    (The user can then press the right arrow the insert the suggestion.)
    class:auto-suggestionN)r{   r6   c                 C   s
   || _ d S rI   )r{   )r:   r{   r;   r;   r<   rK   P  s    zAppendAutoSuggestion.__init__rx   c                 C   s^   |j |jjd krN|jj}|jr2|jjr2|jj}nd}t|j	| j
|fg dS t|j	dS d S )Nr   rq   r   )rE   rD   r   rC   r   
suggestionZis_cursor_at_the_endr\   r!   r8   r{   )r:   ry   r   r   r;   r;   r<   r=   S  s    
z)AppendAutoSuggestion.apply_transformation)r   r~   r;   r;   r;   r<   r,   J  s   r,   c                   @   s@   e Zd ZdZd
eeg ef  eddddZee	ddd	Z
dS )r.   ze
    Make leading whitespace visible.

    :param get_char: Callable that returns one character.
    Nclass:leading-whitespaceget_charr{   r6   c                 C   s"   t ddd}|| _|p|| _d S )NrL   c                   S   s$   d t j ddkrdS dS d S N   ·replace   ?.encoder   outputencodingr;   r;   r;   r<   default_get_charn  s    zAShowLeadingWhiteSpaceProcessor.__init__.<locals>.default_get_charrp   r{   r   r:   r   r{   r   r;   r;   r<   rK   i  s    z'ShowLeadingWhiteSpaceProcessor.__init__rx   c                 C   sf   |j }|r^t|dr^| j|  f}t|}tt|D ]"}|| d dkrX|||< q: q^q:t|S )Nr^   r   )	r8   r   
startswithr{   r   r   rl   rs   r!   )r:   ry   r8   trS   r;   r;   r<   r=   w  s    
z3ShowLeadingWhiteSpaceProcessor.apply_transformation)Nr   r>   r?   r@   rA   r   r   rp   rK   r    r!   r=   r;   r;   r;   r<   r.   b  s     r.   c                   @   s@   e Zd ZdZd
eeg ef  eddddZee	ddd	Z
dS )r/   zf
    Make trailing whitespace visible.

    :param get_char: Callable that returns one character.
    Nclass:training-whitespacer   c                 C   s"   t ddd}|| _|p|| _d S )NrL   c                   S   s$   d t j ddkrdS dS d S r   r   r;   r;   r;   r<   r     s    zBShowTrailingWhiteSpaceProcessor.__init__.<locals>.default_get_charr   r   r;   r;   r<   rK     s    z(ShowTrailingWhiteSpaceProcessor.__init__rx   c                 C   sv   |j }|rn|d d drn| j|  f}t|}tt|d ddD ]&}|| d }|dkrh|||< qF qnqFt|S )Nr   r^   )r8   endswithr{   r   r   rl   rs   r!   )r:   ry   r8   r   rS   rw   r;   r;   r<   r=     s    
z4ShowTrailingWhiteSpaceProcessor.apply_transformation)Nr   r   r;   r;   r;   r<   r/     s     r/   c                   @   sh   e Zd ZdZdeeeg ef f eeeg ef f eeeg ef f edddd	Ze	e
d
ddZdS )r0   a  
    Render tabs as spaces (instead of ^I) or make them visible (for instance,
    by replacing them with dots.)

    :param tabstop: Horizontal space taken by a tab. (`int` or callable that
        returns an `int`).
    :param char1: Character or callable that returns a character (text of
        length one). This one is used for the first space taken by the tab.
    :param char2: Like `char1`, but for the rest of the space.
       |   ┈	class:tabN)tabstopchar1char2r{   r6   c                 C   s   || _ || _|| _|| _d S rI   )r   r   r   r{   )r:   r   r   r   r{   r;   r;   r<   rK     s    zTabsProcessor.__init__rx   c                    s  t | j}| j}t| j}t| j}t|j}i  g }d}t|D ]t\}	}
| |	< |
d dkr|||  }|dkrv|}|	||f |	|||d  f ||7 }qB|	|
 |d7 }qB| t
|< |d  t
|d < ttd fdd}ttd fdd	}t|||d
S )Nr   r   	)from_positionr6   c                    s    |  S )z-Maps original cursor position to the new one.r;   )r   Zposition_mappingsr;   r<   rF     s    z=TabsProcessor.apply_transformation.<locals>.source_to_display)display_posr6   c                    sF   dd    D }| dkrBz
||  W S  ty>   | d8 } Y q0 qdS )z1Maps display cursor position to the original one.c                 S   s   i | ]\}}||qS r;   r;   )rz   kvr;   r;   r<   
<dictcomp>  rU   zQTabsProcessor.apply_transformation.<locals>.display_to_source.<locals>.<dictcomp>r   r   )itemsKeyError)r   Zposition_mappings_reversedr   r;   r<   rQ     s    
z=TabsProcessor.apply_transformation.<locals>.display_to_sourcer   )r   r   r{   r   r   r   r   r8   	enumeratert   rs   rO   r!   )r:   ry   r   r{   Z
separator1Z
separator2r8   Zresult_fragmentsr   rS   Zfragment_and_textcountrF   rQ   r;   r   r<   r=     s8    






z"TabsProcessor.apply_transformation)r   r   r   r   )r>   r?   r@   rA   r   rO   r   rp   rK   r    r!   r=   r;   r;   r;   r<   r0     s       r0   c                   @   sd   e Zd ZU dZeeeegZe	e
e  ed< ded dddZdeddd	d
ZeedddZdS )r1   z
    Process to display the "(reverse-i-search)`...`:..." stuff around
    the search buffer.

    Note: This processor is meant to be applied to the BufferControl that
    contains the search buffer, it's not meant for the original input.
    _excluded_input_processorsr   rY   c                 C   s2   ddl m} t jj}t||r.|j|kr.|S d S )Nr   r   )prompt_toolkit.layout.controlsr   r   ZlayoutZsearch_target_buffer_control
isinstancesearch_buffer_control)r:   rC   r   Zprev_controlr;   r;   r<   _get_main_buffer  s    
z'ReverseSearchProcessor._get_main_bufferr   )main_controlry   r6   c           	         s   ddl m} t| j ttt d fddt|jp<g }t }|rV||g}n|g}ddl	m
} t|j|sxJ ||j|d|jd	|jd
}|j|j|jd	dS )Nr   r   )itemr6   c                    sh   t | tr0fdd| jD }tdd |D S t | trV| j}|rdt|| jS nt |  sd| S dS )zFilter processors from the main control that we want to disable
            here. This returns either an accepted processor or None.c                    s   g | ]} |qS r;   r;   rz   r   )filter_processorr;   r<   r}   .  rU   zMReverseSearchProcessor._content.<locals>.filter_processor.<locals>.<listcomp>c                 S   s   g | ]}|d ur|qS rI   r;   r   r;   r;   r<   r}   0  rU   N)r   _MergedProcessor
processorsr3   r-   	processorfilter)r   Zaccepted_processorsr   Zexcluded_processorsr   r;   r<   r   )  s    



z9ReverseSearchProcessor._content.<locals>.filter_processorr   SearchBufferControlFT)r   input_processorsZ include_default_input_processorslexerpreview_searchr   )r   )r   r   tupler   r   r   r3   r   r$   controlsr   r   rC   r   r   Zcreate_contentrG   rH   )	r:   r   ry   r   Zfiltered_processorZhighlight_processorZnew_processorsr   rC   r;   r   r<   _content   s*    

	zReverseSearchProcessor._contentrx   c                    s   ddl m} t|j|s J d| |j}|jdkr|r| ||}||jj	}|j
jtjkrhd}nd}dd|fd	g}|d
t|jfdg | }t|  fdd}	 fdd}
nd }	d }
|j}t||	|
dS )Nr   r   zK`ReverseSearchProcessor` should be applied to a `SearchBufferControl` only.r   zi-searchzreverse-i-search)class:prompt.searchr   r   )r   z)`zclass:prompt.search.text)rq   z': c                    s   |   S rI   r;   rR   r   r;   r<   rT     rU   z=ReverseSearchProcessor.apply_transformation.<locals>.<lambda>c                    s   |   S rI   r;   rR   r   r;   r<   rT     rU   r   )r   r   r   rC   r   rE   r   Zget_liner   yr[   	directionr   ZFORWARDr   r8   r   r!   )r:   ry   r   r   contentZline_fragmentsZdirection_textr   r8   rF   rQ   r;   r   r<   r=   Y  sH    	z+ReverseSearchProcessor.apply_transformationN)r>   r?   r@   rA   r#   r%   r)   r+   r   r   r
   r   __annotations__r   r   r    r   r!   r=   r;   r;   r;   r<   r1     s   
	9r1   c                   @   s@   e Zd ZdZeeddddZeedddZ	e
d	d
dZdS )r-   a  
    Processor that applies another processor, according to a certain condition.
    Example::

        # Create a function that returns whether or not the processor should
        # currently be applied.
        def highlight_enabled():
            return true_or_false

        # Wrapped it in a `ConditionalProcessor` for usage in a `BufferControl`.
        BufferControl(input_processors=[
            ConditionalProcessor(HighlightSearchProcessor(),
                                 Condition(highlight_enabled))])

    :param processor: :class:`.Processor` instance.
    :param filter: :class:`~prompt_toolkit.filters.Filter` instance.
    N)r   r   r6   c                 C   s   || _ t|| _d S rI   )r   r   r   )r:   r   r   r;   r;   r<   rK     s    zConditionalProcessor.__init__r4   c                 C   s"   |   r| j|S t|jS d S rI   )r   r   r=   r!   r8   r9   r;   r;   r<   r=     s    z)ConditionalProcessor.apply_transformationrL   c                 C   s   d | jj| j| jS )Nz{}(processor={!r}, filter={!r}))formatr   r>   r   r   rM   r;   r;   r<   r     s
    zConditionalProcessor.__repr__)r>   r?   r@   rA   r   r   rK   r    r!   r=   rp   r   r;   r;   r;   r<   r-     s   	r-   c                   @   s<   e Zd ZdZeg ee f ddddZee	dddZ
dS )	r2   z
    Processor class that dynamically returns any Processor.

    :param get_processor: Callable that returns a :class:`.Processor` instance.
    N)get_processorr6   c                 C   s
   || _ d S rI   )r   )r:   r   r;   r;   r<   rK     s    zDynamicProcessor.__init__rx   c                 C   s   |   pt }||S rI   )r   r"   r=   )r:   ry   r   r;   r;   r<   r=     s    z%DynamicProcessor.apply_transformation)r>   r?   r@   rA   r   r   r   rK   r    r!   r=   r;   r;   r;   r<   r2     s   r2   )r   r6   c                 C   s.   t | dkrt S t | dkr&| d S t| S )z6
    Merge multiple `Processor` objects into one.
    r   r   )rs   r"   r   r   r;   r;   r<   r3     s
    r3   c                   @   s2   e Zd ZdZee dddZeedddZ	dS )	r   zw
    Processor that groups multiple other `Processor` objects, but exposes an
    API as if it is one `Processor`.
    r   c                 C   s
   || _ d S rI   r   )r:   r   r;   r;   r<   rK     s    z_MergedProcessor.__init__rx   c                    s   |j gg  |j}ttdfdd}| jD ]F}|t|j|j|j|||j	|j
}|j} |j |j  q,ttd fdd}d d= t|||S )N)rS   r6   c                    s    D ]}|| } q| S )zcTranslate x position from the buffer to the x position in the
            processor fragments list.r;   rS   f)source_to_display_functionsr;   r<   rF     s    
z@_MergedProcessor.apply_transformation.<locals>.source_to_displayc                    s   t  D ]}|| } q| S rI   )reversedr   )display_to_source_functionsr;   r<   rQ     s    
z@_MergedProcessor.apply_transformation.<locals>.display_to_sourcer   )rF   r8   rO   r   r=   r    rC   rD   rE   rG   rH   rt   rQ   r!   )r:   ry   r8   rF   r   ZtransformationrQ   r;   )r   r   r<   r=     s,    

z%_MergedProcessor.apply_transformationN)
r>   r?   r@   rA   r   r   rK   r    r!   r=   r;   r;   r;   r<   r     s   r   )DrA   rc   abcr   r   typingr   r   r   r   r   r	   r
   r   r   Z"prompt_toolkit.application.currentr   Zprompt_toolkit.cacher   Zprompt_toolkit.documentr   Zprompt_toolkit.filtersr   r   r   Zprompt_toolkit.formatted_textr   r   r   Z#prompt_toolkit.formatted_text.utilsr   r   Zprompt_toolkit.searchr   Zprompt_toolkit.utilsr   r   utilsr   r   r   r   __all__r   rO   rP   rV   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r.   r/   r0   r1   r-   r2   r3   r   r;   r;   r;   r<   <module>   sP   ,.K-i2(&'T (