o
    0‚›iÐ	  ã                   @   sP   d Z ddlmZmZ defdd„Zdee fdd„ZG d	d
„ d
eƒZ	dd„ Z
dS )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d„}|S )zR
    Mark the function with the key code so it can be handled in the register
    c                    s    t | dg ƒ}|ˆ g7 }|| _| S ©NÚ
handle_key©Úgetattrr   ©ÚfuncÚhandle©r   © ú`/sda-disk/www/egybert/egybert_env/lib/python3.10/site-packages/accelerate/commands/menu/input.pyÚ	decorator   s   
zmark.<locals>.decoratorr   )r   r   r   r   r   Úmark   ó   r   Úkeysc                     r   )zS
    Mark the function with the key codes so it can be handled in the register
    c                    s   t | dg ƒ}|ˆ 7 }|| _| S r   r   r
   ©r   r   r   r   *   s   z mark_multiple.<locals>.decoratorr   )r   r   r   r   r   Úmark_multiple%   r   r   c                       s,   e Zd ZdZ‡ fdd„Zedd„ ƒZ‡  ZS )Ú
KeyHandlerz;
    Metaclass that adds the key handlers to the class
    c                    s\   t ƒ  | |||¡}t|dƒsi |_tj|_| ¡ D ]}t|dg ƒ}|D ]}||j|< q#q|S )NÚkey_handlerr   )ÚsuperÚ__new__Úhasattrr   r   Úhandle_inputÚvaluesr	   )ÚclsÚnameÚbasesÚattrsÚnew_clsÚvalueÚhandled_keysr   ©Ú	__class__r   r   r   8   s   
ÿzKeyHandler.__new__c                 C   s<   t ƒ }|td krt|ƒ}| j |¡}|r|| _|| ƒS dS )zDFinds and returns the selected character if it exists in the handlerÚ	undefinedN)r   r   Úordr   ÚgetÚcurrent_selection)r   ÚcharÚhandlerr   r   r   r   D   s   zKeyHandler.handle_input)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ústaticmethodr   Ú__classcell__r   r   r$   r   r   3   s
    r   c                 C   s   t | j| j| j ¡ ƒS )z&Adds KeyHandler metaclass to the class)r   r,   Ú	__bases__Ú__dict__Úcopy)r   r   r   r   ÚregisterR   s   r5   N)r/   Úkeymapr   r   Ústrr   Úlistr   Útyper   r5   r   r   r   r   Ú<module>   s   