
    f(                        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y)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                  D    e Zd ZdZedd       Ze	 	 	 	 	 	 	 	 dd       Zy)r   z&
    Base interface for a margin.
    c                     y)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    selfget_ui_contents     X/var/www/cvtools/html/venv/lib/python3.12/site-packages/prompt_toolkit/layout/margins.py	get_widthzMargin.get_width%   s         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   window_render_infowidthheights       r   create_marginzMargin.create_margin0   s	    $ 	r   Nr   zCallable[[], UIContent]returnintr!   r   r"   r'   r#   r'   r&   r
   )__name__
__module____qualname____doc__r   r   r$   r   r   r   r   r       sO       "2;>HK	 r   r   )	metaclassc                  F    e Zd ZdZ	 d	 	 	 	 	 ddZddZ	 	 	 	 	 	 	 	 d	dZy)
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.
    c                D    t        |      | _        t        |      | _        y N)r	   relativedisplay_tildes)r   r1   r2   s      r   __init__zNumberedMargin.__init__O   s     "(+'7r   c                V     |       j                   }t        dt        |       dz         S )N   r   )
line_countmaxlen)r   r   r6   s      r   r   zNumberedMargin.get_widthU   s)    #%00
1cZL*Q.//r   c                z   | j                         }d}d}|j                  j                  j                  }g }d }	t	        |j
                        D ]  \  }
}||	k7  r|n||k(  rE|r|j                  |d|dz   z  f       nd|j                  |d|dz   z  j                  |      f       n;|rt        ||z
        dz
  }|j                  |d|dz   z  j                  |      f       |}	|j                  d        | j                         r5
|j                  k  r&|j                  d       |
dz  }
|
|j                  k  r&|S )Nzclass:line-numberzclass:line-number.currentz%ir   z%i  
)zclass:tildez~
)r1   
ui_contentcursor_positiony	enumeratedisplayed_linesappendrjustabsr2   window_height)r   r!   r"   r#   r1   stylestyle_currentcurrent_linenoresultlast_linenor?   linenos               r   r$   zNumberedMargin.create_marginY   sT    ==?#3 ,66FFHH &("#5#E#EF 	&IAv$>~-}dfqj6I&JK*Ufqj-A,H,H,OP
  !$Vn%<!=!AMM55FQJ+?*F*Fu*M"NO KMM*%-	&2  (66645Q (666 r   N)FF)r1   r   r2   r   r&   Noner%   r(   r)   r*   r+   r,   r3   r   r$   r   r   r   r   r   E   sU     NS8$8>J8	80-"2-;>-HK-	-r   r   c                  8    e Zd ZdZddZddZ	 	 	 	 	 	 	 	 ddZy)	r   zJ
    Wrapper around other :class:`.Margin` classes to show/hide them.
    c                2    || _         t        |      | _        y r0   )marginr	   filter)r   rP   rQ   s      r   r3   zConditionalMargin.__init__   s    'r   c                Z    | j                         r| j                  j                  |      S y)Nr   )rQ   rP   r   r   s     r   r   zConditionalMargin.get_width   s#    ;;=;;((88r   c                d    |r-| j                         r| j                  j                  |||      S g S r0   )rQ   rP   r$   r    s       r   r$   zConditionalMargin.create_margin   s.     T[[];;,,-?OOIr   N)rP   r   rQ   r   r&   rL   r%   r(   rM   r   r   r   r   r      s6    ("2;>HK	r   r   c                  N    e Zd ZdZ	 	 	 d	 	 	 	 	 	 	 ddZddZ	 	 	 	 	 	 	 	 d	dZy)
r   zc
    Margin displaying a scrollbar.

    :param display_arrows: Display scroll up/down arrows.
    c                @    t        |      | _        || _        || _        y r0   )r	   display_arrowsup_arrow_symboldown_arrow_symbol)r   rV   rW   rX   s       r   r3   zScrollbarMargin.__init__   s!     (7.!2r   c                     y)Nr   r   r   s     r   r   zScrollbarMargin.get_width   s    r   c           
        |j                   }|j                  }| j                         }|r|dz  }	 t        |j                        t        |      z  }|j                  t        |      z  }t        t        |t        d||z                    t        ||z        dfd}	g }
|r|
j                  d| j                  fdg       d}d}d}d	}t        |      D ]  } |	|      r3 |	|dz         s|
j                  |d
f       nF|
j                  |d
f       n2 |	|dz         r|
j                  |d
f       n|
j                  |d
f       |
j                  d        |r|
j                  d| j                  f       |
S # t        $ r g cY S w xY w)N   r   c                *    | cxk  xr z   k  S c S )z/True if we should display a button on this row.r   )rowscrollbar_heightscrollbar_tops    r   is_scroll_buttonz7ScrollbarMargin.create_margin.<locals>.is_scroll_button   s    $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&   bool)content_heightrE   rV   r8   rA   floatvertical_scrollr'   minr7   extendrW   rangerB   rX   ZeroDivisionError)r   r!   r"   r#   rc   rE   rV   fraction_visiblefraction_abover`   rI   scrollbar_backgroundscrollbar_background_startscrollbar_buttonscrollbar_button_endir^   r_   s                   @@r   r$   zScrollbarMargin.create_margin   s    ,::*88,,.QM5	"#5#E#EFJ   0??%BWWN"M3q-:J*J#KL    >?M
P
 *,F0$2F2FG1 $@ )U&7#I =) *#A&+AE2 ';S&AB'7&=>'A.'A3&GH';S&ABj)*  68N8NOPMW ! 	I	s   A)E= =F
FN)F^v)rV   r   rW   strrX   rs   r&   rL   r%   r(   rM   r   r   r   r   r      sg     (-"!$	3$3 3 	3
 
3?"2?;>?HK?	?r   r   c                  F    e Zd ZdZ	 d	 	 	 	 	 ddZddZ	 	 	 	 	 	 	 	 d	dZy)
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.
    Nc                     || _         || _        y r0   )
get_promptget_continuation)r   rv   rw   s      r   r3   zPromptMargin.__init__  s     % 0r   c                J    t        | j                               }t        |      S )z Width to report to the `Window`.)r   rv   r   )r   r   texts      r   r   zPromptMargin.get_width  s      %T__%67$r   c                   | j                   }g }|j                  t        | j                                      |rNd }|j                  dd  D ]:  }|j                  d       |j                  t         |||||k(                     |}< |S )Nr   r:   )rw   rg   r   rv   rA   rB   )r   r!   r"   r#   rw   rI   last_yr?   s           r   r$   zPromptMargin.create_margin  s      00%' 	'(9:; F'77; j)%&6uaf&MN  r   r0   )rv   z Callable[[], StyleAndTextTuples]rw   z5None | Callable[[int, int, bool], StyleAndTextTuples]r&   rL   r%   r(   rM   r   r   r   r   r      sX    2 >B	141;1
 
1 "2;>HK	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      sz    # ' * : 
 , ,"w "JAV AH 0Sf Sl96 9r   