
    "                         d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ d	d
lmZ dZ G d d ee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`.
    )unicode_literals)ABCMetaabstractmethod)with_metaclass)range)to_cli_filter)Token)
get_cwidth   )token_list_to_text)MarginNumberredMarginScrollbarMarginConditionalMarginPromptMarginc                   0    e Zd ZdZed        Zed        Zy)r   z&
    Base interface for a margin.
    c                      y)aH  
        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_widthzMargin.get_width   s         c                     g S )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_marginzMargin.create_margin(   s	    " 	r   N)__name__
__module____qualname____doc__r   r   r    r   r   r   r   r      s/     	 	  r   r   c                   $    e Zd ZdZddZd Z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   r(   r)   s      r   __init__zNumberredMargin.__init__E   s    %h/+N;r   c                 Z     |       j                   }t        dt        d|z        dz         S )N   z%sr   )
line_countmaxlen)r   r   r   r-   s       r   r   zNumberredMargin.get_widthI   s,    #%00
1c$+,q011r   c                    | j                  |      }t        j                  }t        j                  j                  }|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                  t        df        | j                  |      rE|j                  k  r6|	j                  t        j                  df       |dz  }||j                  k  r6|	S )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_linenor7   linenos                r   r    zNumberredMargin.create_marginM   so   ==%  ((00 ,66FFHH "#5#E#EFIAv$>~-}dfqj6I&JK}u
7K6R6RSX6Y&Z[  !$Vn%<!=!AMM55FQJ+?*F*Fu*M"NO KMM5$-() G. s#(666u{{E23Q (666 r   N)FFr!   r"   r#   r$   r*   r   r    r   r   r   r   r   <   s    <2)r   r   c                   "    e Zd ZdZd Zd Zd Zy)r   zJ
    Wrapper around other :class:`.Margin` classes to show/hide them.
    c                 V    t        |t              sJ || _        t        |      | _        y r'   )
isinstancer   marginr   filter)r   rI   rJ   s      r   r*   zConditionalMargin.__init__}   s%    &&)))#F+r   c                 ^    | j                  |      r| j                  j                  ||      S y)Nr   )rJ   rI   r   r   r   r5   s      r   r   zConditionalMargin.get_width   s(    ;;s;;((j99r   c                 h    |r/| j                  |      r| j                  j                  ||||      S g S r'   )rJ   rI   r    r   s        r   r    zConditionalMargin.create_margin   s1    T[[%;;,,S2DeVTTIr   NrE   r   r   r   r   r   y   s    ,r   r   c                   $    e Zd ZdZddZd Zd Zy)r   zc
    Margin displaying a scrollbar.

    :param display_arrows: Display scroll up/down arrows.
    c                 $    t        |      | _        y r'   )r   display_arrows)r   rP   s     r   r*   zScrollbarMargin.__init__   s    +N;r   c                      y)Nr   r   rL   s      r   r   zScrollbarMargin.get_width   s    r   c                    j                   }| j                  |      }j                  }|r|dz  }	 t        |      t	        ||      z  fd}g }	|r=|	j                  t        j                  j                  dft        j                  dfg       t        |      D ]n  }
 ||
      r,|	j                  t        j                  j                  df       n!|	j                  t        j                  df       |	j                  t        df       p |r+|	j                  t        j                  j                  df       |	S # t        $ r g cY S w xY w)N   c                 B    t        | dz   z        }|j                  v S )z1 True if we should display a button on this row. g      ?)intr9   )rowcurrent_row_middleitems_per_rowr   s     r   is_scroll_buttonz7ScrollbarMargin.create_margin.<locals>.is_scroll_button   s)    %(#(m)C%D")-?-O-OOOr   ^r2    v)content_heightrP   r=   floatminextendr	   	ScrollbarArrowr   r:   ButtonZeroDivisionError)r   r   r   r   r   total_heightrP   r=   rY   rB   irX   s     `        @r   r    zScrollbarMargin.create_margin   s$   )88,,S1*88QM	!,/#lM2RRMP F__**C0__d+  =)#A&MM5??#9#93"?@MM5??C"89udm, * u44c:;M9 ! 	I	s   D> >EEN)FrE   r   r   r   r   r      s    
<&r   r   c                   (    e Zd ZdZ	 	 ddZd Zd Zy)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                 |    t        |      sJ |t        |      sJ t        |      }|| _        || _        || _        y r'   )callabler   get_prompt_tokensget_continuation_tokensshow_numbers)r   rj   rk   rl   s       r   r*   zPromptMargin.__init__   sG    )***&.(;R2SSS$\2!2'>$(r   c                 L    t        | j                  |            }t        |      S )z" Width to report to the `Window`. )r   rj   r
   )r   r   r5   texts       r   r   zPromptMargin.get_width   s$     "$"8"8"=>$r   c                    | j                  |      d d  }| j                  rt        | j                  ||            }ng }| j                  |      }d }|j                  dd  D ]j  }	|j                  t        df       |r<|	|k7  rH|j                  t        j                  d|	dz   z  j                  |      f       n|j                  |       |	}l |S )Nr   r2   r1   )
rj   rk   listrl   r9   r:   r	   r3   r;   r`   )
r   r   r   r   r   tokenstokens2rl   last_yr7   s
             r   r    zPromptMargin.create_margin   s    '',Q/ '' 477UCDGG((-#33AB7AMM5$-(;MM5#3#3eq1uo5L5LU5S"TUg&F 8 r   )NFrE   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   