
    bi	                     R    d Z ddlmZmZ defdZdee   fdZ G d de      Z	d	 Z
y
)z
This file contains utilities for handling input from the user and registering specific keys to specific functions,
based on https://github.com/bchao1/bullet
   )KEYMAPget_characterkeyc                       fd}|S )zR
    Mark the function with the key code so it can be handled in the register
    c                 <    t        | dg       }|gz  }|| _        | S N
handle_keygetattrr	   )funchandler   s     Y/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/accelerate/commands/menu/input.py	decoratorzmark.<locals>.decorator   s(    |R03%      )r   r   s   ` r   markr          
 r   keysc                        fd}|S )zS
    Mark the function with the key codes so it can be handled in the register
    c                 :    t        | dg       }|z  }|| _        | S r   r
   )r   r   r   s     r   r   z mark_multiple.<locals>.decorator*   s&    |R0$ r   r   )r   r   s   ` r   mark_multipler   %   r   r   c                   2     e Zd ZdZ fdZed        Z xZS )
KeyHandlerz;
    Metaclass that adds the key handlers to the class
    c                     t         |   | |||      }t        |d      si |_        t        j
                  |_        |j                         D ]%  }t        |dg       }|D ]  }||j                  |<    ' |S )Nkey_handlerr	   )super__new__hasattrr   r   handle_inputvaluesr   )	clsnamebasesattrsnew_clsvaluehandled_keysr   	__class__s	           r   r   zKeyHandler.__new__8   s    '/#tUE:w."$G)66\\^ 	1E"5,;L# 1+0##C(1	1 r   c                     t               }|t        d   k7  rt        |      }| j                  j	                  |      }|r|| _         ||       S y)zDFinds and returns the selected character if it exists in the handler	undefinedN)r   r   ordr   getcurrent_selection)r!   charhandlers      r   r   zKeyHandler.handle_inputD   sM     6+&&t9D//%%d+$(C!3<r   )__name__
__module____qualname____doc__r   staticmethodr   __classcell__)r(   s   @r   r   r   3   s!    
 
 
r   r   c                 t    t        | j                  | j                  | j                  j	                               S )z&Adds KeyHandler metaclass to the class)r   r0   	__bases____dict__copy)r!   s    r   registerr:   R   s&    cllCMM3<<3D3D3FGGr   N)r3   keymapr   r   strr   listr   typer   r:   r   r   r   <module>r?      s=   
 *c c  >Hr   