
    g9                         d Z ddlZddlZddlmZ ddlmZmZ ddlm	Z	m
Z
mZmZmZmZmZ ddlmZ d	Z	  ed
          Zn# e$ r Y nw xY wej         G d d                      ZdS )zO
Main driver for the selection menu, based on https://github.com/bchao1/bullet
    N   )_is_package_available   )cursorinput)	Direction
clear_line
forceWrite	linebreakmove_cursorreset_cursor
writeColor)KEYMAPFzgoogle.colabc                      e Zd ZdZdg fdedefdZddefdZd	efd
Z	dde
defdZ ej        ed                   d             Z ej        ed                   d             Z ej        ed                   d             Z ej        ed                   d             Z ej        d  ed          D              d             ZddefdZdS ) 
BulletMenuzR
    A CLI menu to select a choice from a list of choices using the keyboard.
    Npromptchoicesc                 p    d| _         || _        || _        t          j        dk    r	d| _        d S d| _        d S )Nr   win32*u   ➔ )positionr   r   sysplatform
arrow_char)selfr   r   s      c/var/www/html/ai-engine/env/lib/python3.11/site-packages/accelerate/commands/menu/selection_menu.py__init__zBulletMenu.__init__)   s:    <7""!DOOO$DOOO     endc                     t           j        dk    rt          | j        |         d|           d S t	          | j        |         |           d S )Nr       )r   r   r   r   r
   )r   indexr    s      r   write_choicezBulletMenu.write_choice2   sK    <7""t|E*B44444t|E*C00000r   r#   c                     || j         k    r.t          d| j         d           |                     |           nt          d| j        |                     t                       dS )z$Prints the choice at the given index z    N)r   r
   r   r$   r   r   )r   r#   s     r   print_choicezBulletMenu.print_choice8   sm    DM!!-4?---...e$$$$3dl5133444r   r   	direction
num_spacesc                 ~   | j         }|t          j        k    r3| j         dz   t          | j                  k    rdS | xj         |z  c_         n | j         dz
  dk     rdS | xj         |z  c_         t                       |                     |           t          ||j                   |                     | j                    dS )zLShould not be directly called, used to move a direction of either up or downr   Nr   )	r   r   DOWNlenr   r	   r'   r   name)r   r(   r)   old_positions       r   move_directionzBulletMenu.move_directionA   s    }	&&}q C$5$555MMZ'MMM}q 1$$MMZ'MM,'''J	///$-(((((r   upc                 D    |                      t          j                   d S N)r/   r   UPr   s    r   move_upzBulletMenu.move_upQ   s    IL)))))r   downc                 D    |                      t          j                   d S r2   )r/   r   r+   r4   s    r   	move_downzBulletMenu.move_downU   s    IN+++++r   newlinec                 d    t          t          | j                  | j        z
  d           | j        S Nr+   )r   r,   r   r   r4   s    r   selectzBulletMenu.selectY   s+    C%%5v>>>}r   	interruptc                 d    t          t          | j                  | j        z
  d           t          r;   )r   r,   r   r   KeyboardInterruptr4   s    r   r=   zBulletMenu.interrupt^   s)    C%%5v>>>r   c                 B    g | ]}t           t          |                   S  )r   str).0numbers     r   
<listcomp>zBulletMenu.<listcomp>c   s#    GGG66#f++.GGGr   
   c                 `   t          t          | j                            }|| j        z
  }|| j        k    rd S |t	          | j                  k     r]| j        |k    r#|                     t          j        |            d S | j        |k     r"|                     t          j	        |           d S d S d S r2   )
intchrcurrent_selectionr   r,   r   r/   r   r3   r+   )r   r#   movements      r   
select_rowzBulletMenu.select_rowc   s    C.//004=(DM!!F3t|$$$$}u$$##IL8)<<<<<&&##INH=====Fr   r   default_choicec                 n   | j         rKt                       t          | j         d           t          rt          dd           nt          dd           || _        t          t          | j                            D ]&}|                     |           t          d           't          t          | j                  | j        z
  d           t          j                    5  	 t          r4	 t          t          j                              }n&# t          $ r |}Y nw xY w|                                 }|wt#                       t          t          | j                  dz             D ] }t          dd           t%                       !|                     |d           |cddd           S # 1 swxY w Y   dS )z-Start the menu and return the selected choice
z>Please input a choice index (starting from 0), and press enterzOPlease select a choice using the arrow or number keys, and selecting with enterr3   TNr   )r   r   r
   in_colabr   ranger,   r   r'   r   r   hiderH   builtinsr   
ValueErrorhandle_inputr   r	   r$   )r   rM   ichoice_s        r   runzBulletMenu.runs   s   ; 	tKKKt{D))) t[]abbbblnrsss&s4<(()) 	 	Aa   tC%%5t<<<[]] 	" 	"" 10!$X^%5%5!6!6% 0 0 0!/0 "..00F% NNN"3t|#4#4q#899 % %#At,,,"%%fd333!	" 	" 	" 	" 	" 	" 	" 	""	" 	" 	" 	" 	" 	" 	" 	" 	" 	"s=   	F*) D
	F*
DF*DBF*)F**F.1F.)r   )r   )r   )__name__
__module____qualname____doc__rB   listr   r$   rH   r'   r   r/   r   markr   r5   r8   r<   r=   mark_multiplerQ   rL   rY   rA   r   r   r   r   #   s         &*2 % %s %D % % % %1 1s 1 1 1 1#    ) )	 )s ) ) ) )  UZt* * * UZv, ,  , UZy!""  #" UZ{#$$    %$  UGGUU2YYGGGH  IH" "# " " " " " "r   r   )r]   rS   r   utils.importsr   r   r   r   helpersr   r	   r
   r   r   r   r   keymapr   rP   ModuleNotFoundErrorregisterr   rA   r   r   <module>rf      s     



 2 2 2 2 2 2         h h h h h h h h h h h h h h h h h h       	$$^44HH 	 	 	D	 l" l" l" l" l" l" l" l" l" l"s   A   AA