o
    úÜÓh
  ã                   @   s\   d Z ddlm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
é    )ÚListé   )Ú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 }t| d|ƒ | S ©NÚ
handle_key©ÚgetattrÚsetattr©ÚfuncÚhandle©r   © úT/var/www/html/ai/venv/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 }t| d|ƒ | 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                    sh   t ƒ  | |||¡}t|dƒst|di ƒ t|dtjƒ | ¡ D ]}t|dg ƒ}|D ]}||j|< q)q|S )NÚkey_handlerÚhandle_inputr	   )	ÚsuperÚ__new__Úhasattrr   r   r   Úvaluesr   r   )ÚclsÚnameÚbasesÚattrsÚnew_clsÚvalueÚhandled_keysr   ©Ú	__class__r   r   r   :   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   F   s   zKeyHandler.handle_input)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ústaticmethodr   Ú__classcell__r   r   r'   r   r   5   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   ÚregisterT   s   r8   N)r2   Útypingr   Úkeymapr   r   Ústrr   r   Útyper   r8   r   r   r   r   Ú<module>   s   