a
    õ£Beˆ(  ã                   @  sÚ   d Z ddlmZ ddlmZmZ ddlmZmZ ddl	m
Z
mZ ddlmZmZmZ ddlmZ dd	lmZ er|dd
lmZ g d¢ZG dd„ ded�ZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZdS )zQ
Margin implementations for a :class:`~prompt_toolkit.layout.containers.Window`.
é    )Úannotations)ÚABCMetaÚabstractmethod)ÚTYPE_CHECKINGÚCallable)ÚFilterOrBoolÚ	to_filter)ÚStyleAndTextTuplesÚfragment_list_to_textÚto_formatted_text)Ú
get_cwidthé   )Ú	UIContent)ÚWindowRenderInfo)ÚMarginÚNumberedMarginÚScrollbarMarginÚConditionalMarginÚPromptMarginc                   @  s<   e Zd ZdZedddœdd„ƒZeddddd	œd
d„ƒZdS )r   z&
    Base interface for a margin.
    úCallable[[], UIContent]Úint©Úget_ui_contentÚreturnc                 C  s   dS )a  
        Return the width that this margin is going to consume.

        :param get_ui_content: Callable that asks the user control to create
            a :class:`.UIContent` instance. This can be used for instance to
            obtain the number of lines.
        r   © ©Úselfr   r   r   ú`/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/prompt_toolkit/layout/margins.pyÚ	get_width$   s    	zMargin.get_widthr   r	   ©Úwindow_render_infoÚwidthÚheightr   c                 C  s   g S )a³  
        Creates a margin.
        This should return a list of (style_str, text) tuples.

        :param window_render_info:
            :class:`~prompt_toolkit.layout.containers.WindowRenderInfo`
            instance, generated after rendering and copying the visible part of
            the :class:`~prompt_toolkit.layout.controls.UIControl` into the
            :class:`~prompt_toolkit.layout.containers.Window`.
        :param width: The width that's available for this margin. (As reported
            by :meth:`.get_width`.)
        :param height: The height that's available for this margin. (The height
            of the :class:`~prompt_toolkit.layout.containers.Window`.)
        r   ©r   r    r!   r"   r   r   r   Úcreate_margin/   s    zMargin.create_marginN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r$   r   r   r   r   r      s
   
r   )Ú	metaclassc                   @  sH   e Zd ZdZdddddœdd„Zdd	d
œdd„Zdd	d	ddœdd„ZdS )r   a  
    Margin that displays the line numbers.

    :param relative: Number relative to the cursor position. Similar to the Vi
                     'relativenumber' option.
    :param display_tildes: Display tildes after the end of the document, just
        like Vi does.
    Fr   ÚNone)ÚrelativeÚdisplay_tildesr   c                 C  s   t |ƒ| _t |ƒ| _d S ©N)r   r+   r,   )r   r+   r,   r   r   r   Ú__init__N   s    
zNumberedMargin.__init__r   r   r   c                 C  s   |ƒ j }tdtd| ƒd ƒS )Né   z%sr   )Ú
line_countÚmaxÚlen)r   r   r0   r   r   r   r   T   s    zNumberedMargin.get_widthr   r	   r   c                 C  sò   |   ¡ }d}d}|jjj}g }d }	t|jƒD ]š\}
}||	kr¸|d u rFnr||krˆ|rj| |d|d  f¡ q¸| |d|d   |¡f¡ n0|rœt|| ƒd }| |d|d   |¡f¡ |}	| d¡ q,|  	¡ rî|
|j
k rî| d¡ |
d7 }
qÐ|S )Nzclass:line-numberzclass:line-number.currentz%ir   z%i ©Ú Ú
)zclass:tildez~
)r+   Z
ui_contentZcursor_positionÚyÚ	enumerateÚdisplayed_linesÚappendÚrjustÚabsr,   Úwindow_height)r   r    r!   r"   r+   ÚstyleZstyle_currentZcurrent_linenoÚresultZlast_linenor6   Úlinenor   r   r   r$   X   s4    
ÿ


zNumberedMargin.create_marginN)FF©r%   r&   r'   r(   r.   r   r$   r   r   r   r   r   D   s
   
 ÿr   c                   @  sF   e Zd ZdZddddœdd„Zdd	d
œdd„Zdd	d	ddœdd„ZdS )r   zJ
    Wrapper around other :class:`.Margin` classes to show/hide them.
    r   r   r*   )ÚmarginÚfilterr   c                 C  s   || _ t|ƒ| _d S r-   )rA   r   rB   )r   rA   rB   r   r   r   r.   �   s    zConditionalMargin.__init__r   r   r   c                 C  s   |   ¡ r| j |¡S dS d S )Nr   )rB   rA   r   r   r   r   r   r   ‘   s    zConditionalMargin.get_widthr   r	   r   c                 C  s$   |r|   ¡ r| j |||¡S g S d S r-   )rB   rA   r$   r#   r   r   r   r$   —   s    zConditionalMargin.create_marginNr@   r   r   r   r   r   ˆ   s   r   c                   @  sJ   e Zd ZdZddddddœd	d
„Zdddœdd„Zdddddœdd„ZdS )r   zc
    Margin displaying a scrollbar.

    :param display_arrows: Display scroll up/down arrows.
    Fú^Úvr   Ústrr*   )Údisplay_arrowsÚup_arrow_symbolÚdown_arrow_symbolr   c                 C  s   t |ƒ| _|| _|| _d S r-   )r   rF   rG   rH   )r   rF   rG   rH   r   r   r   r.   §   s    
zScrollbarMargin.__init__r   r   r   c                 C  s   dS )Nr   r   r   r   r   r   r   ±   s    zScrollbarMargin.get_widthr   r	   r   c                   sZ  |j }|j}|  ¡ }|r |d8 }zHt|jƒt|ƒ }|jt|ƒ }tt|t	d|| ƒƒƒ‰ t|| ƒ‰W n t
y~   g  Y S 0 dddœ‡ ‡fdd„}	g }
|r²|
 d| jfd	g¡ d
}d}d}d}t|ƒD ]p}|	|ƒ�r|	|d ƒsô|
 |df¡ n|
 |df¡ n,|	|d ƒ�r"|
 |df¡ n|
 |df¡ |
 d¡ qÊ|�rR|
 d| jf¡ |
S d S )Né   r   r   Úbool)Úrowr   c                   s   ˆ|   koˆˆ  kS   S )z/True if we should display a button on this row.r   )rK   ©Zscrollbar_heightZscrollbar_topr   r   Úis_scroll_buttonÌ   s    z7ScrollbarMargin.create_margin.<locals>.is_scroll_buttonzclass:scrollbar.arrow)zclass:scrollbarr5   zclass:scrollbar.backgroundz*class:scrollbar.background,scrollbar.startzclass:scrollbar.buttonz$class:scrollbar.button,scrollbar.endú r3   )Úcontent_heightr<   rF   r2   r8   ÚfloatZvertical_scrollr   Úminr1   ÚZeroDivisionErrorÚextendrG   Úranger9   rH   )r   r    r!   r"   rO   r<   rF   Zfraction_visibleZfraction_aboverM   r>   Zscrollbar_backgroundZscrollbar_background_startZscrollbar_buttonZscrollbar_button_endÚir   rL   r   r$   ´   sP    
ÿÿ
þÿ
zScrollbarMargin.create_marginN)FrC   rD   r@   r   r   r   r   r       s      ü
r   c                   @  sH   e Zd ZdZdddddœdd„Zd	d
dœdd„Zdd
d
ddœdd„ZdS )r   a¢  
    [Deprecated]

    Create margin that displays a prompt.
    This can display one prompt at the first line, and a continuation prompt
    (e.g, just dots) on all the following lines.

    This `PromptMargin` implementation has been largely superseded in favor of
    the `get_line_prefix` attribute of `Window`. The reason is that a margin is
    always a fixed width, while `get_line_prefix` can return a variable width
    prefix in front of every line, making it more powerful, especially for line
    continuations.

    :param get_prompt: Callable returns formatted text or a list of
        `(style_str, type)` tuples to be shown as the prompt at the first line.
    :param get_continuation: Callable that takes three inputs. The width (int),
        line_number (int), and is_soft_wrap (bool). It should return formatted
        text or a list of `(style_str, type)` tuples for the next lines of the
        input.
    Nz Callable[[], StyleAndTextTuples]z5None | Callable[[int, int, bool], StyleAndTextTuples]r*   )Ú
get_promptÚget_continuationr   c                 C  s   || _ || _d S r-   )rV   rW   )r   rV   rW   r   r   r   r.     s    zPromptMargin.__init__r   r   r   c                 C  s   t |  ¡ ƒ}t|ƒS )z Width to report to the `Window`.)r
   rV   r   )r   r   Útextr   r   r   r     s    zPromptMargin.get_widthr   r	   r   c              	   C  sd   | j }g }| t|  ¡ ƒ¡ |r`d }|jdd … D ],}| d¡ | t|||||kƒƒ¡ |}q2|S )Nr   r3   )rW   rS   r   rV   r8   r9   )r   r    r!   r"   rW   r>   Zlast_yr6   r   r   r   r$     s    
ÿzPromptMargin.create_margin)Nr@   r   r   r   r   r   ö   s
    ü	r   N)r(   Ú
__future__r   Úabcr   r   Útypingr   r   Zprompt_toolkit.filtersr   r   Zprompt_toolkit.formatted_textr	   r
   r   Zprompt_toolkit.utilsr   Zcontrolsr   Ú
containersr   Ú__all__r   r   r   r   r   r   r   r   r   Ú<module>   s   	%DV