
    i_                         d Z ddlZddlZddlm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)Optional   )_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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      q/home/obispo/Crisostomo_bridge/mision_env/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_choice3   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_choice9   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_directionB   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_upR   s    ILL)r   downc                 B    | j                  t        j                         y r2   )r/   r	   r+   r4   s    r   	move_downzBulletMenu.move_downV   s    INN+r   newlinec                 r    t        t        | j                        | j                  z
  d       | j                  S Nr+   )r   r,   r   r   r4   s    r   selectzBulletMenu.selectZ   s(    C%5v>}}r   	interruptc                 f    t        t        | j                        | j                  z
  d       t        r;   )r   r,   r   r   KeyboardInterruptr4   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 r2   )
intchrcurrent_selectionr   r,   r   r/   r	   r3   r+   )r   r#   movements      r   
select_rowzBulletMenu.select_rowd   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 enterr3   Nr   )r   r   r   in_colabr   ranger,   r   r'   r   r   hiderB   builtinsr   
ValueErrorhandle_inputr   r
   r$   )r   rG   ichoice_s        r   runzBulletMenu.runt   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__r   strlistr   r$   rB   r'   r	   r/   r   markr   r5   r8   r<   r=   mark_multiplerK   rF   rS   ).0numberr   rY   s   0000r   r   r   $   s-    04R %x} %d %1s 1# )	 )s )  UZZt* * UZZv,  , UZZy!" # UZZ{#$  %  UU2YGG66#f+.GH I"# "! Hs   0Cr   )rX   rM   r   typingr   utils.importsr   rT   r   r   helpersr	   r
   r   r   r   r   r   keymapr   rJ   ModuleNotFoundErrorregisterr    r   r   <module>rf      sq     
  2  h h h  	$^4H
 l" l" l"  		s   A A$#A$