
    f                    p    d Z ddlmZ ddlmZ g dZeZdddZdddZddZ	ddZ
dd	Zdd
ZddZddZy)z
Key bindings, for scrolling up and down through pages.

This are separate bindings, because GNU readline doesn't have them, but
they are very useful for navigating through long multiline buffers, like in
Vi, Emacs, etc...
    )annotations)KeyPressEvent)scroll_forwardscroll_backwardscroll_half_page_upscroll_half_page_downscroll_one_line_upscroll_one_line_downc                   | j                   j                  j                  }| j                   j                  }|r|j                  r|j                  }|j
                  }|j                  }|r|dz  }|j                  j                  dz   }d}||j                  k  r5|j                  |      }	||	z   |k  r||	z  }|dz  }nn||j                  k  r5|j                  j                  |d      |_        yyy)z
    Scroll window down.
          r   N)applayoutcurrent_windowcurrent_bufferrender_info
ui_contentwindow_heightdocumentcursor_position_row
line_countget_height_for_linetranslate_row_col_to_indexcursor_position)
eventhalfwbinfor   scroll_heightyheightline_heights
             e/var/www/cvtools/html/venv/lib/python3.12/site-packages/prompt_toolkit/key_binding/bindings/scroll.pyr   r      s     			''A		  AQ]]}}__
 **aM JJ**Q.*'''2215K#m3+%Q *''' JJAA!QG+ q    c                   | j                   j                  j                  }| j                   j                  }|r|j                  r|j                  }|j
                  }|r|dz  }t        d|j                  j                  dz
        }d}|dkD  r+|j                  |      }||z   |k  r||z  }|dz  }nn|dkD  r+|j                  j                  |d      |_        yyy)z
    Scroll window up.
    r   r   r   N)r   r   r   r   r   r   maxr   r   r   r   r   )	r   r   r   r   r   r    r!   r"   r#   s	            r$   r   r   8   s     			''A		  AQ]]}} **aM 1::11A56!e2215K#m3+%Q !e JJAA!QG) qr%   c                    t        | d       y)z8
    Same as ControlF, but only scroll half a page.
    Tr   N)r   r   s    r$   r   r   V   s     5t$r%   c                    t        | d       y)z8
    Same as ControlB, but only scroll half a page.
    Tr)   N)r   r*   s    r$   r   r   ]   s     E%r%   c                   | j                   j                  j                  }| j                   j                  }|r|j                  r|j                  }|j
                  |j                  |j                  z
  k  rp|j                  j                  |j                  j                  k  r-|xj                  |j                  j                         z  c_        |xj
                  dz  c_        yyyy)z
    scroll_offset += 1
    r   N)r   r   r   r   r   vertical_scrollcontent_heightr   r   r!   configured_scroll_offsetstopr   get_cursor_down_position)r   r   r   r   s       r$   r
   r
   d   s     			''A		  A====D  4#6#69K9K#KK''))T-K-K-O-OO%%)L)L)NN%!!Q&!	 L  	r%   c                >   | j                   j                  j                  }| j                   j                  }|r|j                  r|j                  }|j
                  dkD  r|j                  |j                               }|j                  j                  |j                  dz
  |z
  |j                  j                  z
  z
  }t        t        d|            D ]/  }|xj                  |j                  j!                         z  c_        1 |xj
                  dz  c_        yyyy)z
    scroll_offset -= 1
    r   r   N)r   r   r   r   r   r-   r   first_visible_liner   r!   r   r/   bottomranger'   r   get_cursor_up_position)r   r   r   r   first_line_height	cursor_up_s          r$   r	   r	   w   s    			''A		  A====D  1$$($<$<T=T=T=V$W! 0022&&'( 44;;<	 s1i01 MA%%)J)J)LL%M !!Q&!! %  	r%   c                   | j                   j                  j                  }| j                   j                  }|r|j                  rt        |j                  j                         |j                  dz         }||_        |j                  j                  |d      |_
        |xj                  |j                  j                  d      z  c_
        yyy)zX
    Scroll page down. (Prefer the cursor at the top of the page, after scrolling.)
    r   r   Tafter_whitespaceN)r   r   r   r   r   r'   last_visible_liner-   r   r   r   get_start_of_line_positionr   r   r   
line_indexs       r$   scroll_page_downrA      s     			''A		  AQ]]88:A<M<MPQ<QR
&JJAA*aP	QZZBB! C 
 	
 qr%   c                   | j                   j                  j                  }| j                   j                  }|r|j                  rt        dt        |j                  j                         |j                  j                  dz
              }|j                  j                  |d      |_        |xj                  |j                  j                  d      z  c_        d|_        yyy)zY
    Scroll page up. (Prefer the cursor at the bottom of the page, after scrolling.)
    r   r   Tr;   N)r   r   r   r   r   r'   minr3   r   r   r   r   r>   r-   r?   s       r$   scroll_page_uprD      s     			''A		  AQ]] 002AJJ4R4RUV4VW


 JJAA*aP	QZZBB! C 
 	
  qr%   N)F)r   Er   boolreturnNone)r   rE   rG   rH   )__doc__
__future__r   (prompt_toolkit.key_binding.key_processorr   __all__rE   r   r   r   r   r
   r	   rA   rD    r%   r$   <module>rN      sJ    # B H>H<%&'&'>
$r%   