
    "                         S r SSKJr  SSKJrJr  SSKJr  SSKJ	r	  SSK
Jr  SSKJr  SSKJr  S	S
KJr  Sr " S S\" \\5      5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rg)zQ
Margin implementations for a :class:`~prompt_toolkit.layout.containers.Window`.
    )unicode_literals)ABCMetaabstractmethod)with_metaclass)range)to_cli_filter)Token)
get_cwidth   )token_list_to_text)MarginNumberredMarginScrollbarMarginConditionalMarginPromptMarginc                   8    \ rS rSrSr\S 5       r\S 5       rSrg)r      z
Base interface for a margin.
c                     g)a  
Return the width that this margin is going to consume.

:param cli: :class:`.CommandLineInterface` instance.
: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cliget_ui_contents      0lib/third_party/prompt_toolkit/layout/margins.py	get_widthMargin.get_width   s         c                     / $ )a  
Creates a margin.
This should return a list of (Token, text) tuples.

:param cli: :class:`.CommandLineInterface` instance.
: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   window_render_infowidthheights        r   create_marginMargin.create_margin(   s	    " 	r   r   N)	__name__
__module____qualname____firstlineno____doc__r   r   r"   __static_attributes__r   r   r   r   r      s/     	 	  r   r   c                   .    \ rS rSrSrSS jrS rS rSrg)	r   <   z
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    [        U5      U l        [        U5      U l        g N)r   relativedisplay_tildes)r   r.   r/   s      r   __init__NumberredMargin.__init__E   s    %h/+N;r   c                 Z    U" 5       R                   n[        S[        SU-  5      S-   5      $ )N   z%sr   )
line_countmaxlen)r   r   r   r4   s       r   r   NumberredMargin.get_widthI   s,    #%00
1c$+,q011r   c                    U R                  U5      n[        R                  n[        R                  R                  nUR                  R
                  R                  n/ n	S n
[        UR                  5       H  u  pX:w  a  Uc  OX:X  aJ  U(       a  U	R                  USUS-   -  45        OhU	R                  USUS-   -  R                  U5      45        O?U(       a  [        X-
  5      S-
  nU	R                  USUS-   -  R                  U5      45        Un
U	R                  [        S45        M     U R                  U5      (       aG  WUR                  :  a7  U	R                  [        R                  S45        US-  nXR                  :  a  M7  U	$ )Nz%ir   %i 
z~
)r.   r	   
LineNumberCurrent
ui_contentcursor_positiony	enumeratedisplayed_linesappendrjustabsr/   window_heightTilde)r   r   r   r    r!   r.   tokentoken_currentcurrent_linenoresultlast_linenor?   linenos                r   r"   NumberredMargin.create_marginM   sg   ==%  ((00 ,66FFHH "#5#E#EFIA$>-}dfqj6I&JK}u
7K6R6RSX6Y&Z[  !$V%<!=!AMM55FQJ+?*F*Fu*M"NO KMM5$-() G. s##(666u{{E23Q 666 r   )r/   r.   N)FF	r$   r%   r&   r'   r(   r0   r   r"   r)   r   r   r   r   r   <   s    <2)r   r   c                   *    \ rS rSrSrS rS rS rSrg)r   y   zB
Wrapper around other :class:`.Margin` classes to show/hide them.
c                 ^    [        U[        5      (       d   eXl        [        U5      U l        g r-   )
isinstancer   marginr   filter)r   rS   rT   s      r   r0   ConditionalMargin.__init__}   s&    &&))))#F+r   c                 f    U R                  U5      (       a  U R                  R                  X5      $ g)Nr   )rT   rS   r   r   r   r=   s      r   r   ConditionalMargin.get_width   s)    ;;s;;((99r   c                 x    U(       a2  U R                  U5      (       a  U R                  R                  XX45      $ / $ r-   )rT   rS   r"   r   s        r   r"   ConditionalMargin.create_margin   s/    T[[%%;;,,SeTTIr   )rT   rS   NrN   r   r   r   r   r   y   s    ,r   r   c                   .    \ rS rSrSrSS jrS rS rSrg)	r      zW
Margin displaying a scrollbar.

:param display_arrows: Display scroll up/down arrows.
c                 $    [        U5      U l        g r-   )r   display_arrows)r   r^   s     r   r0   ScrollbarMargin.__init__   s    +N;r   c                     g)Nr   r   rW   s      r   r   ScrollbarMargin.get_width   s    r   c                   ^^ TR                   nU R                  U5      nTR                  nU(       a  US-  n [        U5      [	        XW5      -  mUU4S jn/ n	U(       a=  U	R                  [        R                  R                  S4[        R                  S4/5        [        U5       Ht  n
U" U
5      (       a,  U	R                  [        R                  R                  S45        O!U	R                  [        R                  S45        U	R                  [        S45        Mv     U(       a+  U	R                  [        R                  R                  S45        U	$ ! [         a    / s $ f = f)N   c                 D   > [        U S-   T-  5      nUTR                  ;   $ )z0True if we should display a button on this row. g      ?)intrA   )rowcurrent_row_middleitems_per_rowr   s     r   is_scroll_button7ScrollbarMargin.create_margin.<locals>.is_scroll_button   s)    %(#(m)C%D")-?-O-OOOr   ^r:    v)content_heightr^   rE   floatminextendr	   	ScrollbarArrowr   rB   ButtonZeroDivisionError)r   r   r   r    r!   total_heightr^   rE   ri   rJ   irh   s     `        @r   r"   ScrollbarMargin.create_margin   s%   )88,,S1*88QM	!,/#l2RRMP F__**C0__d+  =)#A&&MM5??#9#93"?@MM5??C"89udm, * u44c:;M9 ! 	I	s   E E#"E#)r^   N)FrN   r   r   r   r   r      s    
<&r   r   c                   2    \ rS rSrSr  SS jrS rS rSrg)	r      a  
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.

:param get_prompt_tokens: Callable that takes a CommandLineInterface as
    input and returns a list of (Token, type) tuples to be shown as the
    prompt at the first line.
:param get_continuation_tokens: Callable that takes a CommandLineInterface
    and a width as input and returns a list of (Token, type) tuples for the
    next lines of the input.
:param show_numbers: (bool or :class:`~prompt_toolkit.filters.CLIFilter`)
    Display line numbers instead of the continuation prompt.
Nc                     [        U5      (       d   eUb  [        U5      (       d   e[        U5      nXl        X l        X0l        g r-   )callabler   get_prompt_tokensget_continuation_tokensshow_numbers)r   r}   r~   r   s       r   r0   PromptMargin.__init__   sG    )****&.(;R2S2SSS$\2!2'>$(r   c                 L    [        U R                  U5      5      n[        U5      $ )z!Width to report to the `Window`. )r   r}   r
   )r   r   r=   texts       r   r   PromptMargin.get_width   s$     "$"8"8"=>$r   c                    U R                  U5      S S  nU R                  (       a  [        U R                  X5      5      nO/ nU R                  U5      nS nUR                  SS   Hp  n	UR                  [        S45        U(       a<  X:w  a6  UR                  [        R                  SU	S-   -  R                  U5      45        OUR                  U5        U	nMr     U$ )Nr   r:   r9   )
r}   r~   listr   rA   rB   r	   r;   rC   rq   )
r   r   r   r    r!   tokenstokens2r   last_yr?   s
             r   r"   PromptMargin.create_margin   s    '',Q/ '' 477CDGG((-#33AB7AMM5$-(;MM5#3#3eq1uo5L5LU5S"TUg&F 8 r   )r~   r}   r   )NFrN   r   r   r   r   r      s      CG#) r   r   N)r(   
__future__r   abcr   r   sixr   	six.movesr   prompt_toolkit.filtersr   prompt_toolkit.tokenr	   prompt_toolkit.utilsr
   utilsr   __all__objectr   r   r   r   r   r   r   r   <module>r      sq    ( '   0 & + %!^GV, !H:f :z .2f 2j86 8r   