
    J                     j    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 G d	 d
e      Zy)z}
The BufferMapping contains all the buffers for a command line interface, and it
keeps track of which buffer gets the focus.
    )unicode_literals   )DEFAULT_BUFFERSEARCH_BUFFERSYSTEM_BUFFERDUMMY_BUFFER)BufferAcceptAction)InMemoryHistoryN)BufferMappingc                   L     e Zd ZdZdef fd	Zd Zd Zd Zd Z	d Z
d	 Z xZS )
r   aT  
    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.)
    Nc                    |t        |t              sJ t        t        |           | j                  t        t        t        j                        t        t        t               t        j                        t        t        t               t        j                        t        t        d      i       || j                  |       |xs t        g| _        y )N)accept_action)historyr   T)	read_only)
isinstancedictsuperr   __init__updater   r	   r
   RETURN_DOCUMENTr   r   IGNOREr   r   focus_stack)selfbuffersinitial	__class__s      0lib/third_party/prompt_toolkit/buffer_mapping.pyr   zBufferMapping.__init__   s    *Wd";;; 	mT+- 	 F1M1MN6/*;<K^K^_6/*;<K^K^_&40
 	 KK  $5~6    c                 &    | | j                   d      S )z.
        The active :class:`.Buffer`.
        r   r   clis     r   currentzBufferMapping.current1   s     D$$R())r   c                      | j                   d   S )z:
        The name of the active :class:`.Buffer`.
        r!   r"   r#   s     r   current_namezBufferMapping.current_name7   s     ##r   c                 x    t        | j                        dkD  r	 | | j                  d      S y# t        $ r Y yw xY w)zL
        Return the previously focussed :class:`.Buffer` or `None`.
        r   N)lenr   KeyErrorr#   s     r   previouszBufferMapping.previous=   sK     t 1$D,,R011 %  s   - 	99c                 L    t        |t        j                        sJ |g| _        y)z7
        Focus the buffer with the given name.
        N)r   six	text_typer   r   r$   buffer_names      r   focuszBufferMapping.focusG   s"     +s}}555'=r   c                 r    t        |t        j                        sJ | j                  j	                  |       y)z1
        Push buffer on the focus stack.
        N)r   r.   r/   r   appendr0   s      r   
push_focuszBufferMapping.push_focusN   s,     +s}}555,r   c                 ~    t        | j                        dkD  r| j                  j                          yt        d      )z2
        Pop buffer from the focus stack.
        r   z*Cannot pop last item from the focus stack.N)r*   r   pop
IndexErrorr#   s     r   	pop_focuszBufferMapping.pop_focusU   s5     t 1$  "IJJr   )__name__
__module____qualname____doc__r   r   r%   r'   r,   r2   r5   r9   __classcell__)r   s   @r   r   r      s3      $^ 7.*$)-Kr   r   )r=   
__future__r   enumsr   r   r   r   bufferr	   r
   r   r   r.   __all__r   r    r   r   <module>rD      s5    ( M M ( $ 

KKD KKr   