
                           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JrJr  SSKJrJrJr  SS	KJr  SS
KJrJrJr  SSKJrJr  SSKJr  SSKJrJrJ r   SSK!J"r"J#r#  SSK$J%r%  SSK&J'r'  SSK(J)r)J*r*  Sr+\'RX                  r, " S S\" \\-5      5      r.S r/ " S S\.5      r0 " S S\.5      r1 " S S\.5      r2 " S S\-5      r3 " S S\-5      r4 " S  S!\-5      r5 " S" S#\-5      r6\" 5       \ " 5       -  r7 " S$ S%\.5      r8 " S& S'\.5      r9\.r:g())za
Container for the layout.
(Containers can contain other containers or user interface controls.)
    )unicode_literals)ABCMetaabstractmethod)with_metaclass)range   )	UIControlTokenListControl	UIContent)LayoutDimensionsum_layout_dimensionsmax_layout_dimensions)Margin)PointWritePosition_CHAR_CACHE)token_list_to_textexplode_tokens)SimpleCache)to_cli_filterViInsertModeEmacsInsertMode)
MouseEventMouseEventType)Integer)Token)take_using_weights
get_cwidth)
	ContainerHSplitVSplitFloatContainerFloatWindowWindowRenderInfoConditionalContainerScrollOffsetsColorColumnc                   h    \ rS rSrSr\S 5       r\S 5       r\S 5       r\S 5       r	\S 5       r
Srg	)
r   '   z'
Base class for user interface layout.
c                     g)z]
Reset the state of this container and all the children.
(E.g. reset scroll offsets, etc...)
N selfs    3lib/third_party/prompt_toolkit/layout/containers.pyresetContainer.reset+           c                     g)z
Return a :class:`~prompt_toolkit.layout.dimension.LayoutDimension` that
represents the desired width for this container.

:param cli: :class:`~prompt_toolkit.interface.CommandLineInterface`.
Nr,   r.   climax_available_widths      r/   preferred_widthContainer.preferred_width2   r2   r3   c                     g)z
Return a :class:`~prompt_toolkit.layout.dimension.LayoutDimension` that
represents the desired height for this container.

:param cli: :class:`~prompt_toolkit.interface.CommandLineInterface`.
Nr,   r.   r6   widthmax_available_heights       r/   preferred_heightContainer.preferred_height;   r2   r3   c                     g)a  
Write the actual content to the screen.

:param cli: :class:`~prompt_toolkit.interface.CommandLineInterface`.
:param screen: :class:`~prompt_toolkit.layout.screen.Screen`
:param mouse_handlers: :class:`~prompt_toolkit.layout.mouse_handlers.MouseHandlers`.
Nr,   r.   r6   screenmouse_handlerswrite_positions        r/   write_to_screenContainer.write_to_screenD   r2   r3   c                     g)zH
Walk through all the layout nodes (and their children) and yield them.
Nr,   r.   r6   s     r/   walkContainer.walkN   r2   r3   r,   N)__name__
__module____qualname____firstlineno____doc__r   r0   r8   r>   rE   rI   __static_attributes__r,   r3   r/   r   r   '   sk              r3   r   c                  b    [        [        R                  " [        R                  S4/5      5      $ )z=Create a `Window` that displays the 'Window too small' text. z Window too small... )r$   r
   staticr   WindowTooSmallr,   r3   r/   _window_too_smallrT   U   s/    "))


 7	89; < <r3   c                   J    \ rS rSrSr  SS jrS rS rS rS r	S	 r
S
 rSrg)r    [   a  
Several layouts, one stacked above/under the other.

:param children: List of child :class:`.Container` objects.
:param window_too_small: A :class:`.Container` object that is displayed if
    there is not enough space for all the children. By default, this is a
    "Window too small" message.
:param get_dimensions: (`None` or a callable that takes a
    `CommandLineInterface` and returns a list of `LayoutDimension`
    instances.) By default the dimensions are taken from the children and
    divided by the available space. However, when `get_dimensions` is specified,
    this is taken instead.
:param report_dimensions_callback: When rendering, this function is called
    with the `CommandLineInterface` and the list of used dimensions. (As a
    list of integers.)
Nc                    [        S U 5       5      (       d   eUb  [        U[        5      (       d   eUb  [        U5      (       d   eUb  [        U5      (       d   eXl        U=(       d
    [        5       U l        X0l        X@l        g )Nc              3   B   #    U  H  n[        U[        5      v   M     g 7fN
isinstancer   .0cs     r/   	<genexpr>"HSplit.__init__.<locals>.<genexpr>n        >X:a++X   	allr[   r   callablechildrenrT   window_too_smallget_dimensionsreport_dimensions_callbackr.   rf   rg   rh   ri   s        r/   __init__HSplit.__init__l       >X>>>>>':6F	+R+RRR%.)A)AAA)1X>X5Y5YYY  0 G4E4G,*D'r3   c                     U R                   (       a5  U R                    Vs/ s H  o3R                  X5      PM     nn[        U5      $ [        S5      $ s  snf Nr   )rf   r8   r   r   r.   r6   r7   r^   
dimensionss        r/   r8   HSplit.preferred_widthx   sF    ==OS}}]}!++CE}J](44"1%% ^s   Ac                 x    U R                    Vs/ s H  oDR                  XU5      PM     nn[        U5      $ s  snf rY   )rf   r>   r   )r.   r6   r<   r=   r^   rq   s         r/   r>   HSplit.preferred_height   s;    TXTaTabTaq((5IJTa
b$Z00 cs   7c                 J    U R                    H  nUR                  5         M     g rY   rf   r0   r.   r^   s     r/   r0   HSplit.reset       AGGI r3   c                 p   U R                  X5      nU R                  (       a  U R                  X5        Uc  U R                  R                  XX45        gUR                  nUR
                  nUR                  n[        XPR                  5       H&  u  pU
R                  XU[        XvX5      5        Xi-  nM(     gz
Render the prompt to a `Screen` instance.

:param screen: The :class:`~prompt_toolkit.layout.screen.Screen` class
    to which the output has to be written.
N)
_divide_heigthsri   rg   rE   yposxposr<   ziprf   r   )r.   r6   rB   rC   rD   sizesr}   r~   r<   sr^   s              r/   rE   HSplit.write_to_screen   s     $$S9**++C7=!!11^= "&&D!&&D"((EE==1!!#~}TY^?bc	 2r3   c           	        ^^^ U R                   (       d  / $ U R                  (       a  U R                  T5      OSmUUU4S jn[        U R                   5       VVs/ s H  u  pEU" XT5      PM     nnn[        U5      nUR                  TR
                  :  a  gU Vs/ s H  oR                  PM     n	n[        [        [        [        U5      5      5      U Vs/ s H  oR                  PM     snS9n
[        U
5      n[        U	5      [	        TR
                  UR                  5      :  aZ  X   Xk   R                  :  a  X==   S-  ss'   [        U
5      n[        U	5      [	        TR
                  UR                  5      :  a  MZ  [        TR                  TR                   TR"                  /5      (       d  [        U	5      [	        TR$                  UR&                  5      :  aZ  X   Xk   R&                  :  a  X==   S-  ss'   [        U
5      n[        U	5      [	        TR$                  UR&                  5      :  a  MZ  U	$ s  snnf s  snf s  snf )zJ
Return the heights for all rows.
Or None when there is not enough space.
Nc                 v   > T(       a  TU   b  TU   $ U R                  TTR                  TR                  5      $ rY   )r>   r<   extended_height)r^   indexr6   given_dimensionsrD   s     r/   get_dimension_for_child7HSplit._divide_heigths.<locals>.get_dimension_for_child   s=    $4U$;$G'..))#~/C/C^EcEcddr3   itemsweightsr   )rf   rh   	enumerater   minr   r   listr   lenweightnextsum	preferredanyis_returning
is_exitingis_abortingheightmax)r.   r6   rD   r   r   r^   rq   sum_dimensionsdr   child_generatorir   s    ``         @r/   r|   HSplit._divide_heigths   s   
 }}I 8<7J7J4..s3PT	e IRRVR_R_H`aH`HE-a7H`
a /z:  > >> !++
1
+,uS_-.'12z!XXz24 !%j3~==~?W?WXXx*-111A_%A	 %j3~==~?W?WXX C$$cnncooFGGe*s>#8#8.:L:LMM8jm///HMH)	 e*s>#8#8.:L:LMM C b , 3s   H>II	
c              #   r   #    U v   U R                    H  nUR                  U5       H  nUv   M	     M!     g7fzWalk through children. Nrf   rI   r.   r6   r^   r   s       r/   rI   HSplit.walk   /     
AVVC[ !    57rf   rh   ri   rg   NNN)rK   rL   rM   rN   rO   rk   r8   r>   r0   rE   r|   rI   rP   r,   r3   r/   r    r    [   s4      37AE
E&122hr3   r    c                   J    \ rS rSrSr  SS jrS rS rS rS r	S	 r
S
 rSrg)r!      a	  
Several layouts, one stacked left/right of the other.

:param children: List of child :class:`.Container` objects.
:param window_too_small: A :class:`.Container` object that is displayed if
    there is not enough space for all the children. By default, this is a
    "Window too small" message.
:param get_dimensions: (`None` or a callable that takes a
    `CommandLineInterface` and returns a list of `LayoutDimension`
    instances.) By default the dimensions are taken from the children and
    divided by the available space. However, when `get_dimensions` is specified,
    this is taken instead.
:param report_dimensions_callback: When rendering, this function is called
    with the `CommandLineInterface` and the list of used dimensions. (As a
    list of integers.)
Nc                    [        S U 5       5      (       d   eUb  [        U[        5      (       d   eUb  [        U5      (       d   eUb  [        U5      (       d   eXl        U=(       d
    [        5       U l        X0l        X@l        g )Nc              3   B   #    U  H  n[        U[        5      v   M     g 7frY   rZ   r\   s     r/   r_   "VSplit.__init__.<locals>.<genexpr>   ra   rb   rc   rj   s        r/   rk   VSplit.__init__   rm   r3   c                 v    U R                    Vs/ s H  o3R                  X5      PM     nn[        U5      $ s  snf rY   )rf   r8   r   rp   s        r/   r8   VSplit.preferred_width   s4    KO==Y=a''A=
Y$Z00 Zs   6c           	          U R                  X5      nUc
  [        5       $ [        X@R                  5       VVs/ s H  u  pVUR	                  XU5      PM     nnn[        U5      $ s  snnf rY   )_divide_widthsr   r   rf   r>   r   )r.   r6   r<   r=   r   r   r^   rq   s           r/   r>   VSplit.preferred_height   sn    ##C/="$$ '*%&?A&?da ,,S5IJ&?  A(44As   A#c                 J    U R                    H  nUR                  5         M     g rY   rv   rw   s     r/   r0   VSplit.reset  ry   r3   c           	        ^^^ U R                   (       d  / $ U R                  (       a  U R                  T5      OSmUUU4S jn[        U R                   5       VVs/ s H  u  pEU" XT5      PM     nnn[        U5      nUR                  T:  a  gU Vs/ s H  oR                  PM     n	n[        [        [        [        U5      5      5      U Vs/ s H  oR                  PM     snS9n
[        U
5      n[        U	5      [	        TUR                  5      :  aP  X   Xk   R                  :  a  X==   S-  ss'   [        U
5      n[        U	5      [	        TUR                  5      :  a  MP  [        U	5      [	        TUR                  5      :  aP  X   Xk   R                  :  a  X==   S-  ss'   [        U
5      n[        U	5      [	        TUR                  5      :  a  MP  U	$ s  snnf s  snf s  snf )zL
Return the widths for all columns.
Or None when there is not enough space.
Nc                 L   > T(       a  TU   b  TU   $ U R                  TT5      $ rY   )r8   )r^   r   r6   r   r<   s     r/   r   6VSplit._divide_widths.<locals>.get_dimension_for_child  s/    $4U$;$G'..((e44r3   r   r   )rf   rh   r   r   r   r   r   r   r   r   r   r   r   r   )r.   r6   r<   r   r   r^   rq   r   r   r   r   r   r   s    ``         @r/   r   VSplit._divide_widths
  s   
 }}I 8<7J7J4..s3PT	5 IRRVR_R_H`aH`HE-a7H`
a /z: % !++
1
+,uS_-.'12z!XXz24 !%j3un&>&>??x*-111A_%A	 %j3un&>&>?? %j3un&8&899x*-+++A_%A	 %j3un&8&899 A b , 3s   GG!G&
c                    U R                   (       d  gU R                  XR                  5      nU R                  (       a  U R                  X5        Uc  U R                  R                  XX45        g[        XPR                   5       VVs/ s H+  u  pgUR                  XUR                  5      R                  PM-     nnn[        UR                  [        UR                  [        U5      5      5      n	UR                  n
UR                  n[        XPR                   5       H&  u  pUR                  XU[        XX5      5        X-  nM(     gs  snnf r{   )rf   r   r<   ri   rg   rE   r   r>   r   r   r   r   r   r}   r~   r   )r.   r6   rB   rC   rD   r   r<   childheightsr   r}   r~   r   r^   s                 r/   rE   VSplit.write_to_screen=  s     }}##C)=)=>**++C7 =!!11^= (+5--'@B'@|u ))#n6T6TU__'@ 	 B^**C0N0NPST[P\,]^ """"}}-DAc>=UV;_`ID .Bs   2Ec              #   r   #    U v   U R                    H  nUR                  U5       H  nUv   M	     M!     g7fr   r   r   s       r/   rI   VSplit.walk_  r   r   r   r   )rK   rL   rM   rN   rO   rk   r8   r>   r0   r   rE   rI   rP   r,   r3   r/   r!   r!      s5      37AE
E151f Dr3   r!   c                   B    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
rg)r"   ig  as  
Container which can contain another container for the background, as well
as a list of floating containers on top of it.

Example Usage::

    FloatContainer(content=Window(...),
                   floats=[
                       Float(xcursor=True,
                            ycursor=True,
                            layout=CompletionMenu(...))
                   ])
c                 |    [        U[        5      (       d   e[        S U 5       5      (       d   eXl        X l        g )Nc              3   B   #    U  H  n[        U[        5      v   M     g 7frY   )r[   r#   )r]   fs     r/   r_   *FloatContainer.__init__.<locals>.<genexpr>w  s     8A:a''rb   )r[   r   rd   contentfloats)r.   r   r   s      r/   rk   FloatContainer.__init__u  s6    '9----888888r3   c                     U R                   R                  5         U R                   H  nUR                   R                  5         M     g rY   )r   r0   r   )r.   r   s     r/   r0   FloatContainer.reset|  s.    AIIOO r3   c                 8    U R                   R                  X5      $ rY   )r   r8   )r.   r6   rD   s      r/   r8   FloatContainer.preferred_width  s    ||++C@@r3   c                 :    U R                   R                  XU5      $ )z
Return the preferred height of the float container.
(We don't care about the height of the floats, they should always fit
into the dimensions provided by the container.)
)r   r>   r;   s       r/   r>   FloatContainer.preferred_height  s     ||,,S9MNNr3   c                 
   U R                   R                  XX45        U R                   GH9  nUR                  =(       d    UR                  n[        UR                  UR                  -
  UR                  UR                  -
  S9nUR                  U5      nUR                  U5      nUR                  b  Ub  UR                  n	Un
GOUR                  bA  UR                  b4  UR                  n	UR                  UR                  -
  UR                  -
  n
GOUb-  UR                  b   UR                  UR                  -
  U-
  n	Un
GOrUR                  (       a  Un
U
cE  UR                   R!                  XR                  5      R"                  n
[%        UR                  U
5      n
UR                  n	X-   UR                  :  a  ['        SUR                  U
-
  5      n	OU(       a  [)        UR                  U-
  S-  5      n	Un
OUR                   R!                  XR                  5      R"                  n
UR                  b  UR                  n	OYUR                  b'  ['        SUR                  U
-
  UR                  -
  5      n	O%['        S[)        UR                  U
-
  S-  5      5      n	[%        XR                  U	-
  5      n
UR*                  b  Ub  UR*                  nUnGOUR*                  bA  UR,                  b4  UR*                  nUR.                  UR*                  -
  UR,                  -
  nGOUb-  UR,                  b   UR.                  U-
  UR,                  -
  nUnGOUR0                  (       a  UR                  S-   nUnUc0  UR                   R3                  XUR4                  5      R"                  nXR4                  U-
  :  aK  UR4                  U-
  S-   U:  a  UR4                  U-
  nGO[%        XR                  5      nUR                  U-
  nOU(       a  [)        UR.                  U-
  S-  5      nUnOUR                   R3                  XUR4                  5      R"                  nUR*                  b  UR*                  nOYUR,                  b'  ['        SUR.                  U-
  UR,                  -
  5      nO%['        S[)        UR.                  U-
  S-  5      5      n[%        XR.                  U-
  5      nUS:  d  GM  U
S:  d  GM  [7        XR                  -   XR                  -   XS9nUR8                  (       a  U R;                  X-5      (       d  GM  UR                   R                  XX=5        GM<     g )Nxyr      r   )r~   r}   r<   r   )r   rE   r   menu_positioncursor_positionr   r   r~   r   r}   	get_width
get_heightleftrightr<   xcursorr8   r   r   r   inttopbottomr   ycursorr>   r   r   hide_when_covering_content_area_is_empty)r.   r6   rB   rC   rD   flr   fl_width	fl_heightr~   r<   r}   r   wps                 r/   rE   FloatContainer.write_to_screen  s   $$S.Q++B %22Lf6L6LO#o&7&7.:M:M&M&5&7&7.:M:M&MOO ||C(Hc*I ww"x';ww $)=ww&,,rww6A%"((*>%++bhh6A  =JJ66s<P<PQ[[E 4 4e<E&((<."6"66q."6"6">?DN008;q@A  

2238L8LMWW77&77DXX)q."6"6">"IJDq#~';';e'Cq&H"IJD E#7#7$#>? vv!i&;vv"#		(=vv'..7"))C&299+@%,,y8299D"&((1,">ZZ88N$B$BDDMI 
 ::TAA%55<q@DH "0!?!?$!F "%V->->!?.0069 N11I=BC" 44 > >@@I	  66%66DYY*q."7"7&"@299"LMDq#~'<'<v'E&J"KLD V%:%:T%AB zeai"/B/B(B(,/B/B(B).? 448K8KF8W8WJJ..sNOa r3   c                    Un[         R                  n[        UR                  UR                  UR                  -   5       H~  nXQR
                  ;   d  M  UR
                  U   n[        UR                  UR                  UR                  -   5       H*  nXg   nUR                  S:w  d  UR                  U:w  d  M)      g   M     g)zz
Return True when the area below the write position is still empty.
(For floats that should not hide content underneath.)
 FT)
r   Transparentr   r}   r   data_bufferr~   r<   chartoken)	r.   rB   rD   r   r   r   rowr   r^   s	            r/   r   FloatContainer._area_is_empty  s    
 ''rww")) 34A&&&((+rww"(((:;AAvv};(>$ <	 5 r3   c              #      #    U v   U R                   R                  U5       H  nUv   M	     U R                   H)  nUR                   R                  U5       H  nUv   M	     M+     g7fr   )r   rI   r   )r.   r6   r   r   s       r/   rI   FloatContainer.walk  sT     
""3'AG ( AYY^^C( ) s   A%A')r   r   N)rK   rL   rM   rN   rO   rk   r0   r8   r>   rE   r   rI   rP   r,   r3   r/   r"   r"   g  s/    AOsPj&	r3   r"   c                   <    \ rS rSrSr    S	S jrS rS rS rSr	g)
r#   i!  z
Float for use in a :class:`.FloatContainer`.

:param content: :class:`.Container` instance.
:param hide_when_covering_content: Hide the float when it covers content underneath.
Nc                     [        U[        5      (       d   eUb  Ub   eUb  Ub   eX@l        X l        Xl        X0l        XPl        X`l        Xpl        Xl	        Xl
        Xl        Xl        Xl        g rY   )r[   r   r   r   r   r   _width_height
_get_width_get_heightr   r   r   r   )r.   r   r   r   r   r<   r   r   r   r   r   r   r   s                r/   rk   Float.__init__(  su     '9----}	 111~!333	
#%*D'r3   c                     U R                   (       a  U R                   $ U R                  (       a  U R                  U5      $ g rY   )r   r   rH   s     r/   r   Float.get_widthA  s.    ;;;;????3'' r3   c                     U R                   (       a  U R                   $ U R                  (       a  U R                  U5      $ g rY   )r   r   rH   s     r/   r   Float.get_heightG  s2    <<<<##C(( r3   c                      SU R                   -  $ )NzFloat(content=%r)r   r-   s    r/   __repr__Float.__repr__M  s    "T\\11r3   )r   r   r   r   r   r   r   r   r   r   r   r   )NNNNNNNNFFNF)
rK   rL   rM   rN   rO   rk   r   r   r   rP   r,   r3   r/   r#   r#   !  s,     @DEI7;,1E2()2r3   r#   c                       \ rS rSrSrS r\S 5       r\S 5       r\S 5       r	\S 5       r
\S 5       rSS	 jrSS
 jr  SS jr\S 5       r\S 5       r\S 5       r\S 5       r\S 5       rS rSrg)r%   iQ  a$  
Render information, for the last render time of this control.
It stores mapping information between the input buffers (in case of a
:class:`~prompt_toolkit.layout.controls.BufferControl`) and the actual
render position on the output screen.

(Could be used for implementation of the Vi 'H' and 'L' key bindings as
well as implementing mouse support.)

:param ui_content: The original :class:`.UIContent` instance that contains
    the whole input, without clipping. (ui_content)
:param horizontal_scroll: The horizontal scroll of the :class:`.Window` instance.
:param vertical_scroll: The vertical scroll of the :class:`.Window` instance.
:param window_width: The width of the window that displays the content,
    without the margins.
:param window_height: The height of the window that displays the content.
:param configured_scroll_offsets: The scroll offsets as configured for the
    :class:`Window` instance.
:param visible_line_to_row_col: Mapping that maps the row numbers on the
    displayed screen (starting from zero for the first visible line) to
    (row, col) tuples pointing to the row and column of the :class:`.UIContent`.
:param rowcol_to_yx: Mapping that maps (row, column) tuples representing
    coordinates of the :class:`UIContent` to (y, x) absolute coordinates at
    the rendered screen.
c                 v   [        U[        5      (       d   e[        U[        5      (       d   e[        U[        5      (       d   e[        U[        5      (       d   e[        U[        5      (       d   e[        U[        5      (       d   e[        U[        5      (       d   e[        U[        5      (       d   e[        U	[        5      (       d   e[        U
[        5      (       d   e[        U[
        5      (       d   eXl        X0l        X@l        XPl	        X`l
        Xpl        Xl        Xl        Xl        Xl        g rY   )r[   r   r   r'   dictbool
ui_contentvertical_scrollwindow_widthwindow_heightconfigured_scroll_offsetsvisible_line_to_row_col
wrap_lines_rowcol_to_yx	_x_offset	_y_offset)r.   r  horizontal_scrollr  r  r  r  r  rowcol_to_yxx_offsety_offsetr  s               r/   rk   WindowRenderInfo.__init__k  s   
 *i0000+S1111/3////,,,,,-----3]CCCC148888,----(C(((((C((((*d++++$.(*)B&'>$$)!!r3   c                 V    [        S U R                  R                  5        5       5      $ )Nc              3   2   #    U  H  u  pXS    4v   M     g7f)r   Nr,   )r]   visible_linerowcols      r/   r_   >WindowRenderInfo.visible_line_to_input_line.<locals>.<genexpr>  s"      N(L$ !9%(Ls   )r   r  r   r-   s    r/   visible_line_to_input_line+WindowRenderInfo.visible_line_to_input_line  s/     N(,(D(D(J(J(LN N 	Nr3   c                     U R                   R                  nU R                  UR                  UR                  4   u  p#[        X0R                  -
  X R                  -
  S9$ )za
Return the cursor position coordinates, relative to the left/top corner
of the rendered screen.
r   )r  r   r	  r   r   r   r
  r  )r.   cposr   r   s       r/   r    WindowRenderInfo.cursor_position  sL     ..!!$&&$&&.1q>>)Q-?@@r3   c                 h   U R                   S   S:X  a  SnOLU R                  U R                  R                  R                     n[        X R                  R                  5      n[        U[        U R                  R                  U R                   S   -
  S-
  U R                  R                  5      SSS9$ )z
Return a :class:`.ScrollOffsets` instance that indicates the actual
offset. This can be less than or equal to what's configured. E.g, when
the cursor is completely at the top, the top offset will be zero rather
than what's configured.
r   r   r   r   r   r   )displayed_linesinput_line_to_visible_liner  r   r   r   r  r   r'   
line_countr   )r.   r   r   s      r/   applied_scroll_offsets'WindowRenderInfo.applied_scroll_offsets  s     "a'C //0O0O0Q0QRAa77;;<Ct11D4H4H4LLqP55<<> ! 	r3   c                 V    [        S U R                  R                  5        5       5      $ )zn
List of all the visible rows. (Line numbers of the input buffer.)
The last line may not be entirely visible.
c              3   *   #    U  H	  u  pUv   M     g 7frY   r,   )r]   r   cols      r/   r_   3WindowRenderInfo.displayed_lines.<locals>.<genexpr>  s     P*Ohcc*Os   )sortedr  valuesr-   s    r/   r   WindowRenderInfo.displayed_lines  s$     P$*F*F*M*M*OPPPr3   c                     0 nU R                   R                  5        H   u  p#X1;   a  [        X   U5      X'   M  X!U'   M"     U$ )z
Return the dictionary mapping the line numbers of the input buffer to
the lines of the screen. When a line spans several rows at the screen,
the first row appears in the dictionary.
)r  r   r   )r.   resultkvs       r/   r  +WindowRenderInfo.input_line_to_visible_line  sG     3399;DA{	1-	q		 <
 r3   c                 t    U(       a#  U R                   U R                  R                     $ U R                   S   $ )zf
Return the line number (0 based) of the input document that corresponds
with the first visible line.
r   )r  r!  r   )r.   after_scroll_offsets     r/   first_visible_line#WindowRenderInfo.first_visible_line  s5    
 ''(C(C(G(GHH''**r3   c                 z    U(       a&  U R                   SU R                  R                  -
     $ U R                   S   $ )z;
Like `first_visible_line`, but for the last visible line.
r  )r  r!  r   )r.   before_scroll_offsets     r/   last_visible_line"WindowRenderInfo.last_visible_line  s:      ''T-H-H-O-O(OPP''++r3   c                 r    U R                  U5      U R                  U5      U R                  U5      -
  S-  -   $ )z=
Like `first_visible_line`, but for the center visible line.
r   )r1  r5  )r.   r4  r0  s      r/   center_visible_line$WindowRenderInfo.center_visible_line  sJ    
 ''(;<''(<=(()<=>BCDD 	r3   c                 .    U R                   R                  $ )z&
The full height of the user control.
)r  r   r-   s    r/   content_heightWindowRenderInfo.content_height  s    
 )))r3   c                 h    U R                   S:H  =(       a    U R                  5       U R                  :H  $ )zE
True when the full height is visible (There is no vertical scroll.)
r   )r  r5  r;  r-   s    r/   full_height_visible$WindowRenderInfo.full_height_visible  s.    
 ##q(\T-C-C-EI\I\-\\r3   c                      U R                   S:H  $ )z-
True when the top of the buffer is visible.
r   )r  r-   s    r/   top_visibleWindowRenderInfo.top_visible  s    
 ##q((r3   c                 B    U R                  5       U R                  S-
  :H  $ )z0
True when the bottom of the buffer is visible.
r   )r5  r;  r-   s    r/   bottom_visibleWindowRenderInfo.bottom_visible  s#    
 %%'4+>+>+BBBr3   c                 ^    U R                   (       a  gSU R                  -  U R                  -  $ )zc
Vertical scroll as a percentage. (0 means: the top is visible,
100 means: the bottom is visible.)
d   )rD  r  r;  r-   s    r/   vertical_scroll_percentage+WindowRenderInfo.vertical_scroll_percentage  s,     $...$2E2EEFr3   c                 p    U R                   (       a%  U R                  R                  XR                  5      $ g)zd
Return the height of the given line.
(The height that it would take, if this line became visible.)
r   )r  r  get_height_for_liner  )r.   linenos     r/   rK  $WindowRenderInfo.get_height_for_line  s)    
 ????66v?P?PQQr3   )
r	  r
  r  r  r  r  r  r  r  r  N)F)FF)rK   rL   rM   rN   rO   rk   propertyr  r   r!  r  r  r1  r5  r8  r;  r>  rA  rD  rH  rK  rP   r,   r3   r/   r%   r%   Q  s    2"> N N
 A A  0 Q Q  +, 8=05 * * ] ] ) ) C C G Gr3   r%   c                   h    \ rS rSrSrSS jr\S 5       r\S 5       r\S 5       r	\S 5       r
S rS	rg
)r'   i  z|
Scroll offsets for the :class:`.Window` class.

Note that left/right offsets only make sense if line wrapping is disabled.
c                     [        U[        5      (       d   e[        U[        5      (       d   e[        U[        5      (       d   e[        U[        5      (       d   eXl        X l        X0l        X@l        g rY   )r[   r   _top_bottom_left_right)r.   r   r   r   r   s        r/   rk   ScrollOffsets.__init__  sb    #w''''&'****$((((%))))	
r3   c                 ,    [        U R                  5      $ rY   )r   rQ  r-   s    r/   r   ScrollOffsets.top*  s    499~r3   c                 ,    [        U R                  5      $ rY   )r   rR  r-   s    r/   r   ScrollOffsets.bottom.  s    4<<  r3   c                 ,    [        U R                  5      $ rY   )r   rS  r-   s    r/   r   ScrollOffsets.left2  s    4::r3   c                 ,    [        U R                  5      $ rY   )r   rT  r-   s    r/   r   ScrollOffsets.right6  s    4;;r3   c           	      x    SU R                   < SU R                  < SU R                  < SU R                  < S3	$ )NzScrollOffsets(top=z	, bottom=z, left=z, right=)r  r-   s    r/   r   ScrollOffsets.__repr__:  s%    HHdkk499djj: 	:r3   )rR  rS  rT  rQ  N)r   r   r   r   )rK   rL   rM   rN   rO   rk   rN  r   r   r   r   r   rP   r,   r3   r/   r'   r'     sa    
	   ! !      :r3   r'   c                   4    \ rS rSr\R
                  4S jrSrg)r(   i?  c                     Xl         X l        g rY   positionr   )r.   rd  r   s      r/   rk   ColorColumn.__init__@  s     
r3   rc  N)rK   rL   rM   rN   r   r(   rk   rP   r,   r3   r/   r(   r(   ?  s    ','8'8 r3   r(   c                       \ rS rSrSrSSSSSSSSSSSSSSSSS\R                  \R                  4S jrS r	S r
S rS	 rS
 r\SS j5       rS rS rS r   SS jrS rS rS rS rS rS rS rS rS rS rSrg)r$   iH  a  
Container that holds a control.

:param content: :class:`~prompt_toolkit.layout.controls.UIControl` instance.
:param width: :class:`~prompt_toolkit.layout.dimension.LayoutDimension` instance.
:param height: :class:`~prompt_toolkit.layout.dimension.LayoutDimension` instance.
:param get_width: callable which takes a `CommandLineInterface` and returns a `LayoutDimension`.
:param get_height: callable which takes a `CommandLineInterface` and returns a `LayoutDimension`.
:param dont_extend_width: When `True`, don't take up more width then the
                          preferred width reported by the control.
:param dont_extend_height: When `True`, don't take up more width then the
                           preferred height reported by the control.
:param left_margins: A list of :class:`~prompt_toolkit.layout.margins.Margin`
    instance to be displayed on the left. For instance:
    :class:`~prompt_toolkit.layout.margins.NumberredMargin` can be one of
    them in order to show line numbers.
:param right_margins: Like `left_margins`, but on the other side.
:param scroll_offsets: :class:`.ScrollOffsets` instance, representing the
    preferred amount of lines/columns to be always visible before/after the
    cursor. When both top and bottom are a very high number, the cursor
    will be centered vertically most of the time.
:param allow_scroll_beyond_bottom: A `bool` or
    :class:`~prompt_toolkit.filters.CLIFilter` instance. When True, allow
    scrolling so far, that the top part of the content is not visible
    anymore, while there is still empty space available at the bottom of
    the window. In the Vi editor for instance, this is possible. You will
    see tildes while the top part of the body is hidden.
:param wrap_lines: A `bool` or :class:`~prompt_toolkit.filters.CLIFilter`
    instance. When True, don't scroll horizontally, but wrap lines instead.
:param get_vertical_scroll: Callable that takes this window
    instance as input and returns a preferred vertical scroll.
    (When this is `None`, the scroll is only determined by the last and
    current cursor position.)
:param get_horizontal_scroll: Callable that takes this window
    instance as input and returns a preferred vertical scroll.
:param always_hide_cursor: A `bool` or
    :class:`~prompt_toolkit.filters.CLIFilter` instance. When True, never
    display the cursor, even when the user control specifies a cursor
    position.
:param cursorline: A `bool` or :class:`~prompt_toolkit.filters.CLIFilter`
    instance. When True, display a cursorline.
:param cursorcolumn: A `bool` or :class:`~prompt_toolkit.filters.CLIFilter`
    instance. When True, display a cursorcolumn.
:param get_colorcolumns: A callable that takes a `CommandLineInterface` and
    returns a a list of :class:`.ColorColumn` instances that describe the
    columns to be highlighted.
:param cursorline_token: The token to be used for highlighting the current line,
    if `cursorline` is True.
:param cursorcolumn_token: The token to be used for highlighting the current line,
    if `cursorcolumn` is True.
NFc                 f  ^^ [        U[        5      (       d   eTb  [        T[        5      (       d   eTb  [        T[        5      (       d   eUb  [        U5      (       d   eUb  [        U5      (       d   eTb  Ub   eTb  Ub   eU
b  [        U
[        5      (       d   eUb  [        S U 5       5      (       d   eU	b  [        S U	 5       5      (       d   eUb  [        U5      (       d   eUb  [        U5      (       d   eUb  [        U5      (       d   e[        U5      U l        [        U5      U l        [        U5      U l	        [        U5      U l
        [        U5      U l        Xl        X`l        Xpl        U=(       d    / U l        U	=(       d    / U l        U
=(       d
    [	        5       U l        Xl        Xl        U=(       d    U4S jU l        U=(       d    U4S jU l        U=(       d    S U l        UU l        UU l        [3        SS9U l        [3        SS9U l        U R9                  5         g )	Nc              3   B   #    U  H  n[        U[        5      v   M     g 7frY   r[   r   r]   ms     r/   r_   "Window.__init__.<locals>.<genexpr>  s     *W,Q:a+@+@,rb   c              3   B   #    U  H  n[        U[        5      v   M     g 7frY   ri  rj  s     r/   r_   rl    s     +Y=aJq&,A,A=rb   c                    > T$ rY   r,   )r6   r<   s    r/   <lambda>!Window.__init__.<locals>.<lambda>  s    r3   c                    > T$ rY   r,   )r6   r   s    r/   ro  rp    s    &r3   c                     / $ rY   r,   )r6   s    r/   ro  rp    s    r3      )maxsizer   )r[   r	   r   re   r'   rd   r   allow_scroll_beyond_bottomalways_hide_cursorr  
cursorlinecursorcolumnr   dont_extend_widthdont_extend_heightleft_marginsright_marginsscroll_offsetsget_vertical_scrollget_horizontal_scrollr   r   get_colorcolumnscursorline_tokencursorcolumn_tokenr   _ui_content_cache_margin_width_cacher0   )r.   r   r<   r   r   r   ry  rz  r{  r|  r}  ru  r  r~  r  rv  rw  rx  r  r  r  s     ``                 r/   rk   Window.__init__|  s
    '9----}
5/ B BBB~FO!D!DDD HY$7$777!Xj%9%999}	 111~!333%NM)R)RRR#s*W,*W'W'WWW$+Y=+Y(Y(YYY"*h7J.K.KKK$,9N0O0OOO'84D+E+EEE*78R*S'"/0B"C'
3'
3),7!2"4(.B*0b,?#6 %:"6$5!9&8 0 D^ 0"4 "-Q!7#.q#9 

r3   c                      SU R                   -  $ )NzWindow(content=%r)r   r-   s    r/   r   Window.__repr__  s    #dll22r3   c                 p    U R                   R                  5         SU l        SU l        SU l        S U l        g ro   )r   r0   r  r  vertical_scroll_2render_infor-   s    r/   r0   Window.reset  s8      !!"
 "#  r3   c                 z   ^ ^^^ UU 4S jmUUU4S jnTTR                   4nT R                  R                  XC5      $ )zJ
Return the width for this margin.
(Calculate only once per render time.)
c                  &   > TR                  T SSS9$ )Nr   r<   r   )_get_ui_content)r6   r.   s   r/   get_ui_content0Window._get_margin_width.<locals>.get_ui_content  s    ''1Q'??r3   c                  (   > TR                  T T5      $ rY   )r   )r6   r  margins   r/   r   +Window._get_margin_width.<locals>.get_width  s    ##C88r3   )render_counterr  get)r.   r6   r  r   keyr  s   ```  @r/   _get_margin_widthWindow._get_margin_width  s7    	@	9 s))*''++C;;r3   c                    ^ ^ [        UU 4S jT R                  T R                  -    5       5      nT R                  R	                  TX#-
  5      nUb  XC-  nT R                  T R                  T5      UT R                  S9$ )Nc              3   H   >#    U  H  nTR                  TU5      v   M     g 7frY   r  r]   rk  r6   r.   s     r/   r_   )Window.preferred_width.<locals>.<genexpr>  +      !I!G EF!7!7Q!?!?!G   "	dimensionr   dont_extend)r   r{  r|  r   r8   _merge_dimensionsr   ry  )r.   r6   r7   total_margin_widthr8   s   ``   r/   r8   Window.preferred_width  s      !I!%!2!2T5G5G!G!I I ,,66$9; &1O %%kk#&%.. & 0 	0r3   c           	        ^ ^ [        UU 4S jT R                  T R                  -    5       5      nT R                  T5      nT R	                  T R                  T5      T R                  R                  TX$-
  X55      T R                  S9$ )Nc              3   H   >#    U  H  nTR                  TU5      v   M     g 7frY   r  r  s     r/   r_   *Window.preferred_height.<locals>.<genexpr>  r  r  r  )	r   r{  r|  r  r  r   r   r>   rz  )r.   r6   r<   r=   r  r  s   ``    r/   r>   Window.preferred_height  s      !I!%!2!2T5G5G!G!I I__S)
%%ll3'll33U/1ES//	 & 1 	1r3   c                    U =(       d
    [        5       n U R                  (       a  U R                  nUbL  U R                  (       a  [	        XR                  5      nU R                  (       a  [        XR                  5      nU(       a  Ub  [	        U R                  U5      nOU R                  n[        U R                  UXR
                  S9$ )z
Take the LayoutDimension from this `Window` class and the received
preferred size from the `UIControl` and return a `LayoutDimension` to
report to the parent container.
)r   r   r   r   )r   preferred_specifiedr   r   r   r   )r  r   r  max_s       r/   r  Window._merge_dimensions  s     2!2	 ((!++I  }}	==9	}}	==9	 90y}}i0D==D4(8(8: 	:r3   c                 p   ^ ^^^ UUU U4S jnTR                   TT4nT R                  R                  XT5      $ )z 
Create a `UIContent` instance.
c                  :   > TR                   R                  T TTS9$ )Nr  )r   create_content)r6   r   r.   r<   s   r/   get_content+Window._get_ui_content.<locals>.get_content  s    <<..s%.OOr3   )r  r  r  )r.   r6   r<   r   r  r  s   ````  r/   r  Window._get_ui_content  s:    	P 	P !!5&1%%))#;;r3   c                     UR                   (       a  gUR                  R                  (       a2  UR                  R                  (       a  UR                  R                  $ gg)z2Return `False`, or the Digraph symbol to be used. ^?F)quoted_insertvi_statewaiting_for_digraphdigraph_symbol1rH   s     r/   _get_digraph_charWindow._get_digraph_char  s>    <<++||++||333r3   c                 (  ^ ^^^^ T R                    Vs/ s H  nT R                  TU5      PM     nnT R                   Vs/ s H  nT R                  TU5      PM     nn[        Xg-   5      nT R                  R                  TTR                  U-
  TR                  5      n	[        U	[        5      (       d   eT R                  T5      n
U
(       a  T R                  OT R                  nU" U	TR                  U-
  TR                  T5        T R                  TXT[        U5      TR                  U-
  T R                  T R                  T R                  R!                  T5      U
ST R"                  T R%                  T5      S9u  mmTR&                  [        U5      -   nTR(                  n[+        U	T R                  T R                  TR                  U-
  TR                  T R,                  TTUUU
S9T l        UU UU4S jnUR1                  TR&                  [        U5      -   TR&                  TR                  -   U-
  TR(                  TR(                  TR                  -   US9  SnUU U4S jn[3        T R                   U5       H*  u  nnU" UU5      nT R5                  TUUTUU5        UU-  nM,     TR                  [        U5      -
  n[3        T R                  U5       H*  u  nnU" UU5      nT R5                  TUUTUU5        UU-  nM,     gs  snf s  snf )	z
Write window to screen. This renders the user control, the margins and
copies everything over to the absolute position at the given screen.
T)	has_focusr  highlight_linesr  rv  )r  r  r  r  r  r  r  r  r  r  r  c           
      T  > [        S T	R                  5        5       5      nUR                  R                  nUR                  R                  nTR
                  [        T5      -   S-
  n[        XS5      nUS:  a?   X#U4   u  pgT
R                  R                  U [        [        XvS9UR                  S95      nO6T
R                  R                  U [        [        SSS9UR                  S95      nU[        :X  a  T
R                  X5      $ U$ ! [         a    US-  n Of = fUS:  a  M  Nq)ziWrapper around the mouse_handler of the `UIControl` that turns
screen coordinates into line coordinates. c              3   ,   #    U  H
  u  pX!4v   M     g 7frY   r,   )r]   r,  r-  s      r/   r_   @Window.write_to_screen.<locals>.mouse_handler.<locals>.<genexpr>W  s     H3G413Gs   r   r   r   )rd  
event_type)r   r   rd  r   r   r}   r   r   r   mouse_handlerr   r   r  KeyErrorNotImplemented_mouse_handler)r6   mouse_eventyx_to_rowcolr   r   max_yr   r%  r+  r  r.   r  rD   s            r/   r  -Window.write_to_screen.<locals>.mouse_handlerS  s/     H<3E3E3GHHL$$&&A$$&&A #''#.E*FFJEEAq&+qD1HC "\\77Z1D3>3I3IKLF  33UQ!_/:/E/EGH
 '**3<<M/    FA q&s   ;D DD)x_minx_maxy_miny_maxhandlerr   c                    > U R                  TTR                  UTR                  5      n[        R                  " U5      R                  TUS-   TR                  5      $ )z Render margin. Return `Screen`. r   )create_marginr  r   r
   rR   r  )rk  r<   tokensr6   r.   rD   s      r/   render_margin-Window.write_to_screen.<locals>.render_margin  sV     __S$*:*:E>CXCXYF $**62AAUQY 5 57 7r3   N)r{  r  r|  r   r   r  r<   r   r[   r   r  _scroll_when_linewrapping_scroll_without_linewrapping
_copy_bodyr  r  r  r  rv  r~   r}   r%   r}  r  set_mouse_handler_for_ranger   _copy_margin)r.   r6   rB   rC   rD   rk  left_margin_widthsright_margin_widthsr  r  r  scroll_funcr  r  r  move_xr  r<   margin_screenr  r  s   ``  `              @@r/   rE   Window.write_to_screen!  s    GKFWFWXFWd44S!<FWXGKGYGYZGY!t55c1=GYZ !3!IJ \\00%%(::N<Q<QS
*i0000 __S)
8Bd44HiHi,,/AA>CXCXZ]	_ 15^"#^%9%9<N%N  $"8"8ll,,S1!4"44#66s; 1@ 1=-  $$s+='>>$$+!"44 00'--0BB(//&*&9&9$;%!#'	 '	R 	22 %%,>(?? %%(<(<<?QQ %% %%(=(==! 	3 	# 	7 D--/ABHAu)!U3M c=&.&RWXeOF C  %%,?(@@D..0CDHAu)!U3M c=&.&RWXeOF Eg YZs   L
 Lc                 h  ^^^^^^^
^^^^^^^^^ TR                   U-   mTR                  mTR                  mTR                  m[        S[
        4   m[
        R                  m0 m0 mTR                  nU(       a@  [        TTTR                  -   5       H#  nTU   n[        TTT-   5       H  nUUU'   M
     M%     UUUUUUUUUUUUU
UUU4S jnU" 5       nU4S jnTR                  (       a  U" TR                  R                  TR                  R                  5      nU	(       a9  UTl
        U(       a  STl        OTR                  Tl        U R                  UT5        U(       a!  U R                  UTUTTTTR                  5        U	(       a#  TR                  (       a  U R!                  UT5        TR"                  (       dG  TR"                  (       a6  U" TR"                  R                  TR"                  R                  5      Tl        [%        TR                  TTR                  -   5      Tl	        TT4$ )z,
Copy the UIContent into the output screen.
 c                  T  > T* n TnU TR                   :  Ga  UT:  Ga  TR                  U5      nSnT* nUT4TU '   TU T-      nU GH:  u  pgUT:X  a"  TR                  U T-      UT-   ==   U-  ss'   M.  U GH  n[        X4   n	U	R                  n
T(       aA  XJ-   T:  a9  UTU    S   U-   4TU S-   '   U S-  n T* nTU T-      nU TR                   :  a  U s  s  $ US:  a  U S:  a  UTR                  :  a~  XUT-   '   U
S:  a  [        SU
5       H  nTXTT-   U-   '   M     OEU
S:X  a?  US-
  S:  a6  XTT-   S-
     n[        UR                  U-   UR                  4   nXUT-   S-
  '   U T-   UT-   4TX4'   US-  nXJ-  nGM     GM=     US-  nU S-  n U TR                   :  a	  UT:  a  GM  U $ )Nr   r   )r   get_linezero_width_escapesr   r<   r   r   r   )r   rL  liner%  r   new_buffer_rowr   textr^   r   
char_widthr   	prev_charchar2ZeroWidthEscape
empty_charr  r   
new_buffer
new_screenr  r  r  r  r  r<   r  rD   r~   r}   s                 r/   copyWindow._copy_body.<locals>.copy  s%   ##A$Fn+++0C!**62&&.46G-H'*!+AH!5#'KE /"55a$h?DITQI !*184%)ZZ
 &!.5*@ &(?(B1(E(I>K3AE:FA!2 2A-7D-AN N$9$99'( 6a1f^5I5I1I7;1t84  *A~).q*)=ACMNt8a<$@ *> ",qQUaZ,:t8a<,H	(3INNQ4F	4W(X?Dq4x!| < :;T1t88LL5qS " $(d !Q{ n+++0C| Hr3   c                 \   >  TX4   u  p#[        X#S9$ ! [         a    [        SSS9s $ f = f)z=Translate row/col from UIContent to real Screen coordinates. )r   r   r   )r   r  )r   r%  r   r   r  s       r/   cursor_pos_to_screen_pos3Window._copy_body.<locals>.cursor_pos_to_screen_pos  sA    '#CH- q&  ' qA&'s    ++F)r~   r}   r   r   r   r   r  default_charr   r   r   r   r   show_cursor_highlight_digraph_highlight_cursorlines _show_input_processor_key_bufferr   r   )r.   r6   r  r  rD   r  r<   r  r  r  r  r  r  rv  r  r   r  r   r  r  screen_cursor_positionr  r  r   r  r  r  r~   r}   s     ``` ``` ` `        @@@@@@@@r/   r  Window._copy_body  s    ""V+""**
++
 U+
// #% "..4(=(=!=>!+AtTE\2A(4N1% 3 ?B	 B	 B	H F	'" %%%=..00*2L2L2N2N&P" -C
*%-2J*-7-C-CJ*''Z8++%;T4"))+
 3311#zB ''J,D,D'?,,..
0H0H0J0J(LJ$  
 1 14.:O:O3OP
&44r3   c                     U R                  U5      nU(       aJ  UR                  n[        U[        R                  4   UR
                  UR                     UR                  '   gg)zL
When we are in Vi digraph mode, put a question mark underneath the
cursor.
N)r  r   r   r   Digraphr   r   r   )r.   r6   r  digraph_charr  s        r/   r  Window._highlight_digraph7  sU    
 --c2--DL%--78 ""466*4662 r3   c                 V   UR                   R                  nU(       a  [        U5      (       a{  UR                  (       di  US   R                  n[        U5      S:X  aJ  UR                  n[        U[        R                  4   UR                  UR                     UR                  '   ggggg)a8  
When the user is typing a key binding that consists of several keys,
display the last pressed key if the user is in insert mode and the key
is meaningful to be displayed.
E.g. Some people want to bind 'jj' to escape in Vi insert mode. But the
     first 'j' needs to be displayed in order to get some feedback.
r  r   N)input_processor
key_buffer_in_insert_modeis_donedatar   r   r   r   PartialKeyBindingr   r   r   )r.   r6   r  r  r  r  s         r/   r  'Window._show_input_processor_key_bufferB  s     ((33
/#..s{{ b>&&D $1$!11e&=&= => &&tvv.tvv6 % 8C.:r3   c                 
   SU R                   -   nSU R                  -   n	UR                  n
U R                  U5      (       aK  XR                     n[        XDU-   5       H+  nX   n[        UR                  UR                  U-   4   X'   M-     U R                  U5      (       aU  [        XUU-   5       HC  nX   nXR                     n[        UR                  UR                  U	-   4   XR                  '   ME     U R                  U5       Hx  n[        U[        5      (       d   eSUR                  -   nUR                  n[        XUU-   5       H1  nX   nUU   n[        UR                  UR                  U-   4   UU'   M3     Mz     g)z
Highlight cursor row/column.
):N)r  r  r   rw  r   r   r   r   r   rx  r   r  r[   r(   rd  )r.   r6   r  r  r   r   r<   r   cursor_line_tokencursor_column_tokenr   r   original_chary2cccolor_column_tokencolumns                    r/   r  Window._highlight_cursorlinesW  s    $d&;&;;%(?(?? ,, ??3ff%C1%i( #$!&&(;(;>O(OOQ ) S!!A6z*!o #FF) %%}':':=P'PPRFF + '',Bb+....!(288!3[[FA6z*!o #F) %%}':':=O'OOQF + -r3   c                     UR                   U-   nUR                  n[        XxXdR                  5      n	U R	                  XX9SU5        g)z<
Copy characters from the margin screen to the real screen.
r   N)r~   r}   r   r   r  )
r.   r6   lazy_screenr  rD   r  r<   r~   r}   margin_write_positions
             r/   r  Window._copy_margin|  sE     ""V+"" -d%AVAV W*QPUVr3   c                   ^^^^^ U R                   R                  mU R                   R                  mSU l        TR	                  TR
                  R                  T5      TT-
  :  a  [        TR                  TR
                  R                  5      5      n[        USTR
                  R                  S-    5      n[        R                  " UT5      nTR
                  R                  U l        [        US-
  U R                  5      U l        [!        SUT-
  U R                  5      U l        gSU l        UUUU4S jnUUU4S jn	UUU4S jn
U
" 5       n[!        U R                  [        X" 5       5      5      U l        [        U R                  U	" 5       5      U l        U R#                  U5      (       d  [        U R                  U5      U l        gg)
Scroll to make sure the cursor position is visible and that we maintain
the requested scroll offset.

Set `self.horizontal_scroll/vertical_scroll`.
r   Nr   c                     > Sn TR                   R                  n[        TR                   R                  SS5       H'  nU TR                  UT5      -  n U TT-
  :  a  Us  $ UnM)     g)Nr   r  r   r   r   rK  )used_heightprev_linenorL  r   scroll_offsets_bottomr  r<   s      r/   get_min_vertical_scrollAWindow._scroll_when_linewrapping.<locals>.get_min_vertical_scroll  sp     K$4466K
 : : < <b"Ez==feLL*?!??&&"(K F r3   c                     > TR                   R                  n Sn[        TR                   R                  S-
  SS5       H$  nUTR                  UT5      -  nUT:  a  U s  $ Un M&     U $ )Nr   r   r  r  )r  r  rL  scroll_offsets_topr  r<   s      r/   get_max_vertical_scrollAWindow._scroll_when_linewrapping.<locals>.get_max_vertical_scroll  sq    $4466KK
 : : < <q @"bIz==feLL!33&&"(K J r3   c                     > TR                   S-
  n Sn[        TR                   S-
  SS5       H$  nUTR                  UT5      -  nUT:  a  U s  $ Un M&     U $ )z
Calculate the upper most line that can be visible, while the bottom
is still visible. We should not allow scroll more than this if
`allow_scroll_beyond_bottom` is false.
r   r   r  )r   r   rK  )r  r  rL  r   r  r<   s      r/   get_topmost_visible=Window._scroll_when_linewrapping.<locals>.get_topmost_visible  sk     %//!3KK
 5 5 92rBz==feLL'&&"(K C r3   )r}  r   r   r  rK  r   r   r   r  r   r   r   get_height_for_textr  r   r  r   ru  )r.   r  r<   r   r6   r  text_before_cursortext_before_heightr  r"  r%  topmost_visibler  r!  s    ```        @@r/   r   Window._scroll_when_linewrapping  s    !% 3 3 : :!0044 "# ))**D*D*F*FNQWZlQll "*"5"5j6P6P6R6R"STD!3D9Z*:T:T:V:VYZ:Z4[!\!*!>!>?QSX!Y $.#=#=#?#?D %();a)?AWAW%XD"%(,>,GI_I_%`D"%&D"	 			$ ./
  #4#7#7_NeNg9hi"4#7#79P9RS ..s33#&t';';_#MD  4r3   c                   ^ ^ UR                   =(       d    [        SS5      nST l        UR                  S:X  a  ST l        ST l        g[        UR                  UR                  5      5      nUU 4S jnT R                  (       a7  T R                  T 5      T l        [        T R                  [        5      (       d   eT R                  (       a7  T R                  T 5      T l        [        T R
                  [        5      (       d   eT R                  nU" T R                  UR                  UR                  UR                   R                  UUR                  S9T l        U" T R
                  UR                   UR"                  [%        USUR                   R&                   5      U[)        [%        U5      T R
                  U-   5      S9T l        g)r  r   Nc                 :  > [        [        XS-  U5      5      n[        [        X$S-  US-
  U-
  5      5      nU S:  a  Sn TR                  T5      (       d  XU-
  :  a  [        SXT-
  5      n XU-
  :  a  [        SX1-
  5      n XS-   U-
  U-   :  a  US-   U-
  U-   n U $ )zFScrolling algorithm. Used for both horizontal and vertical scrolling. r   r   r   )r   r   ru  r   )current_scrollscroll_offset_startscroll_offset_end
cursor_poswindow_sizecontent_sizer6   r.   s         r/   	do_scroll6Window._scroll_without_linewrapping.<locals>.do_scroll  s     #&c*=QPZ&["\ #C(9?(4q(8:(E%G !H !!" 33C88"K%??!$Q(B!C -@ @@!$Q
(H!I a; >AR RR",q.K!?BS!S!!r3   )r.  r/  r0  r1  r2  r3  )r   r   r  r   r  r  r   r  r   r~  r[   r   r  r}  r   r   r   r   r   r   r   )	r.   r  r<   r   r6   r   current_line_textr4  offsetss	   `   `    r/   r  #Window._scroll_without_linewrapping  s    %44Ca "#  A%#$D %&D" 2:3F3FGXGX3Y Z	"< ###'#;#;D#AD d22C8888%%%)%?%?%ED"d44c:::: %%(// '%nn!1133#.. 0 "+11 '%mm!"34QZ5O5O5Q5Q"RS Z(9:D<R<RUZ<Z["]r3   c                     UR                   [        R                  :X  a  U R                  U5        gUR                   [        R                  :X  a  U R                  U5        gg)zQ
Mouse handler. Called when the UI control doesn't handle this
particular event.
N)r  r   SCROLL_DOWN_scroll_down	SCROLL_UP
_scroll_up)r.   r6   r  s      r/   r  Window._mouse_handler3  sL    
 !!^%?%??c"##~'?'??OOC  @r3   c                 (   U R                   nU R                  UR                  UR                  -
  :  a_  UR                  R
                  UR                  R                  ::  a  U R                  R                  U5        U =R                  S-  sl        gg)zScroll window down. r   N)
r  r  r;  r  r   r   r  r   r   move_cursor_downr.   r6   infos      r/   r;  Window._scroll_down=  su    $"5"58J8J"JJ##%%)G)G)K)KK--c2  A% 	 Kr3   c                    U R                   nUR                  S:  ao  UR                  R                  UR                  S-
  UR
                  R                  -
  :  a  U R                  R                  U5        U =R                  S-  sl        gg)zScroll window up. r   r   N)	r  r  r   r   r  r  r   r   move_cursor_uprA  s      r/   r=  Window._scroll_upG  ss    !###%%););a)?$B`B`BgBg)gg++C0  A%  $r3   c              #      #    U v   g 7frY   r,   rH   s     r/   rI   Window.walkR  s
     
s   )r   r  r  r   ru  rv  r   rx  r  rw  r  rz  ry  r  r  r~  r  r{  r  r|  r}  r  r  r  )NF)r   r   FFFr   F)rK   rL   rM   rN   rO   r   
CursorLineCursorColumnrk   r   r0   r  r8   r>   staticmethodr  r  r  rE   r  r  r  r  r  r  r  r  r;  r=  rI   rP   r,   r3   r/   r$   r$   H  s    2f '+44 Ee"$t,1e%)Z_!"'"2"2uGYGY-^3  <0&	1 : :B<D @AFK;@S5j	9?*#QJW\N|M]^!&	&r3   r$   c                   B    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
rg)r&   iW  a  
Wrapper around any other container that can change the visibility. The
received `filter` determines whether the given container should be
displayed or not.

:param content: :class:`.Container` instance.
:param filter: :class:`~prompt_toolkit.filters.CLIFilter` instance.
c                 ^    [        U[        5      (       d   eXl        [        U5      U l        g rY   )r[   r   r   r   filter)r.   r   rN  s      r/   rk   ConditionalContainer.__init__`  s&    '9----#F+r3   c                 @    SU R                   < SU R                  < S3$ )NzConditionalContainer(z	, filter=r_  r   rN  r-   s    r/   r   ConditionalContainer.__repr__f  s    8<dkkRRr3   c                 8    U R                   R                  5         g rY   )r   r0   r-   s    r/   r0   ConditionalContainer.reseti  s    r3   c                     U R                  U5      (       a  U R                  R                  X5      $ [        R                  " S5      $ ro   )rN  r   r8   r   exactr5   s      r/   r8   $ConditionalContainer.preferred_widthl  s7    ;;s<<//II"((++r3   c                     U R                  U5      (       a  U R                  R                  XU5      $ [        R                  " S5      $ ro   )rN  r   r>   r   rV  r;   s       r/   r>   %ConditionalContainer.preferred_heightr  s:    ;;s<<00=QRR"((++r3   c                 h    U R                  U5      (       a  U R                  R                  XX45      $ g rY   )rN  r   rE   rA   s        r/   rE   $ConditionalContainer.write_to_screenx  s-    ;;s<<//^\\ r3   c                 8    U R                   R                  U5      $ rY   )r   rI   rH   s     r/   rI   ConditionalContainer.walk|  s    ||  %%r3   rQ  N)rK   rL   rM   rN   rO   rk   r   r0   r8   r>   rE   rI   rP   r,   r3   r/   r&   r&   W  s,    ,S,,]&r3   r&   N);rO   
__future__r   abcr   r   sixr   	six.movesr   controlsr	   r
   r   r  r   r   r   marginsr   rB   r   r   r   utilsr   r   prompt_toolkit.cacher   prompt_toolkit.filtersr   r   r   prompt_toolkit.mouse_eventsr   r   prompt_toolkit.reactiver   prompt_toolkit.tokenr   prompt_toolkit.utilsr   r   __all__r   objectr   rT   r    r!   r"   r#   r%   r'   r(   r  r$   r&   Layoutr,   r3   r/   <module>rn     s   ( '   < < T T  5 5 5 , O O B + & ? +w/ +\<~Y ~BHY HVwY wt-2F -2`Ev EP#:F #:L&  .?#44LY L^&&9 &&T 
r3   