
    Mh@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dS )    )annotations)Point)FilterOrBool	to_filter)KeyBindingsBase)
MouseEvent   )	ContainerScrollOffsets)AnyDimension	Dimensionsum_layout_dimensionsto_dimension)MouseHandlerMouseHandlers)CharScreenWritePositionScrollablePanei'  c            
          e Zd ZdZdddeddddddf
dBdZdCdZdDdZdEdZdFdZ	dGd+Z
dHd.ZdId1ZdJd3ZdKd4ZdLd5ZdMd7ZdNd9ZdOd?ZdPdAZdS )Qr   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^vcontentr
   scroll_offsetsScrollOffsets | Nonekeep_cursor_visibler   keep_focused_window_visiblemax_available_heightintwidthr   heightshow_scrollbardisplay_arrowsup_arrow_symbolstrdown_arrow_symbolreturnNonec                8   || _         |pt          dd          | _        t          |          | _        t          |          | _        || _        || _        || _        t          |          | _	        t          |	          | _
        |
| _        || _        d| _        d S )Nr	   )topbottomr   )r   r   r   r   r   r   r   r    r!   r"   r#   r$   r&   vertical_scroll)selfr   r   r   r   r   r    r!   r"   r#   r$   r&   s               e/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/prompt_toolkit/layout/scrollable_pane.py__init__zScrollablePane.__init__4   s     ,N!A0N0N0N#,-@#A#A +45P+Q+Q($8!
'77'77.!2     c                    d| j         dS )NzScrollablePane()r   r-   s    r.   __repr__zScrollablePane.__repr__P   s    22222r0   c                8    | j                                          d S N)r   resetr4   s    r.   r8   zScrollablePane.resetS   s    r0   max_available_widthr   c                    | j         t          | j                   S | j                            |          }|                                 r#t          t          j        d          |g          S |S )Nr	   )r    r   r   preferred_widthr"   r   r   exact)r-   r9   content_widths      r.   r;   zScrollablePane.preferred_widthV   sl    :!
+++ 445HII    	N()/!*<*<m)LMMMr0   c                    | j         t          | j                   S |                                 r|dz  }| j                            || j                  }t          d|j                  S )Nr	   r   )min	preferred)r!   r   r"   r   preferred_heightr   r   r@   )r-   r    r   	dimensions       r.   rA   zScrollablePane.preferred_heightd   sk    ;",,,    	QJEL11%9RSS	 Q)*=>>>>r0   screenr   mouse_handlersr   write_positionr   parent_styleerase_bgboolz_index
int | Nonec                2   |                                  }|r|j        dz
  }n|j        }| j                            || j                  j        }	t          |	|j                  }	t          |	| j                  }	t          t          d|                    }
|j        |
_        t          dd||	          }t                      }| j                            |
|||||           |
                                 ddlm}  |            j        j        }	 |
j        |         }|                     |j        |	||
j                            |                     n# t0          $ r Y nw xY w|                     ||
||           |                     ||||           |j        }|j        }t          |j        ||z             |_        t          |j        ||j        z             |_        |                     ||
|           |
j        rd|_        |
j                                        D ]w\  }}d|j        cxk    r|j        k     r[n | j         |j!        cxk    r|j        | j         z   k     r4n FtE          |j        |z   |j!        |z   | j         z
  	          |j        |<   x|
j#                                        D ]J\  }}| $                    tE          |j        |z   |j!        |z   | j         z
  	          |          |j#        |<   K|r| %                    ||	|           d
S d
S )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   rA   r   r@   maxr!   r?   r   r   show_cursorr   r   write_to_screendraw_all_floatsprompt_toolkit.applicationrR   layoutcurrent_window"visible_windows_to_write_positions_make_window_visiblecursor_positionsgetKeyError_copy_over_screen_copy_over_mouse_handlersrQ   rP   _copy_over_write_positionsitemsrT   r,   rU   r   menu_positions_clip_point_to_visible_area_draw_scrollbar)r-   rC   rD   rE   rF   rG   rI   r"   virtual_widthvirtual_heighttemp_screentemp_write_positiontemp_mouse_handlersrR   focused_windowvisible_win_write_posrQ   rP   windowpoints                       r.   rX   zScrollablePane.write_to_screens   s    ,,.. 	1*014MM*0M 6644
 

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

 ""6<)=>>FM4.2G+GHH 	''^LLL" 	&!%F )9??AA 		 		MFEUW3333~333333(7? ? ? ? '$*>>? ? ? ? ? 38gn$9M(M3 3 3'/
 )7==?? 	 	MFE,0,L,L$%'D.4;O*OPPP- -F!&))  	      	 	s   E 
E"!E"rq   r   c                   |j         |j        k     r|                    |j                  }|j        |j        k     r|                    |j                  }|j         |j        |j        z   k    r&|                    |j        |j        z   dz
            }|j        |j        |j        z   k    r&|                    |j        |j        z   dz
            }|S )zV
        Ensure that the cursor and menu positions always are always reported
        )rT   )rU   r	   )rT   rP   _replacerU   rQ   r    r!   )r-   rq   rE   s      r.   rg   z*ScrollablePane._clip_point_to_visible_area   s     7^(((NN^%8N99E7^(((NN^%8N99E7n)N,@@@@NN^%8>;O%ORS%SNTTE7n)N,AAAANN^%8>;P%PST%TNUUEr0   rk   ri   c                H   |j         }|j        }t          |j                  D ]~}|j        || j        z            }|j        ||z            }	|j        || j        z            }
|j        ||z            }t          |          D ]"}||         |	||z   <   ||
v r|
|         |||z   <   #dS )zU
        Copy over visible screen content and "zero width escape sequences".
        N)rQ   rP   ranger!   data_bufferr,   zero_width_escapes)r-   rC   rk   rE   ri   rQ   rP   rU   temp_rowrowtemp_zero_width_escapesrw   rT   s                r.   rb   z ScrollablePane._copy_over_screen   s     ""~,-- 	N 	NA".q43G/GHH$QX.C&1&DD(('# "(!:1t8!D=)) N N (AH///3J13M&q4x0	N	N 	Nr0   rm   c                "    |j         |j        i d fd}|j        }|j        }t          |j                  D ]N}||v rH|| j        z            }	||z            }
t          |          D ]}||	v r ||	|                   |
|z   <   OdS )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.
        handlerr   r'   c                :      vrd fd}| <             S )z:Wrap mouse handler. Translate coordinates in `MouseEvent`.eventr   r'   r(   c                    t          t          | j        j        z
  | j        j        j        z   z
            | j        | j        | j                  } |           d S )NrS   )position
event_typebutton	modifiers)	r   r   r   rT   rU   r,   r   r   r   )r~   	new_eventr|   r-   rP   rQ   s     r.   new_handlerzYScrollablePane._copy_over_mouse_handlers.<locals>.wrap_mouse_handler.<locals>.new_handler.  su     *!&#n.5#n.1EEL" " " $)#3$|"'/! ! !I GI&&&&&r0   )r~   r   r'   r(    )r|   r   mouse_handler_wrappersr-   rP   rQ   s   ` r.   wrap_mouse_handlerzDScrollablePane._copy_over_mouse_handlers.<locals>.wrap_mouse_handler*  sU    444
' 
' 
' 
' 
' 
' 
' 
' 
' 3>&w/)'22r0   N)r|   r   r'   r   )rQ   rP   rD   ru   r!   r,   )r-   rD   rm   rE   ri   r   mouse_handlers_dicttemp_mouse_handlers_dictrU   temp_mouse_row	mouse_rowrT   r   rP   rQ   s   `           @@@r.   rc   z(ScrollablePane._copy_over_mouse_handlers  s     "" DF	3 	3 	3 	3 	3 	3 	3 	3 	3( -;#6#E ~,-- 	T 	TA,,,!9!d>R:R!S/D9	}-- T TAN**.@.@PQAR.S.S	!d(+	T 	Tr0   c                    |j         }|j        }|j                                        D ]B\  }}t	          |j        |z   |j         |z   | j        z
  |j        |j                  |j        |<   CdS )z3
        Copy over window write positions.
        )rP   rQ   r!   r    N)rQ   rP   r]   re   r   r,   r!   r    )r-   rC   rk   rE   rQ   rP   win	write_poss           r.   rd   z)ScrollablePane._copy_over_write_positionsI  s     "")LRRTT 	 	NC=J^d*^d*T-AA !'o> > >F5c::	 	r0   c                4    | j                                         S r7   )r   is_modalr4   s    r.   r   zScrollablePane.is_modal\  s    |$$&&&r0   KeyBindingsBase | Nonec                4    | j                                         S r7   )r   get_key_bindingsr4   s    r.   r   zScrollablePane.get_key_bindings_  s    |,,...r0   list[Container]c                    | j         gS r7   r3   r4   s    r.   get_childrenzScrollablePane.get_childrenb  s    ~r0   visible_heightrj   ro   cursor_positionPoint | Nonec                2   d}||z
  }|                                  r[|Y| j        }|j        |z
  dz   |j        z   }|j        |j        z
  }	t          ||          }t          dt          ||	                    }|                                 r^|j        |k    r|j	        |j        z   |z
  }
|j	        }n|j	        }
|j	        |j        z   |z
  }t          ||
          }t          ||          }||k    r|}| j
        |k    r|| _
        | j
        |k     r	|| _
        dS dS )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   rU   r+   r*   rV   r?   r   r!   rQ   r,   )r-   r   rj   ro   r   
min_scroll
max_scrolloffsetscpos_min_scrollcpos_max_scrollwindow_min_scrollwindow_max_scrolls               r.   r^   z#ScrollablePane._make_window_visiblee  sr   & 
#n4
##%% 		F*-#%6:W^K   #2"3gk"A _==
 C
O$D$DEE
++-- 	< %+~==).+23$% "
 %:$>!! %:$>!).+23$% " Z):;;JZ):;;J
""#J *,,#-D *,,#-D    -,r0   content_heightc           
        |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 ]T}d} ||          r ||dz             s|}n|}n ||dz             r|}n|}t          d|          ||
         |	<   |
dz  }
U|r t          | j        d          ||
         |	<   dS dS # t          $ r Y dS w xY w)z
        Draw the scrollbar on the screen.

        Note: There is some code duplication with the `ScrollbarMargin`
              implementation.
           r	   ry   r   r'   rH   c                *    | cxk    oz   k    nc S )z/True if we should display a button on this row.r   )ry   scrollbar_heightscrollbar_tops    r.   is_scroll_buttonz8ScrollablePane._draw_scrollbar.<locals>.is_scroll_button  s+    $OOOO}?O/OOOOOOr0   zclass:scrollbar.arrowzclass:scrollbar.backgroundz*class:scrollbar.background,scrollbar.startzclass:scrollbar.buttonz$class:scrollbar.button,scrollbar.end rL   N)ry   r   r'   rH   )r!   r#   floatr,   r   r?   rV   rP   r    rQ   rv   r   r$   ru   r&   ZeroDivisionError)r-   rE   r   rC   window_heightr#   fraction_visiblefraction_abover   rP   rQ   rv   scrollbar_backgroundscrollbar_background_startscrollbar_buttonscrollbar_button_endirN   r   r   s                     @@r.   rh   zScrollablePane._draw_scrollbar  sC    '-,,.. 	QM7	-4u^7L7LL!1E.4I4IIN"M3q-:J*J#K#KLL      >??M
P P P P P P P "&)==AD!&D ,K  *.(*A+ +D!$' 	 $@ )U&7#I =))  ##A&& 5++AE22 1 !5 0''A.. 5 : 4*.sE*:*:D!$'	  *.*,C+ +D!$''' Y ! 	 	 	FF	s   A.E0 0
E>=E>)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'   r%   )r'   r(   )r9   r   r'   r   )r    r   r   r   r'   r   )rC   r   rD   r   rE   r   rF   r%   rG   rH   rI   rJ   r'   r(   )rq   r   rE   r   r'   r   )
rC   r   rk   r   rE   r   ri   r   r'   r(   )
rD   r   rm   r   rE   r   ri   r   r'   r(   )rC   r   rk   r   rE   r   r'   r(   )r'   rH   )r'   r   )r'   r   )
r   r   rj   r   ro   r   r   r   r'   r(   )rE   r   r   r   rC   r   r'   r(   )__name__
__module____qualname____doc__MAX_AVAILABLE_HEIGHTr/   r5   r8   r;   rA   rX   rg   rb   rc   rd   r   r   r   r^   rh   r   r0   r.   r   r      s        F 04,048$8"#'+'+"!$! ! ! ! !83 3 3 3      ? ? ? ?u u u un   "N N N N61T 1T 1T 1Tf   &' ' ' '/ / / /   @. @. @. @.DG G G G G Gr0   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   rD   r   r   rC   r   r   r   __all__r   r   r   r0   r.   <module>r      s%   " " " " " " 0 0 0 0 0 0 : : : : : : : : 6 6 6 6 6 6 2 2 2 2 2 2 0 0 0 0 0 0 0 0 S S S S S S S S S S S S 7 7 7 7 7 7 7 7 / / / / / / / / / /
  [ [ [ [ [Y [ [ [ [ [r0   