
    bi9                         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ej(                   G d d             Zy# e$ r Y !w xY w)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&                   ed      D  cg c]  }t        t	        |          c}}}}  d        ZddefdZyc c}}}} w )
BulletMenuzR
    A CLI menu to select a choice from a list of choices using the keyboard.
    Npromptchoicesc                 r    d| _         || _        || _        t        j                  dk(  rd| _        y d| _        y )Nr   win32*u   ➔ )positionr   r   sysplatform
arrow_char)selfr   r   s      b/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/accelerate/commands/menu/selection_menu.py__init__zBulletMenu.__init__)   s1    <<7"!DO$DO    endc                     t         j                  dk7  rt        | j                  |   d|       y t	        | j                  |   |       y )Nr       )r   r   r   r   r
   )r   indexr   s      r   write_choicezBulletMenu.write_choice2   s6    <<7"t||E*B4t||E*C0r   r"   c                     || j                   k(  r5t        d| j                   d       | j                  |       t                yt        d| j                  |           t                y)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   sY    DMM!4??+1-.e$ 	 dll51234r   	direction
num_spacesc                    | j                   }|t        j                  k(  r<| j                   dz   t        | j                        k\  ry| xj                   |z  c_         n(| j                   dz
  dk  ry| xj                   |z  c_         t                | j                  |       t        ||j                         | j                  | j                          y)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MMZ'M}}q 1$MMZ'M,'J	/$--(r   upc                 B    | j                  t        j                         y N)r.   r   UPr   s    r   move_upzBulletMenu.move_upQ   s    ILL)r   downc                 B    | j                  t        j                         y r1   )r.   r   r*   r3   s    r   	move_downzBulletMenu.move_downU   s    INN+r   newlinec                 r    t        t        | j                        | j                  z
  d       | j                  S Nr*   )r   r+   r   r   r3   s    r   selectzBulletMenu.selectY   s(    C%5v>}}r   	interruptc                 f    t        t        | j                        | j                  z
  d       t        r:   )r   r+   r   r   KeyboardInterruptr3   s    r   r<   zBulletMenu.interrupt^   s$    C%5v>r   
   c                 r   t        t        | j                              }|| j                  z
  }|| j                  k(  ry |t	        | j
                        k  rb| j                  |kD  r"| j                  t        j                  |        y | j                  |k  r!| j                  t        j                  |       y y y r1   )
intchrcurrent_selectionr   r+   r   r.   r   r2   r*   )r   r"   movements      r   
select_rowzBulletMenu.select_rowc   s    C../04==(DMM!3t||$$}}u$##ILL8)<&##INNH=r   default_choicec                    | j                   r?t                t        | j                   d       t        rt        dd       nt        dd       || _        t        t        | j                              D ]  }| j                  |       t        d         t        t        | j                        | j                  z
  d       t        j                         5  	 t        r	 t        t        j                               }n| j!                         }|ct#                t        t        | j                        dz         D ]  }t        dd       t%                 | j'                  |d       |cddd       S # t        $ r |}Y sw xY w# 1 sw Y   yxY w)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 enterr2   Nr   )r   r   r
   in_colabr   ranger+   r   r&   r   r   hiderA   builtinsr   
ValueErrorhandle_inputr   r	   r#   )r   rF   ichoice_s        r   runzBulletMenu.runs   sH   ;;Kt{{D)[]ablnrs&s4<<() 	Aa t	 	C%5t<[[] 	"0!$X^^%5!6 "..0F% N"3t||#4q#89 %#At,"% %%fd3!	" 	" & 0!/0	" 	"s7   F E/8A,F .F /E=:F <E==F  F	) )r   )r   )__name__
__module____qualname____doc__strlistr   r#   rA   r&   r   r.   r   markr   r4   r7   r;   r<   mark_multiplerJ   rE   rR   ).0numberr   rX   s   0000r   r   r   #   s)    &*2 %s %D %1s 1# )	 )s )  UZZt* * UZZv,  , UZZy!" # UZZ{#$  %  UU2YGG66#f+.GH I"# "! Hs   -Cr   )rW   rL   r   utils.importsr   rS   r   r   helpersr   r	   r
   r   r   r   r   keymapr   rI   ModuleNotFoundErrorregisterr    r   r   <module>rd      sn     
 2  h h h  	$^4H
 l" l" l"  		s   A AA