ó
±xYc           @  s  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 d e e e ƒ f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   uQ   
Margin implementations for a :class:`~prompt_toolkit.layout.containers.Window`.
iÿÿÿÿ(   t   unicode_literals(   t   ABCMetat   abstractmethod(   t   with_metaclass(   t   range(   t   to_cli_filter(   t   Token(   t
   get_cwidthi   (   t   token_list_to_textu   Marginu   NumberredMarginu   ScrollbarMarginu   ConditionalMarginu   PromptMargint   Marginc           B  s,   e  Z d  Z e d „  ƒ Z e d „  ƒ Z RS(   u&   
    Base interface for a margin.
    c         C  s   d S(   uH  
        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.
        i    (    (   t   selft   clit   get_ui_content(    (    s<   lib/python2.7/site-packages/prompt_toolkit/layout/margins.pyt	   get_width   s    
c         C  s   g  S(   uì  
        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   t   window_render_infot   widtht   height(    (    s<   lib/python2.7/site-packages/prompt_toolkit/layout/margins.pyt   create_margin(   s    (   t   __name__t
   __module__t   __doc__R   R   R   (    (    (    s<   lib/python2.7/site-packages/prompt_toolkit/layout/margins.pyR	      s   t   NumberredMarginc           B  s/   e  Z d  Z e e d „ Z d „  Z d „  Z RS(   u  
    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         C  s"   t  | ƒ |  _ t  | ƒ |  _ d  S(   N(   R   t   relativet   display_tildes(   R
   R   R   (    (    s<   lib/python2.7/site-packages/prompt_toolkit/layout/margins.pyt   __init__E   s    c         C  s'   | ƒ  j  } t d t d | ƒ d ƒ S(   Ni   u   %si   (   t
   line_countt   maxt   len(   R
   R   R   R   (    (    s<   lib/python2.7/site-packages/prompt_toolkit/layout/margins.pyR   I   s    c         C  sz  |  j  | ƒ } t j } t j j } | j j j } g  }	 d  }
 xì t | j	 ƒ D]Û \ } } | |
 k r| d  k rv q| | k rÍ | r¦ |	 j
 | d | d f ƒ q|	 j
 | d | d j | ƒ f ƒ q| rê t | | ƒ d } n  |	 j
 | d | d j | ƒ f ƒ n  | }
 |	 j
 t d f ƒ qO W|  j | ƒ rvx6 | | j k  rr|	 j
 t j d f ƒ | d 7} q@Wn  |	 S(   Nu   %ii   u   %i u   
u   ~
(   R   R   t
   LineNumbert   Currentt
   ui_contentt   cursor_positiont   yt   Nonet	   enumeratet   displayed_linest   appendt   rjustt   absR   t   window_heightt   Tilde(   R
   R   R   R   R   R   t   tokent   token_currentt   current_linenot   resultt   last_linenoR    t   lineno(    (    s<   lib/python2.7/site-packages/prompt_toolkit/layout/margins.pyR   M   s0    	''(   R   R   R   t   FalseR   R   R   (    (    (    s<   lib/python2.7/site-packages/prompt_toolkit/layout/margins.pyR   <   s   	t   ConditionalMarginc           B  s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   uJ   
    Wrapper around other :class:`.Margin` classes to show/hide them.
    c         C  s1   t  | t ƒ s t ‚ | |  _ t | ƒ |  _ d  S(   N(   t
   isinstanceR	   t   AssertionErrort   marginR   t   filter(   R
   R3   R4   (    (    s<   lib/python2.7/site-packages/prompt_toolkit/layout/margins.pyR   }   s    	c         C  s*   |  j  | ƒ r" |  j j | | ƒ Sd Sd  S(   Ni    (   R4   R3   R   (   R
   R   R   (    (    s<   lib/python2.7/site-packages/prompt_toolkit/layout/margins.pyR   ƒ   s    c         C  s6   | r. |  j  | ƒ r. |  j j | | | | ƒ Sg  Sd  S(   N(   R4   R3   R   (   R
   R   R   R   R   (    (    s<   lib/python2.7/site-packages/prompt_toolkit/layout/margins.pyR   ‰   s    (   R   R   R   R   R   R   (    (    (    s<   lib/python2.7/site-packages/prompt_toolkit/layout/margins.pyR0   y   s   		t   ScrollbarMarginc           B  s,   e  Z d  Z e d „ Z d „  Z d „  Z RS(   uc   
    Margin displaying a scrollbar.

    :param display_arrows: Display scroll up/down arrows.
    c         C  s   t  | ƒ |  _ d  S(   N(   R   t   display_arrows(   R
   R6   (    (    s<   lib/python2.7/site-packages/prompt_toolkit/layout/margins.pyR   –   s    c         C  s   d S(   Ni   (    (   R
   R   R   (    (    s<   lib/python2.7/site-packages/prompt_toolkit/layout/margins.pyR   ™   s    c           sA  ˆ j  } |  j | ƒ } ˆ j } | r4 | d 8} n  y t | ƒ t | | ƒ ‰  Wn t k
 re g  SX‡  ‡ f d †  } g  }	 | r¯ |	 j t j j	 d f t j d f g ƒ n  xe t
 | ƒ D]W }
 | |
 ƒ rê |	 j t j j d f ƒ n |	 j t j d f ƒ |	 j t d f ƒ q¼ W| r9|	 j t j j	 d f ƒ n  |	 Sd  S(   Ni   c           s!   t  |  d ˆ  ƒ } | ˆ j k S(   u1    True if we should display a button on this row. g      à?(   t   intR#   (   t   rowt   current_row_middle(   t   items_per_rowR   (    s<   lib/python2.7/site-packages/prompt_toolkit/layout/margins.pyt   is_scroll_button©   s    u   ^u   
u    u   v(   t   content_heightR6   R'   t   floatt   mint   ZeroDivisionErrort   extendR   t	   Scrollbart   ArrowR   R$   t   Button(   R
   R   R   R   R   t   total_heightR6   R'   R;   R,   t   i(    (   R:   R   s<   lib/python2.7/site-packages/prompt_toolkit/layout/margins.pyR   œ   s.    		(   R   R   R   R/   R   R   R   (    (    (    s<   lib/python2.7/site-packages/prompt_toolkit/layout/margins.pyR5      s   	t   PromptMarginc           B  s/   e  Z d  Z d e d „ Z d „  Z d „  Z RS(   u·  
    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.
    c         C  s[   t  | ƒ s t ‚ | d  k s0 t  | ƒ s0 t ‚ t | ƒ } | |  _ | |  _ | |  _ d  S(   N(   t   callableR2   R!   R   t   get_prompt_tokenst   get_continuation_tokenst   show_numbers(   R
   RH   RI   RJ   (    (    s<   lib/python2.7/site-packages/prompt_toolkit/layout/margins.pyR   Ô   s    		c         C  s   t  |  j | ƒ ƒ } t | ƒ S(   u"    Width to report to the `Window`. (   R   RH   R   (   R
   R   R   t   text(    (    s<   lib/python2.7/site-packages/prompt_toolkit/layout/margins.pyR   Þ   s    c   
      C  sÐ   |  j  | ƒ } |  j r4 t |  j | | ƒ ƒ } n g  } |  j | ƒ } d  } xz | j d D]k }	 | j t d f ƒ | rµ |	 | k rÂ | j t j d |	 d j	 | ƒ f ƒ qÂ n | j
 | ƒ |	 } q] W| S(   Ni   u   
u   %i (   RH   RI   t   listRJ   R!   R#   R$   R   R   R%   R@   (
   R
   R   R   R   R   t   tokenst   tokens2RJ   t   last_yR    (    (    s<   lib/python2.7/site-packages/prompt_toolkit/layout/margins.pyR   ä   s    	-
N(   R   R   R   R!   R/   R   R   R   (    (    (    s<   lib/python2.7/site-packages/prompt_toolkit/layout/margins.pyRF   Å   s
   		N(   u   Marginu   NumberredMarginu   ScrollbarMarginu   ConditionalMarginu   PromptMargin(   R   t
   __future__R    t   abcR   R   t   sixR   t	   six.movesR   t   prompt_toolkit.filtersR   t   prompt_toolkit.tokenR   t   prompt_toolkit.utilsR   t   utilsR   t   __all__t   objectR	   R   R0   R5   RF   (    (    (    s<   lib/python2.7/site-packages/prompt_toolkit/layout/margins.pyt   <module>   s$       $=5