
    W                     l    S SK Jr  S SKJr  S SKJr  SrS rS rS r	S r
S	 r " S
 S\5      rS rS rg)    )unicode_literals
get_cwidth)Token)token_list_lentoken_list_widthtoken_list_to_textexplode_tokenssplit_linesfind_window_for_buffer_namec                 N   ^ [         R                  m[        U4S jU  5       5      $ )z
Return the amount of characters in this token list.

:param tokenlist: List of (token, text) or (token, text, mouse_handler)
                  tuples.
c              3   T   >#    U  H  oS    T:w  d  M  [        US   5      v   M     g7fr      N)len.0itemZeroWidthEscapes     .lib/third_party/prompt_toolkit/layout/utils.py	<genexpr>!token_list_len.<locals>.<genexpr>   s&     P	!W5O|s47||	s   ((r   r   sum	tokenlistr   s    @r   r   r      s!     ++OP	PPP    c                 N   ^ [         R                  m[        U4S jU  5       5      $ )z
Return the character width of this token list.
(Take double width characters into account.)

:param tokenlist: List of (token, text) or (token, text, mouse_handler)
                  tuples.
c              3   f   >#    U  H&  oS      H  o!S   T:w  d  M  [        U5      v   M     M(     g7f)r   r   Nr   )r   r   cr   s      r   r   #token_list_width.<locals>.<genexpr>$   s-     bGqAwRaGa}z!}}G}s   11r   r   s    @r   r   r      s!     ++Obbbbr   c                 Z   ^ [         R                  mSR                  U4S jU  5       5      $ )z'
Concatenate all the text parts again.
 c              3   B   >#    U  H  oS    T:w  d  M  US   v   M     g7fr    r   s     r   r   %token_list_to_text.<locals>.<genexpr>,   s      OytG4N747ys   )r   r   joinr   s    @r   r	   r	   '   s%     ++O77OyOOOr   c              #      #    / n[        U 5       H%  u  p#UR                  X#45        US:X  d  M  Uv   / nM'     Uv   g7f)z0
Iterator that yields tokenlists for each line.

N)r
   append)r   linetokenr    s       r   iter_token_linesr-   /   sC      D"9-UJ9JD . Js   )>>c              #     #    / nU  H  n[        U5      S:X  aW  Uu  p4UR                  S5      nUSS  H"  nU(       a  UR                  X645        Uv   / nM$     UR                  X5S   45        Mi  Uu  p4nUR                  S5      nUSS  H#  nU(       a  UR                  X6U45        Uv   / nM%     UR                  X5S   U45        M     Uv   g7f)z
Take a single list of (Token, text) tuples and yield one such list for each
line. Just like str.split, this will yield at least one item.

:param tokenlist: List of (token, text) or (token, text, mouse_handler)
                  tuples.
   r)   N)r   splitr*   )r   r+   r   r,   stringpartspartmouse_handlers           r   r   r   >   s      Dt9> MELL&Ecr
KK.
	 # KKb	*+ ,0(E=LL&Ecr
KKm <=
	 # KKb	=9:; F Js   CCc                   P   ^  \ rS rSrSrU 4S jrS rU 4S jrS rU 4S jr	Sr
U =r$ )	_ExplodedListn   z
Wrapper around a list, that marks it as 'exploded'.

As soon as items are added or the list is extended, the new items are
automatically exploded as well.
c                 <   > [         [        U ]
  " U0 UD6  SU l        g )NT)superr7   __init__exploded)selfakw	__class__s      r   r;   _ExplodedList.__init__u   s    mT+Q5"5r   c                 (    U R                  U/5        g N)extend)r=   r   s     r   r*   _ExplodedList.appendy   s    TFr   c                 >   > [         [        U ]  [        U5      5        g rC   )r:   r7   rD   r
   )r=   lstr@   s     r   rD   _ExplodedList.extend|   s    mT).*=>r   c                     [         erC   )NotImplementedError)r=   indexr   s      r   insert_ExplodedList.insert   s    !!r   c                    > [        U[        5      (       d  [        XS-   5      n[        U/5      n[        [        U ]  X5        g)zP
Ensure that when `(Token, 'long string')` is set, the string will be
exploded.
r   N)
isinstanceslicer
   r:   r7   __setitem__)r=   rK   valuer@   s      r   rQ   _ExplodedList.__setitem__   s;    
 %''%+Ew'mT.u<r   )r<   )__name__
__module____qualname____firstlineno____doc__r;   r*   rD   rL   rQ   __static_attributes____classcell__)r@   s   @r   r7   r7   n   s&    ?"
= =r   r7   c                     [        U SS5      (       a  U $ / nU  H   u  p#U H  nUR                  X$45        M     M"     [        U5      $ )a  
Turn a list of (token, text) tuples into another list where each string is
exactly one character.

It should be fine to call this function several times. Calling this on a
list that is already exploded, is a null operation.

:param tokenlist: List of (token, text) tuples.
r<   F)getattrr*   r7   )r   resultr,   r2   r    s        r   r
   r
      sO     y*e,,F"AMM5*%  #   r   c                 *   SSK Jn  [        X5      (       d   eSSKJn  SSKJn  U R                  R                  U 5       HP  n[        XS5      (       d  M  [        UR                  U5      (       d  M2  UR                  R                  U:X  d  MN  Us  $    g)z
Look for a :class:`~prompt_toolkit.layout.containers.Window` in the Layout
that contains the :class:`~prompt_toolkit.layout.controls.BufferControl`
for the given buffer and return it. If no such Window is found, return None.
r   )CommandLineInterfacer   )Window)BufferControlN)prompt_toolkit.interfacer_   rO   
containersr`   controlsra   layoutwalkcontentbuffer_name)clirh   r_   r`   ra   ls         r   r   r      sg     >c0000"'ZZ__S!a  Z		=%I%Iyy$$3 "r   N)
__future__r   prompt_toolkit.utilsr   prompt_toolkit.tokenr   __all__r   r   r	   r-   r   listr7   r
   r   r%   r   r   <module>rp      sI    ' + &Q	cP-`=D =B!.r   