
    9i
                     ^    d Z ddlm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
    )List   )KEYMAPget_characterkeyc                       fd}|S )zR
    Mark the function with the key code so it can be handled in the register
    c                 H    t        | dg       }|gz  }t        | d|       | S N
handle_keygetattrsetattr)funchandler   s     h/var/www/html/backtest/airagagent/rag_env/lib/python3.12/site-packages/accelerate/commands/menu/input.py	decoratorzmark.<locals>.decorator   s-    |R03%lF+     )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                 F    t        | dg       }|z  }t        | d|       | S r
   r   )r   r   r   s     r   r   z mark_multiple.<locals>.decorator,   s+    |R0$lF+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t        |di        t        |dt        j
                         |j                         D ]%  }t        |dg       }|D ]  }||j                  |<    ' |S )Nkey_handlerhandle_inputr   )	super__new__hasattrr   r   r   valuesr   r   )	clsnamebasesattrsnew_clsvaluehandled_keysr   	__class__s	           r   r!   zKeyHandler.__new__:   s    '/#tUE:w.G]B/)@)@A\\^ 	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_inputF   sM     6+&&t9D//%%d+$(C!3<r   )__name__
__module____qualname____doc__r!   staticmethodr   __classcell__)r+   s   @r   r   r   5   s!    
 
 
r   r   c                 t    t        | j                  | j                  | j                  j	                               S )z&Adds KeyHandler metaclass to the class)r   r3   	__bases____dict__copy)r$   s    r   registerr=   T   s&    cllCMM3<<3D3D3FGGr   N)r6   typingr   keymapr   r   strr   r   typer   r=   r   r   r   <module>rB      s@   
  )c c  >Hr   