ó
±xYc           @  sŠ   d  Z  d d l 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 d d l Z d Z d	 e f d
 „  ƒ  YZ d S(   u}   
The BufferMapping contains all the buffers for a command line interface, and it
keeps track of which buffer gets the focus.
iÿÿÿÿ(   t   unicode_literalsi   (   t   DEFAULT_BUFFERt   SEARCH_BUFFERt   SYSTEM_BUFFERt   DUMMY_BUFFER(   t   Buffert   AcceptAction(   t   InMemoryHistoryNu   BufferMappingt   BufferMappingc           B  sS   e  Z d  Z d e d „ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z RS(	   uT  
    Dictionary that maps the name of the buffers to the
    :class:`~prompt_toolkit.buffer.Buffer` instances.

    This mapping also keeps track of which buffer currently has the focus.
    (Some methods receive a 'cli' parameter. This is useful for applications
    where this `BufferMapping` is shared between several applications.)
    c         C  sÎ   | d  k s! t | t ƒ s! t ‚ t t |  ƒ j ƒ  |  j i t d t	 j
 ƒ t 6t d t ƒ  d t	 j ƒ t 6t d t ƒ  d t	 j ƒ t 6t d t ƒ t 6ƒ | d  k	 r¸ |  j | ƒ n  | pÁ t g |  _ d  S(   Nt   accept_actiont   historyt	   read_only(   t   Nonet
   isinstancet   dictt   AssertionErrort   superR   t   __init__t   updateR   R   t   RETURN_DOCUMENTR   R   t   IGNORER   R   t   TrueR   t   focus_stack(   t   selft   bufferst   initial(    (    s<   lib/python2.7/site-packages/prompt_toolkit/buffer_mapping.pyR      s    !	c         C  s   |  |  j  d S(   u.   
        The active :class:`.Buffer`.
        iÿÿÿÿ(   R   (   R   t   cli(    (    s<   lib/python2.7/site-packages/prompt_toolkit/buffer_mapping.pyt   current1   s    c         C  s   |  j  d S(   u:   
        The name of the active :class:`.Buffer`.
        iÿÿÿÿ(   R   (   R   R   (    (    s<   lib/python2.7/site-packages/prompt_toolkit/buffer_mapping.pyt   current_name7   s    c         C  sC   t  |  j ƒ d k r? y |  |  j d SWq? t k
 r; q? Xn  d S(   uL   
        Return the previously focussed :class:`.Buffer` or `None`.
        i   iþÿÿÿN(   t   lenR   t   KeyError(   R   R   (    (    s<   lib/python2.7/site-packages/prompt_toolkit/buffer_mapping.pyt   previous=   s
    c         C  s(   t  | t j ƒ s t ‚ | g |  _ d S(   u7   
        Focus the buffer with the given name.
        N(   R   t   sixt	   text_typeR   R   (   R   R   t   buffer_name(    (    s<   lib/python2.7/site-packages/prompt_toolkit/buffer_mapping.pyt   focusG   s    c         C  s,   t  | t j ƒ s t ‚ |  j j | ƒ d S(   u1   
        Push buffer on the focus stack.
        N(   R   R    R!   R   R   t   append(   R   R   R"   (    (    s<   lib/python2.7/site-packages/prompt_toolkit/buffer_mapping.pyt
   push_focusN   s    c         C  s5   t  |  j ƒ d k r% |  j j ƒ  n t d ƒ ‚ d S(   u2   
        Pop buffer from the focus stack.
        i   u*   Cannot pop last item from the focus stack.N(   R   R   t   popt
   IndexError(   R   R   (    (    s<   lib/python2.7/site-packages/prompt_toolkit/buffer_mapping.pyt	   pop_focusU   s    N(   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   R#   R%   R(   (    (    (    s<   lib/python2.7/site-packages/prompt_toolkit/buffer_mapping.pyR      s   			
		(   u   BufferMapping(   R+   t
   __future__R    t   enumsR   R   R   R   t   bufferR   R   R
   R   R    t   __all__R   R   (    (    (    s<   lib/python2.7/site-packages/prompt_toolkit/buffer_mapping.pyt   <module>   s   "