
xYc           @  s   d  Z  d d l m Z d d l m Z d d l m Z d Z d   Z e	 d  Z
 e	 d  Z d   Z d   Z d   Z d   Z d   Z d   Z d S(   u   
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...
i(   t   unicode_literals(   t   find_window_for_buffer_name(   t   rangeu   scroll_forwardu   scroll_backwardu   scroll_half_page_upu   scroll_half_page_downu   scroll_one_line_upu   scroll_one_line_downc         C  s   t  |  j |  j j  S(   u@   
    Return the `Window` for the currently focussed Buffer.
    (   R   t   clit   current_buffer_name(   t   event(    (    sI   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/scroll.pyt   _current_window_for_event   s    c   
      C  s   t  |   } |  j j } | r | j r | j } | j } | j } | rU | d } n  | j j d } d } xJ | | j k  r | j	 |  }	 | |	 | k  r | |	 7} | d 7} qn Pqn W| j j
 | d  | _ n  d S(   u   
    Scroll window down.
    i   i   i    N(   R   R   t   current_buffert   render_infot
   ui_contentt   window_heightt   documentt   cursor_position_rowt
   line_countt   get_height_for_linet   translate_row_col_to_indext   cursor_position(
   R   t   halft   wt   bt   infoR	   t   scroll_heightt   yt   heightt   line_height(    (    sI   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/scroll.pyt   scroll_forward   s"    			
c   	      C  s   t  |   } |  j j } | r | j r | j } | j } | rL | d } n  t d | j j d  } d } xG | d k r | j |  } | | | k  r | | 7} | d 8} qn Pqn W| j j	 | d  | _
 n  d S(   u   
    Scroll window up.
    i   i    i   N(   R   R   R   R   R
   t   maxR   R   R   R   R   (	   R   R   R   R   R   R   R   R   R   (    (    sI   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/scroll.pyt   scroll_backward=   s     		
c         C  s   t  |  d t d S(   u8   
    Same as ControlF, but only scroll half a page.
    R   N(   R   t   True(   R   (    (    sI   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/scroll.pyt   scroll_half_page_down[   s    c         C  s   t  |  d t d S(   u8   
    Same as ControlB, but only scroll half a page.
    R   N(   R   R   (   R   (    (    sI   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/scroll.pyt   scroll_half_page_upb   s    c         C  s   t  |  j |  j j  } |  j j } | r | j r | j } | j | j | j k  r | j j	 | j
 j k r | j | j j   7_ n  | j d 7_ q q n  d S(   u   
    scroll_offset += 1
    i   N(   R   R   R   R   R   t   vertical_scrollt   content_heightR
   R   R   t   configured_scroll_offsetst   topR   t   get_cursor_down_position(   R   R   R   R   (    (    sI   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/scroll.pyt   scroll_one_line_downi   s    		c         C  s   t  |  j |  j j  } |  j j } | r | j r | j } | j d k r | j | j    } | j j	 | j
 d | | j j } x5 t t d |   D] } | j | j j   7_ q W| j d 8_ q q n  d S(   u   
    scroll_offset -= 1
    i    i   N(   R   R   R   R   R   R   R   t   first_visible_lineR   R   R
   R!   t   bottomR   R   R   t   get_cursor_up_position(   R   R   R   R   t   first_line_heightt	   cursor_upt   _(    (    sI   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/scroll.pyt   scroll_one_line_up|   s    		c         C  s   t  |   } |  j j } | r | j r t | j j   | j d  } | | _ | j j | d  | _	 | j	 | j j
 d t  7_	 n  d S(   uX   
    Scroll page down. (Prefer the cursor at the top of the page, after scrolling.)
    i   i    t   after_whitespaceN(   R   R   R   R   R   t   last_visible_lineR   R   R   R   t   get_start_of_line_positionR   (   R   R   R   t
   line_index(    (    sI   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/scroll.pyt   scroll_page_down   s    	c         C  s   t  |   } |  j j } | r | j r t d t | j j   | j j d   } | j j	 | d  | _
 | j
 | j j d t  7_
 d | _ n  d S(   uY   
    Scroll page up. (Prefer the cursor at the bottom of the page, after scrolling.)
    i    i   R,   N(   R   R   R   R   R   t   minR%   R   R   R   R   R.   R   R   (   R   R   R   R/   (    (    sI   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/scroll.pyt   scroll_page_up   s    N(   u   scroll_forwardu   scroll_backwardu   scroll_half_page_upu   scroll_half_page_downu   scroll_one_line_upu   scroll_one_line_down(   t   __doc__t
   __future__R    t   prompt_toolkit.layout.utilsR   t	   six.movesR   t   __all__R   t   FalseR   R   R   R   R$   R+   R0   R2   (    (    (    sI   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/scroll.pyt   <module>   s$        						