
    Mh(                       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e          Z G d de          Z G d de          Z G d de          Z G 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                  B    e Zd ZdZedd            Zedd            ZdS )r   z&
    Base interface for a margin.
    get_ui_contentCallable[[], UIContent]returnintc                    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   s     ]/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/prompt_toolkit/layout/margins.py	get_widthzMargin.get_width%   s	     q    window_render_infor   widthheightr
   c                    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$   s       r   create_marginzMargin.create_margin0   s	    $ 	r!   Nr   r   r   r   r"   r   r#   r   r$   r   r   r
   )__name__
__module____qualname____doc__r   r    r'   r   r!   r   r   r       s^             ^    ^  r!   r   )	metaclassc                  .    e Zd ZdZ	 dddZddZ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.
    Frelativer   display_tildesr   Nonec                V    t          |          | _        t          |          | _        d S N)r	   r0   r1   )r   r0   r1   s      r   __init__zNumberedMargin.__init__O   s)     "(++'77r!   r   r   r   c                b     |            j         }t          dt          |           dz             S )N   r   )
line_countmaxlen)r   r   r8   s      r   r    zNumberedMargin.get_widthU   s1    #^%%0
1cZ/**Q.///r!   r"   r   r#   r$   r
   c                   |                                  }d}d}|j        j        j        }g }d }	t	          |j                  D ]\  }
}||	k    r|n||k    rQ|r|                    |d|dz   z  f           nx|                    |d|dz   z                      |          f           nG|rt          ||z
            dz
  }|                    |d|dz   z                      |          f           |}	|                    d           | 	                                r0|
|j
        k     r%|                    d           |
dz  }
|
|j
        k     %|S )Nzclass:line-numberzclass:line-number.currentz%ir   z%i  
)zclass:tildez~
)r0   
ui_contentcursor_positiony	enumeratedisplayed_linesappendrjustabsr1   window_height)r   r"   r#   r$   r0   stylestyle_currentcurrent_linenoresultlast_linenorA   linenos               r   r'   zNumberedMargin.create_marginY   s    ==??#3 ,6FH &("#5#EFF 	& 	&IAv$$>~-- }dfqj6I&JKKKK*Ufqj-A,H,H,O,OP   
   B!$Vn%<!=!=!AMM55FQJ+?*F*Fu*M*M"NOOO KMM*%%%%    	(6664555Q (666 r!   N)FF)r0   r   r1   r   r   r2   r(   r)   r*   r+   r,   r-   r5   r    r'   r   r!   r   r   r   E   sf          NS8 8 8 8 80 0 0 0- - - - - -r!   r   c                  *    e Zd ZdZddZddZddZdS )r   zJ
    Wrapper around other :class:`.Margin` classes to show/hide them.
    marginr   filterr   r   r2   c                <    || _         t          |          | _        d S r4   )rP   r	   rQ   )r   rP   rQ   s      r   r5   zConditionalMargin.__init__   s    ''r!   r   r   r   c                b    |                                  r| j                            |          S dS )Nr   )rQ   rP   r    r   s     r   r    zConditionalMargin.get_width   s-    ;;== 	;((8881r!   r"   r   r#   r$   r
   c                j    |r0|                                  r| j                            |||          S g S r4   )rQ   rP   r'   r&   s       r   r'   zConditionalMargin.create_margin   s;      	T[[]] 	;,,-?OOOIr!   N)rP   r   rQ   r   r   r2   r(   r)   rN   r   r!   r   r   r      sZ         ( ( ( (        r!   r   c                  2    e Zd ZdZ	 	 	 dddZddZddZdS )r   zc
    Margin displaying a scrollbar.

    :param display_arrows: Display scroll up/down arrows.
    F^vdisplay_arrowsr   up_arrow_symbolstrdown_arrow_symbolr   r2   c                J    t          |          | _        || _        || _        d S r4   )r	   rX   rY   r[   )r   rX   rY   r[   s       r   r5   zScrollbarMargin.__init__   s*     (77.!2r!   r   r   r   c                    dS )Nr   r   r   s     r   r    zScrollbarMargin.get_width   s    qr!   r"   r   r#   r$   r
   c           
     p   |j         }|j        }|                                 }|r|dz  }	 t          |j                  t          |          z  }|j        t          |          z  }t          t          |t          d||z                                t          ||z            dfd}	g }
|r|

                    d| j        fd	g           d
}d}d}d}t          |          D ]} |	|          r> |	|dz             s|
                    |df           nU|
                    |df           n= |	|dz             r|
                    |df           n|
                    |df           |
                    d           |r|
                    d| j        f           |
S # t          $ r g cY S w xY w)N   r   rowr   r   boolc                *    | cxk    oz   k    nc S )z/True if we should display a button on this row.r   )r`   scrollbar_heightscrollbar_tops    r   is_scroll_buttonz7ScrollbarMargin.create_margin.<locals>.is_scroll_button   s+    $OOOO}?O/OOOOOOr!   zclass:scrollbar.arrow)zclass:scrollbarr>   zclass:scrollbar.backgroundz*class:scrollbar.background,scrollbar.startzclass:scrollbar.buttonz$class:scrollbar.button,scrollbar.end r<   )r`   r   r   ra   )content_heightrG   rX   r:   rC   floatvertical_scrollr   minr9   extendrY   rangerD   r[   ZeroDivisionError)r   r"   r#   r$   rg   rG   rX   fraction_visiblefraction_abovere   rK   scrollbar_backgroundscrollbar_background_startscrollbar_buttonscrollbar_button_endirc   rd   s                   @@r   r'   zScrollbarMargin.create_margin   sg    ,:*8,,.. 	QM5	"#5#EFFJ J   0?%BWBWWN"M3q-:J*J#K#KLL      >??M
P P P P P P P
 *,F 0$2FG1   $@ )U&7#I =)) * *##A&& C++AE22 ? ';S&ABBBB'7&=>>>>''A.. C'A3&GHHHH';S&ABBBj))))  Q68NOPPPMW ! 	 	 	III	s   A;F& &F54F5N)FrV   rW   )rX   r   rY   rZ   r[   rZ   r   r2   r(   r)   rN   r   r!   r   r   r      sj          (-"!$	3 3 3 3 3   ? ? ? ? ? ?r!   r   c                  .    e Zd ZdZ	 ddd	ZddZ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 Callable[[], StyleAndTextTuples]get_continuation5None | Callable[[int, int, bool], StyleAndTextTuples]r   r2   c                "    || _         || _        d S r4   )rv   rx   )r   rv   rx   s      r   r5   zPromptMargin.__init__  s     % 0r!   r   r   r   c                b    t          |                                           }t          |          S )z Width to report to the `Window`.)r   rv   r   )r   r   texts      r   r    zPromptMargin.get_width  s)     %T__%6%677$r!   r"   r   r#   r$   r
   c                <   | j         }g }|                    t          |                                                      |r\d }|j        dd          D ]J}|                    d           |                    t           |||||k                                   |}K|S )Nr   r<   )rx   rk   r   rv   rC   rD   )r   r"   r#   r$   rx   rK   last_yrA   s           r   r'   zPromptMargin.create_margin  s      0%' 	'(9(9::;;;  	F'7;  j)))%&6&6uaf&M&MNN   r!   r4   )rv   rw   rx   ry   r   r2   r(   r)   rN   r   r!   r   r   r      se         2 >B	1 1 1 1 1            r!   r   N)r-   
__future__r   abcr   r   typingr   r   prompt_toolkit.filtersr   r	   prompt_toolkit.formatted_textr
   r   r   prompt_toolkit.utilsr   controlsr   
containersr   __all__r   r   r   r   r   r   r!   r   <module>r      s    # " " " " " ' ' ' ' ' ' ' ' * * * * * * * * : : : : : : : :         
 , + + + + +       -,,,,,,  " " " " "w " " " "JA A A A AV A A AH       0S S S S Sf S S Sl9 9 9 9 96 9 9 9 9 9r!   