a
    lc(                     @   s   d Z ddl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mZmZ ddlmZ ddlmZ ertd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`.
    )ABCMetaabstractmethod)TYPE_CHECKINGCallableOptional)FilterOrBool	to_filter)StyleAndTextTuplesfragment_list_to_textto_formatted_text)
get_cwidth   )	UIContent)WindowRenderInfo)MarginNumberedMarginScrollbarMarginConditionalMarginPromptMarginc                   @   sD   e Zd ZdZeeg ef edddZedeee	dddZ
d	S )
r   z&
    Base interface for a margin.
    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   Y/var/www/html/django/DPS/env/lib/python3.9/site-packages/prompt_toolkit/layout/margins.py	get_width"   s    	zMargin.get_widthr   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   intr   r	   r"   r   r   r   r   r      s   
r   )	metaclassc                   @   sP   e Zd ZdZdeeddddZeg ef eddd	Z	d
eee
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.
    FN)relativedisplay_tildesr   c                 C   s   t || _t || _d S N)r   r)   r*   )r   r)   r*   r   r   r   __init__L   s    
zNumberedMargin.__init__r   c                 C   s   | j }tdtd| d S )N   z%sr   )
line_countmaxlen)r   r   r.   r   r   r   r   S   s    zNumberedMargin.get_widthr   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|rt|| 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_linenor4   linenor   r   r   r"   W   s4    



zNumberedMargin.create_margin)FF)r#   r$   r%   r&   r   r,   r   r   r'   r   r	   r"   r   r   r   r   r   B   s   
 r   c                   @   sN   e Zd ZdZeeddddZeg ef e	dddZ
d	e	e	ed
ddZdS )r   zJ
    Wrapper around other :class:`.Margin` classes to show/hide them.
    N)marginfilterr   c                 C   s   || _ t|| _d S r+   )r>   r   r?   )r   r>   r?   r   r   r   r,      s    zConditionalMargin.__init__r   c                 C   s   |   r| j|S dS d S )Nr   )r?   r>   r   r   r   r   r   r      s    zConditionalMargin.get_widthr   r   c                 C   s$   |r|   r| j|||S g S d S r+   )r?   r>   r"   r!   r   r   r   r"      s    zConditionalMargin.create_margin)r#   r$   r%   r&   r   r   r,   r   r   r'   r   r	   r"   r   r   r   r   r      s   r   c                   @   sR   e Zd ZdZdeeeddddZeg ef e	d	d
dZ
de	e	edddZdS )r   zc
    Margin displaying a scrollbar.

    :param display_arrows: Display scroll up/down arrows.
    F^vN)display_arrowsup_arrow_symboldown_arrow_symbolr   c                 C   s   t || _|| _|| _d S r+   )r   rB   rC   rD   )r   rB   rC   rD   r   r   r   r,      s    
zScrollbarMargin.__init__r   c                 C   s   dS )Nr   r   r   r   r   r   r      s    zScrollbarMargin.get_widthr   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 tt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   )rowr   c                    s   |   ko  kS   S )z/True if we should display a button on this row.r   )rF   Zscrollbar_heightZscrollbar_topr   r   is_scroll_button   s    z7ScrollbarMargin.create_margin.<locals>.is_scroll_buttonzclass:scrollbar.arrow)zclass:scrollbarr3   zclass:scrollbar.backgroundz*class:scrollbar.background,scrollbar.startzclass:scrollbar.buttonz$class:scrollbar.button,scrollbar.end r1   )content_heightr:   rB   r0   r6   floatZvertical_scrollr'   minr/   ZeroDivisionErrorboolextendrC   ranger7   rD   )r   r   r   r    rJ   r:   rB   Zfraction_visibleZfraction_aboverH   r<   Zscrollbar_backgroundZscrollbar_background_startZscrollbar_buttonZscrollbar_button_endir   rG   r   r"      sP    


zScrollbarMargin.create_margin)Fr@   rA   )r#   r$   r%   r&   r   strr,   r   r   r'   r   r	   r"   r   r   r   r   r      s      r   c                   @   sj   e Zd ZdZdeg ef eeeeegef  ddddZ	eg e
f edddZd	eee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.
    N)
get_promptget_continuationr   c                 C   s   || _ || _d S r+   )rS   rT   )r   rS   rT   r   r   r   r,     s    zPromptMargin.__init__r   c                 C   s   t |  }t|S )z Width to report to the `Window`.)r
   rS   r   )r   r   textr   r   r   r     s    zPromptMargin.get_widthr   r   c              	   C   sd   | j }g }|t|   |r`d }|jdd  D ],}|d |t|||||k |}q2|S )Nr   r1   )rT   rO   r   rS   r6   r7   )r   r   r   r    rT   r<   Zlast_yr4   r   r   r   r"     s    
zPromptMargin.create_margin)N)r#   r$   r%   r&   r   r	   r   r'   rN   r,   r   r   r"   r   r   r   r   r      s    
r   N)r&   abcr   r   typingr   r   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   	%EW