U
    0È-e
  ã                   @   s\   d Z ddlmZ ddlmZmZ edœdd„Zee dœ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                    s   ‡ 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Úhandler   © ú_/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/accelerate/commands/menu/input.pyÚ	decorator   s    
zmark.<locals>.decoratorr   )r   r   r   r   r   Úmark   s    r   ©Úkeysc                     s   ‡ fdd„}|S )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'   s    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|< qRq>|S )NÚkey_handlerÚhandle_inputr	   )	ÚsuperÚ__new__Úhasattrr   r   r   Úvaluesr   r   )ÚclsÚnameÚbasesÚattrsZnew_clsÚvalueZhandled_keysr   ©Ú	__class__r   r   r   :   s    
zKeyHandler.__new__c                 C   s@   t ƒ }|td krt|ƒ}| j |¡}|r8|| _|| ƒS dS dS )zDFinds and returns the selected character if it exists in the handlerÚ	undefinedN)r   r   Úordr   ÚgetZ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    r3   N)r-   Útypingr   Zkeymapr   r   Ústrr   r   Útyper   r3   r   r   r   r   Ú<module>   s   