
    ^h@K                        S SK J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  SSKJrJrJrJr  SS	KJrJr  SS
KJrJrJr  S/rSr " S S\5      rg)    )annotations)Point)FilterOrBool	to_filter)KeyBindingsBase)
MouseEvent   )	ContainerScrollOffsets)AnyDimension	Dimensionsum_layout_dimensionsto_dimension)MouseHandlerMouseHandlers)CharScreenWritePositionScrollablePanei'  c            
      x   \ rS rSrSrSSS\SSSSSS4
                       SS jjrSS jrSS	 jrSS
 jr	SS jr
              SS jr      SS jr          SS jr          SS jr        S S jrS!S jrS"S jrS#S jr          S$S jr        S%S jrSrg)&r      a  
Container widget that exposes a larger virtual screen to its content and
displays it in a vertical scrollbale region.

Typically this is wrapped in a large `HSplit` container. Make sure in that
case to not specify a `height` dimension of the `HSplit`, so that it will
scale according to the content.

.. note::

    If you want to display a completion menu for widgets in this
    `ScrollablePane`, then it's still a good practice to use a
    `FloatContainer` with a `CompletionsMenu` in a `Float` at the top-level
    of the layout hierarchy, rather then nesting a `FloatContainer` in this
    `ScrollablePane`. (Otherwise, it's possible that the completion menu
    is clipped.)

:param content: The content container.
:param scrolloffset: Try to keep the cursor within this distance from the
    top/bottom (left/right offset is not used).
:param keep_cursor_visible: When `True`, automatically scroll the pane so
    that the cursor (of the focused window) is always visible.
:param keep_focused_window_visible: When `True`, automatically scroll the
    pane so that the focused window is visible, or as much visible as
    possible if it doesn't completely fit the screen.
:param max_available_height: Always constraint the height to this amount
    for performance reasons.
:param width: When given, use this width instead of looking at the children.
:param height: When given, use this height instead of looking at the children.
:param show_scrollbar: When `True` display a scrollbar on the right.
NT^vc                
   Xl         U=(       d
    [        SSS9U l        [        U5      U l        [        U5      U l        XPl        X`l        Xpl        [        U5      U l	        [        U	5      U l
        Xl        Xl        SU l        g )Nr	   )topbottomr   )contentr   scroll_offsetsr   keep_cursor_visiblekeep_focused_window_visiblemax_available_heightwidthheightshow_scrollbardisplay_arrowsup_arrow_symboldown_arrow_symbolvertical_scroll)selfr   r   r   r    r!   r"   r#   r$   r%   r&   r'   s               _/home/james-whalen/.local/lib/python3.13/site-packages/prompt_toolkit/layout/scrollable_pane.py__init__ScrollablePane.__init__4   sw     ,N!A0N#,-@#A +45P+Q($8!
'7'7.!2     c                $    SU R                   < S3$ )NzScrollablePane()r   r)   s    r*   __repr__ScrollablePane.__repr__P   s      022r-   c                8    U R                   R                  5         g N)r   resetr1   s    r*   r6   ScrollablePane.resetS   s    r-   c                    U R                   b  [        U R                   5      $ U R                  R                  U5      nU R	                  5       (       a!  [        [        R                  " S5      U/5      $ U$ )Nr	   )r"   r   r   preferred_widthr$   r   r   exact)r)   max_available_widthcontent_widths      r*   r9   ScrollablePane.preferred_widthV   sb    ::!

++ 445HI   ()//!*<m)LMMr-   c                    U R                   b  [        U R                   5      $ U R                  5       (       a  US-  nU R                  R	                  XR
                  5      n[        SUR                  S9$ )Nr	   r   )min	preferred)r#   r   r$   r   preferred_heightr!   r   r@   )r)   r"   r!   	dimensions       r*   rA   ScrollablePane.preferred_heightd   sd    ;;",,   QJELL11%9R9RS	 Q)*=*=>>r-   c                   U R                  5       nU(       a  UR                  S-
  nOUR                  nU R                  R                  XR                  5      R
                  n	[        XR                  5      n	[        XR                  5      n	[        [        SUS9S9n
UR                  U
l        [        SSXS9n[        5       nU R                  R                  U
UUUUU5        U
R                  5         SSKJn  U" 5       R$                  R&                  n U
R(                  U   nU R+                  UR                  U	UU
R,                  R/                  U5      5        U R3                  XX85        U R5                  X,X85        UR6                  nUR8                  n[        UR                  UU-   5      Ul        [        UR                  UUR                  -   5      Ul        U R;                  XU5        U
R                  (       a  SUl        U
R,                  R=                  5        H  u  nnSUR>                  s=::  a  UR                  :  d  M)  O  M-  U R@                  URB                  s=::  a  UR                  U R@                  -   :  d  Mg  O  Mk  [E        UR>                  U-   URB                  U-   U R@                  -
  S	9UR,                  U'   M     U
RF                  R=                  5        HT  u  nnU RI                  [E        UR>                  U-   URB                  U-   U R@                  -
  S	9U5      URF                  U'   MV     U(       a  U RK                  UU	U5        g
g
! [0         a     GNf = f)zx
Render scrollable pane content.

This works by rendering on an off-screen canvas, and copying over the
visible region.
r	    )charstyle)default_charr   )xposyposr"   r#   )get_appTxyN)&r$   r"   r   rA   r!   r@   maxr#   r?   r   r   show_cursorr   r   write_to_screendraw_all_floatsprompt_toolkit.applicationrK   layoutcurrent_window"visible_windows_to_write_positions_make_window_visiblecursor_positionsgetKeyError_copy_over_screen_copy_over_mouse_handlersrJ   rI   _copy_over_write_positionsitemsrM   r(   rN   r   menu_positions_clip_point_to_visible_area_draw_scrollbar)r)   screenmouse_handlerswrite_positionparent_styleerase_bgz_indexr$   virtual_widthvirtual_heighttemp_screentemp_write_positiontemp_mouse_handlersrK   focused_windowvisible_win_write_posrJ   rI   windowpoints                       r*   rQ   ScrollablePane.write_to_screens   s    ,,.*0014M*00M 6644

) 	
 ^-B-BC^-F-FG $C|*LM"("4"4+-
 ,o$$	
 	##% 	7 ))88	$/$R$R%! %%%%%,,00@	 	vNR 	&&	

 """"6<<)=>FMM4.2G2G+GH 	''^L""!%F )99??AMFEUWW3~3333((77? ''$*>*>>? ? 38ggn$9M9M(M3''/ B )77==?MFE,0,L,L$%''D.4;O;O*OP-F!!&) @    i  		s   M 
M+*M+c                   UR                   UR                  :  a  UR                  UR                  S9nUR                  UR                  :  a  UR                  UR                  S9nUR                   UR                  UR
                  -   :  a)  UR                  UR                  UR
                  -   S-
  S9nUR                  UR                  UR                  -   :  a)  UR                  UR                  UR                  -   S-
  S9nU$ )zF
Ensure that the cursor and menu positions always are always reported
)rM   )rN   r	   )rM   rI   _replacerN   rJ   r"   r#   )r)   rp   rd   s      r*   r`   *ScrollablePane._clip_point_to_visible_area   s     77^(((NN^%8%8N9E77^(((NN^%8%8N9E77n))N,@,@@@NN^%8%8>;O;O%ORS%SNTE77n))N,A,AAANN^%8%8>;P;P%PST%TNUEr-   c                r   UR                   nUR                  n[        UR                  5       H  nUR                  XpR
                  -      nUR                  Xu-      n	UR                  XpR
                  -      n
UR                  Xu-      n[        U5       H  nX   XU-   '   X;   d  M  X   XU-   '   M     M     g)zE
Copy over visible screen content and "zero width escape sequences".
N)rJ   rI   ranger#   data_bufferr(   zero_width_escapes)r)   rb   rj   rd   rh   rJ   rI   rN   temp_rowrowtemp_zero_width_escapesrx   rM   s                r*   r[    ScrollablePane._copy_over_screen   s     """"~,,-A"..q3G3G/GHH$$QX.C&1&D&D((('# "(!:!:18!D=) (H/3J3M&4x0	 * .r-   c                L  ^ ^^^ UR                   mUR                  m0 mSUU UU4S jjnUR                  nUR                  n[        UR                  5       HJ  nX;   d  M
  XxT R
                  -      n	XhT-      n
[        U5       H  nX;   d  M
  U" X   5      XT-   '   M     ML     g)z
Copy over mouse handlers from virtual screen to real screen.

Note: we take `virtual_width` because we don't want to copy over mouse
      handlers that we possibly have behind the scrollbar.
c                <   >^  T T;  a  SU UUU4S jjnUTT '   TT    $ )z:Wrap mouse handler. Translate coordinates in `MouseEvent`.c                   > [        [        U R                  R                  T-
  U R                  R                  TR
                  -   T-
  S9U R                  U R                  U R                  S9nT" U5        g )NrL   )position
event_typebutton	modifiers)	r   r   r   rM   rN   r(   r   r   r   )event	new_eventhandlerr)   rI   rJ   s     r*   new_handlerYScrollablePane._copy_over_mouse_handlers.<locals>.wrap_mouse_handler.<locals>.new_handler.  sg     *!&#nn..5#nn..1E1EEL" $)#3#3$||"'//!I I&r-   )r   r   returnNone )r   r   mouse_handler_wrappersr)   rI   rJ   s   ` r*   wrap_mouse_handlerDScrollablePane._copy_over_mouse_handlers.<locals>.wrap_mouse_handler*  s.    44
' 
' 3>&w/)'22r-   N)r   r   r   r   )rJ   rI   rc   rv   r#   r(   )r)   rc   rl   rd   rh   r   mouse_handlers_dicttemp_mouse_handlers_dictrN   temp_mouse_row	mouse_rowrM   r   rI   rJ   s   `           @@@r*   r\   (ScrollablePane._copy_over_mouse_handlers  s     """" DF	3 	3( -;;#6#E#E ~,,-A,!9d>R>R:R!S/D9	}-A*.@AR.S	d(+ .	 .r-   c                "   UR                   nUR                  nUR                  R                  5        HY  u  pg[	        UR                  U-   UR                   U-   U R
                  -
  UR                  UR                  S9UR                  U'   M[     g)z#
Copy over window write positions.
)rI   rJ   r#   r"   N)rJ   rI   rV   r^   r   r(   r#   r"   )r)   rb   rj   rd   rJ   rI   win	write_poss           r*   r]   )ScrollablePane._copy_over_write_positionsI  s     """")LLRRTNC=J^^d*^^d*T-A-AA !''oo>F55c: Ur-   c                6    U R                   R                  5       $ r5   )r   is_modalr1   s    r*   r   ScrollablePane.is_modal\  s    ||$$&&r-   c                6    U R                   R                  5       $ r5   )r   get_key_bindingsr1   s    r*   r   ScrollablePane.get_key_bindings_  s    ||,,..r-   c                    U R                   /$ r5   r0   r1   s    r*   get_childrenScrollablePane.get_childrenb  s    ~r-   c                   SnX!-
  nU R                  5       (       ag  Ubd  U R                  nUR                  U-
  S-   UR                  -   nUR                  UR                  -
  n	[        XX5      n[        S[        Xi5      5      nU R                  5       (       aw  UR                  U::  a)  UR                  UR                  -   U-
  n
UR                  nO(UR                  n
UR                  UR                  -   U-
  n[        XZ5      n[        Xk5      nXV:  a  UnU R                  U:  a  X`l
        U R                  U:  a  XPl
        gg)a  
Scroll the scrollable pane, so that this window becomes visible.

:param visible_height: Height of this `ScrollablePane` that is rendered.
:param virtual_height: Height of the virtual, temp screen.
:param visible_win_write_pos: `WritePosition` of the nested window on the
    temp screen.
:param cursor_position: The location of the cursor position of this
    window on the temp screen.
r   Nr	   )r   r   rN   r   r   rO   r?   r    r#   rJ   r(   )r)   visible_heightri   rn   cursor_position
min_scroll
max_scrolloffsetscpos_min_scrollcpos_max_scrollwindow_min_scrollwindow_max_scrolls               r*   rW   #ScrollablePane._make_window_visiblee  sV   & 
#4
##%%*--#%%6:W^^K   #2"3"3gkk"A =
 C
$DE
++-- %++~=)..+223$% "
 %:$>$>! %:$>$>!)..+223$% " Z;JZ;J"#J *,#- *,#-  -r-   c           
       ^^ UR                   nU R                  5       nU(       a  US-  n UR                   [        U5      -  nU R                  [        U5      -  n[	        [        U[        SXF-  5      5      5      m[	        XG-  5      mSUU4S jjnUR                  UR                  -   S-
  n	UR                  n
UR                  nU(       a   [        U R                  S5      X   U	'   U
S-  n
SnSnSnSn[        U5       HS  nS	nU" U5      (       a  U" US-   5      (       d  UnOUnOU" US-   5      (       a  UnOUn[        S
U5      X   U	'   U
S-  n
MU     U(       a  [        U R                  S5      X   U	'   gg! [         a     gf = f)zz
Draw the scrollbar on the screen.

Note: There is some code duplication with the `ScrollbarMargin`
      implementation.
   r	   c                4   > TU s=:*  =(       a    TT-   :*  $ s  $ )z/True if we should display a button on this row.r   )rz   scrollbar_heightscrollbar_tops    r*   is_scroll_button8ScrollablePane._draw_scrollbar.<locals>.is_scroll_button  s"    $OO}?O/OOOOOr-   zclass:scrollbar.arrowzclass:scrollbar.backgroundz*class:scrollbar.background,scrollbar.startzclass:scrollbar.buttonz$class:scrollbar.button,scrollbar.end rE   N)rz   intr   bool)r#   r%   floatr(   r   r?   rO   rI   r"   rJ   rw   r   r&   rv   r'   ZeroDivisionError)r)   rd   content_heightrb   window_heightr%   fraction_visiblefraction_abover   rI   rJ   rw   scrollbar_backgroundscrollbar_background_startscrollbar_buttonscrollbar_button_endirG   r   r   s                     @@r*   ra   ScrollablePane._draw_scrollbar  s    '--,,.QM7	-44u^7LL!11E.4IIN"M3q-*J#KL    >?M
P P "&&)=)==AD!&&D ,,K *.((*A+!$' 	 $@ )U&7#I =)#A&&+AE22 !5 0'A.. : 4*.sE*:!$'	! *& *.**,C+!$' Y ! 		s   AE< <
F	F	)r   r%   r'   r#   r   r    r!   r   r$   r&   r(   r"   )r   r
   r   zScrollOffsets | Noner   r   r    r   r!   r   r"   r   r#   r   r$   r   r%   r   r&   strr'   r   r   r   )r   r   )r   r   )r;   r   r   r   )r"   r   r!   r   r   r   )rb   r   rc   r   rd   r   re   r   rf   r   rg   z
int | Noner   r   )rp   r   rd   r   r   r   )
rb   r   rj   r   rd   r   rh   r   r   r   )
rc   r   rl   r   rd   r   rh   r   r   r   )rb   r   rj   r   rd   r   r   r   )r   r   )r   zKeyBindingsBase | None)r   zlist[Container])
r   r   ri   r   rn   r   r   zPoint | Noner   r   )rd   r   r   r   rb   r   r   r   )__name__
__module____qualname____firstlineno____doc__MAX_AVAILABLE_HEIGHTr+   r2   r6   r9   rA   rQ   r`   r[   r\   r]   r   r   r   rW   ra   __static_attributes__r   r-   r*   r   r      s7   F 04,048$8"#'+'+"!$!! -! *	!
 &2! "! ! ! %! %! ! ! 
!83?uu &u &	u
 u u u 
un,9	"NN N &	N
 N 
N61T%1T +1T &	1T
 1T 
1Tf+1CP	&'/@.@. @.  -	@.
 &@. 
@.DG+G=@GJPG	Gr-   N)
__future__r   prompt_toolkit.data_structuresr   prompt_toolkit.filtersr   r   prompt_toolkit.key_bindingr   prompt_toolkit.mouse_eventsr   
containersr
   r   rB   r   r   r   r   rc   r   r   rb   r   r   r   __all__r   r   r   r-   r*   <module>r      sD    " 0 : 6 2 0 S S 7 / /
  [Y [r-   