
    f@K                        d dl m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mZ ddlmZmZmZmZ dd	lmZmZ dd
lmZmZmZ dgZdZ G d de      Zy)    )annotations)Point)FilterOrBool	to_filter)KeyBindingsBase)
MouseEvent   )	ContainerScrollOffsets)AnyDimension	Dimensionsum_layout_dimensionsto_dimension)MouseHandlerMouseHandlers)CharScreenWritePositionScrollablePanei'  c            
      P   e Zd ZdZdddeddddddf
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZddZdd	Zdd
Z		 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ
	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 ddZddZd dZd!dZ	 	 	 	 	 	 	 	 	 	 d"dZ	 	 	 	 	 	 	 	 d#dZy)$r   aK  
    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s t        dd      | _        t        |      | _        t        |      | _        || _        || _        || _        t        |      | _	        t        |	      | _
        |
| _        || _        d| _        y )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               `/var/www/cvtools/html/venv/lib/python3.12/site-packages/prompt_toolkit/layout/scrollable_pane.py__init__zScrollablePane.__init__4   s     ,N!A0N#,-@#A +45P+Q($8!
'7'7.!2     c                "    d| j                   dS )NzScrollablePane()r   r(   s    r)   __repr__zScrollablePane.__repr__P   s      022r+   c                8    | j                   j                          y N)r   resetr/   s    r)   r3   zScrollablePane.resetS   s    r+   c                    | j                   t        | j                         S | j                  j                  |      }| j	                         r t        t        j                  d      |g      S |S )Nr	   )r!   r   r   preferred_widthr#   r   r   exact)r(   max_available_widthcontent_widths      r)   r5   zScrollablePane.preferred_widthV   s_    ::!

++ 445HI  ()//!*<m)LMMr+   c                    | j                   t        | j                         S | j                         r|dz  }| j                  j	                  || j
                        }t        d|j                        S )Nr	   r   )min	preferred)r"   r   r#   r   preferred_heightr    r   r;   )r(   r!   r    	dimensions       r)   r<   zScrollablePane.preferred_heightd   sc    ;;",,  QJELL11%9R9RS	 Q)*=*=>>r+   c                   | j                         }|r|j                  dz
  }n|j                  }| j                  j                  || j                        j
                  }	t        |	|j                        }	t        |	| j                        }	t        t        d|            }
|j                  |
_        t        dd||	      }t               }| j                  j                  |
|||||       |
j                          ddlm}  |       j$                  j&                  }	 |
j(                  |   }| j+                  |j                  |	||
j,                  j/                  |             | j3                  ||
||       | j5                  ||||       |j6                  }|j8                  }t        |j                  ||z         |_        t        |j                  ||j                  z         |_        | j;                  ||
|       |
j                  rd|_        |
j,                  j=                         D ]  \  }}d|j>                  cxk  r|j                  k  s&n )| j@                  |jB                  cxk  r|j                  | j@                  z   k  s`n ctE        |j>                  |z   |jB                  |z   | j@                  z
  	      |j,                  |<    |
jF                  j=                         D ]V  \  }}| jI                  tE        |j>                  |z   |jB                  |z   | j@                  z
  	      |      |jF                  |<   X |r| jK                  ||	|       y
y
# t0        $ r Y w xY w)z
        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   r<   r    r;   maxr"   r:   r   r   show_cursorr   r   write_to_screendraw_all_floatsprompt_toolkit.applicationrE   layoutcurrent_window"visible_windows_to_write_positions_make_window_visiblecursor_positionsgetKeyError_copy_over_screen_copy_over_mouse_handlersrD   rC   _copy_over_write_positionsitemsrG   r'   rH   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_handlersrE   focused_windowvisible_win_write_posrD   rC   windowpoints                       r)   rK   zScrollablePane.write_to_screens   s2    ,,.*0014M*00M 66444

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

 """"6<<)=>FMM4.2G2G+GH 	''^L""!%F )99??A 		MFEUWW3~333((77? ''$*>*>>? 38ggn$9M9M(M3''/		 )77==? 	MFE,0,L,L$%''D.4;O;O*OP-F!!&)	    i  		s   M 	M'&M'c                "   |j                   |j                  k  r|j                  |j                        }|j                  |j                  k  r|j                  |j                        }|j                   |j                  |j
                  z   k\  r,|j                  |j                  |j
                  z   dz
        }|j                  |j                  |j                  z   k\  r,|j                  |j                  |j                  z   dz
        }|S )zV
        Ensure that the cursor and menu positions always are always reported
        )rG   )rH   r	   )rG   rC   _replacerH   rD   r!   r"   )r(   rj   r^   s      r)   rZ   z*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                v   |j                   }|j                  }t        |j                        D ]  }|j                  || j
                  z      }|j                  ||z      }	|j                  || j
                  z      }
|j                  ||z      }t        |      D ]  }||   |	||z   <   ||
v s|
|   |||z   <     y)zU
        Copy over visible screen content and "zero width escape sequences".
        N)rD   rC   ranger"   data_bufferr'   zero_width_escapes)r(   r\   rd   r^   rb   rD   rC   rH   temp_rowrowtemp_zero_width_escapesrp   rG   s                r)   rU   z ScrollablePane._copy_over_screen   s     """"~,,- 	NA"..q43G3G/GHH$$QX.C&1&D&DD((('# "(!:!:1t8!D=) N (AH//3J13M&q4x0	N	Nr+   c                @    |j                   |j                  i d fd}|j                  }|j                  }t        |j                        D ]G  }||v s|| j
                  z      }	||z      }
t        |      D ]  }||	v s ||	|         |
|z   <    I y)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                4      vrd fd}| <       S )z:Wrap mouse handler. Translate coordinates in `MouseEvent`.c                    t        t        | j                  j                  z
  | j                  j                  j
                  z   z
        | j                  | j                  | j                        } |       y )NrF   )position
event_typebutton	modifiers)	r   r   rw   rG   rH   r'   rx   ry   rz   )event	new_eventhandlerr(   rC   rD   s     r)   new_handlerzYScrollablePane._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(   rC   rD   s   ` r)   wrap_mouse_handlerzDScrollablePane._copy_over_mouse_handlers.<locals>.wrap_mouse_handler*  s.    44
' 
' 3>&w/)'22r+   N)r}   r   r   r   )rD   rC   r]   rn   r"   r'   )r(   r]   rf   r^   rb   r   mouse_handlers_dicttemp_mouse_handlers_dictrH   temp_mouse_row	mouse_rowrG   r   rC   rD   s   `           @@@r)   rV   z(ScrollablePane._copy_over_mouse_handlers  s     """" DF	3 	3( -;;#6#E#E ~,,- 	TA,,!9!d>R>R:R!S/D9	}- TAN*.@PQAR.S	!d(+T		Tr+   c                &   |j                   }|j                  }|j                  j                         D ]\  \  }}t	        |j                  |z   |j                   |z   | j
                  z
  |j                  |j                        |j                  |<   ^ y)z3
        Copy over window write positions.
        )rC   rD   r"   r!   N)rD   rC   rP   rX   r   r'   r"   r!   )r(   r\   rd   r^   rD   rC   win	write_poss           r)   rW   z)ScrollablePane._copy_over_write_positionsI  s     """")LLRRT 	NC=J^^d*^^d*T-A-AA !''oo>F55c:	r+   c                6    | j                   j                         S r2   )r   is_modalr/   s    r)   r   zScrollablePane.is_modal\  s    ||$$&&r+   c                6    | j                   j                         S r2   )r   get_key_bindingsr/   s    r)   r   zScrollablePane.get_key_bindings_  s    ||,,..r+   c                    | j                   gS r2   r.   r/   s    r)   get_childrenzScrollablePane.get_childrenb  s    ~r+   c                z   d}||z
  }| j                         rh|f| j                  }|j                  |z
  dz   |j                  z   }|j                  |j                  z
  }	t        ||      }t        dt        ||	            }| j                         rx|j                  |k  r)|j                  |j                  z   |z
  }
|j                  }n(|j                  }
|j                  |j                  z   |z
  }t        ||
      }t        ||      }||kD  r|}| j                  |kD  r|| _
        | j                  |k  r|| _
        yy)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   rH   r   r   rI   r:   r   r"   rD   r'   )r(   visible_heightrc   rh   cursor_position
min_scroll
max_scrolloffsetscpos_min_scrollcpos_max_scrollwindow_min_scrollwindow_max_scrolls               r)   rQ   z#ScrollablePane._make_window_visiblee  sb   & 
#n4
##%*--#%%6:W^^K   #2"3"3gkk"A _=
 C
O$DE
++- %++~=)..+223$% "
 %:$>$>! %:$>$>!)..+223$% " Z):;JZ):;J
"#J *,#-D *,#-D  -r+   c           
        |j                   }| j                         }|r|dz  }	 |j                   t        |      z  }| j                  t        |      z  }t	        t        |t        d||z                    t	        ||z        dfd}|j                  |j                  z   dz
  }	|j                  }
|j                  }|r!t        | j                  d      ||
   |	<   |
dz  }
d}d}d}d}t        |      D ]D  }d	} ||      r ||dz         s|}n|}n ||dz         r|}n|}t        d
|      ||
   |	<   |
dz  }
F |rt        | j                  d      ||
   |	<   yy# t        $ r Y yw xY w)z
        Draw the scrollbar on the screen.

        Note: There is some code duplication with the `ScrollbarMargin`
              implementation.
           r	   c                *    | cxk  xr z   k  S c S )z/True if we should display a button on this row.r   )rr   scrollbar_heightscrollbar_tops    r)   is_scroll_buttonz8ScrollablePane._draw_scrollbar.<locals>.is_scroll_button  s    $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 r?   N)rr   intr   bool)r"   r$   floatr'   r   r:   rI   rC   r!   rD   ro   r   r%   rn   r&   ZeroDivisionError)r(   r^   content_heightr\   window_heightr$   fraction_visiblefraction_abover   rC   rD   ro   scrollbar_backgroundscrollbar_background_startscrollbar_buttonscrollbar_button_endirA   r   r   s                     @@r)   r[   zScrollablePane._draw_scrollbar  s    '--,,.QM7	-44u^7LL!11E.4IIN"M3q-:J*J#KL    >?M
P "&&)=)==AD!&&D ,,K *.((*A+D!$' 	 $@ )U&7#I =) #A&+AE2 !5 0'A. : 4*.sE*:D!$'	!& *.**,C+D!$' Y ! 		s   A E 	E+*E+)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   )r7   r   r   r   )r!   r   r    r   r   r   )r\   r   r]   r   r^   r   r_   r   r`   r   ra   z
int | Noner   r   )rj   r   r^   r   r   r   )
r\   r   rd   r   r^   r   rb   r   r   r   )
r]   r   rf   r   r^   r   rb   r   r   r   )r\   r   rd   r   r^   r   r   r   )r   r   )r   zKeyBindingsBase | None)r   zlist[Container])
r   r   rc   r   rh   r   r   zPoint | Noner   r   )r^   r   r   r   r\   r   r   r   )__name__
__module____qualname____doc__MAX_AVAILABLE_HEIGHTr*   r0   r3   r5   r<   rK   rZ   rU   rV   rW   r   r   r   rQ   r[   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   r=   r   r   r   r   r]   r   r   r\   r   r   r   __all__r   r   r   r+   r)   <module>r      sD    " 0 : 6 2 0 S S 7 / /
  [Y [r+   