
                            S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKJr  SSK	J
r
  SSKJr  SSKr " S	 S
\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rg)z$The gcloud interactive key bindings.    )absolute_import)division)unicode_literalsN)browser)keys)managerc                   L    \ rS rSrSr  SS jrS rSS jrSS jrS r	S	 r
S
rg)_KeyBinding    ap  Key binding base info to keep registered bindings and toolbar in sync.

Attributes:
  key: The keys.Key.* object.
  help_text: The UX help text.
  label: The short word label for the bottom toolbar.
  metavar: Display this value in GetLabel(markdown=True) instead of the real
    value.
  status: The bool => string toggle status map.
  toggle: The bool toggle state.
Nc                 L    Xl         X l        X0l        X@l        XPl        X`l        g N)key	help_textlabelmetavarstatustoggle)selfr   r   r   r   r   r   s          6lib/googlecloudsdk/command_lib/interactive/bindings.py__init___KeyBinding.__init__-   s     HNJLKK    c                     [         R                  " SS[        R                  " U R                  5      5      R                  SS5      $ )z!Returns the binding display name.z
.*<(.*)>.*z\1zC-zctrl-)resubsix	text_typer   replace)r   s    r   GetName_KeyBinding.GetName6   s4    66,--)++274+ABr   c                    U R                   c  U R                  c  g/ nU(       a  UR                  S5        UR                  U R                  5       5        UR                  S5        U R                   (       a=  UR                  U R                   5        U R                  (       a  UR                  S5        U(       a  UR                  S5        U R                  (       av  U(       aG  UR                  S5        UR                  U R                  =(       d    S5        UR                  S5        O(UR                  U R                  U R
                     5        SR                  U5      $ )zDReturns the key binding display label containing the name and value.N*:_STATE )r   r   appendr   r   r   join)r   markdownr   s      r   GetLabel_KeyBinding.GetLabel;   s    zzdkk1Ell3	LL 	LLzzll4::	Sll3{{	ST\\,W-ST[[-.775>r   c                     U R                   (       d  gU R                  5       nU(       a  SR                  U5      nU R                   R                  US9$ )zReturns the key help text.Nz*{}*r   )r   r   format)r   r)   r   s      r   GetHelp_KeyBinding.GetHelpS   s@    >>
,,.CMM#c>>  S ))r   c                     Ag)z Sets the toggle mode in the cli.N )r   clis     r   SetMode_KeyBinding.SetMode\   s    r   c                 f    U R                   (       + U l         U R                  UR                  5        g)zHandles a bound key event.N)r   r4   r3   r   events     r   Handle_KeyBinding.Handle`   s    kk/DKLLr   )r   r   r   r   r   r   )NNNNT)F)__name__
__module____qualname____firstlineno____doc__r   r   r*   r/   r4   r9   __static_attributes__r2   r   r   r
   r
       s/    
 ?C#'B
0*r   r
   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )_WebHelpKeyBindingf   zThe web help key binding.c                 ,   > [         [        U ]  USSS9  g )Nzweb-helpzOpens a web browser tab/window to display the complete man page help for the current command. If there is no active web browser (running in *ssh*(1) for example), then command specific help or *man*(1) help is attempted.r   r   r   )superrB   r   r   r   	__class__s     r   r   _WebHelpKeyBinding.__init__i   s#    	
d,*	 - 	r   c                     UR                   R                  R                  n[        R                  " UR                   UR
                  UR                  5        g r   )r3   current_bufferdocumentr   OpenReferencePagetextcursor_position)r   r8   docs      r   r9   _WebHelpKeyBinding.Handleu   s7    
))
"
"
+
+Ceii33F3FGr   r2   	r;   r<   r=   r>   r?   r   r9   r@   __classcell__rH   s   @r   rB   rB   f   s    !
H Hr   rB   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )_ContextKeyBindingz   zset context key binding.c                 ,   > [         [        U ]  USSS9  g )Ncontexta  Sets the context for command input, so you won't have to re-type common command prefixes at every prompt. The context is the command line from just after the prompt up to the cursor.
+
For example, if you are about to work with `gcloud compute` for a while, type *gcloud compute* and hit {key}. This will display *gcloud compute* at subsequent prompts until the context is changed.
+
Hit ctrl-c and {key} to clear the context, or edit a command line and/or move the cursor and hit {key} to set a different context.rE   )rF   rV   r   rG   s     r   r   _ContextKeyBinding.__init__}   s$    	
d,
O	 - r   c                     UR                   R                  R                  R                  UR                   R                  l        g r   )r3   rK   rL   text_before_cursorconfigrY   r7   s     r   r9   _ContextKeyBinding.Handle   s-    		  ))<< 
IIr   r2   rR   rT   s   @r   rV   rV   z   s     &> >r   rV   c                   0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )_HelpKeyBinding   zThe help key binding.c                 6   > [         [        U ]  USUSSS.SS9  g )NhelpOFFON)FTzHToggles the active help section, *ON* when enabled, *OFF* when disabled.)r   r   r   r   r   )rF   r`   r   )r   r   r   rH   s      r   r   _HelpKeyBinding.__init__   s,    	/4)e48 * r   r2   Tr;   r<   r=   r>   r?   r   r@   rS   rT   s   @r   r`   r`      s    	 	r   r`   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )_QuitKeyBinding   zThe quit key binding.c                 ,   > [         [        U ]  USSS9  g )NquitzExit.rE   )rF   rj   r   rG   s     r   r   _QuitKeyBinding.__init__   s     	/4)	 * r   c                 2    A[         R                  " S5        g )N   )sysexitr7   s     r   r9   _QuitKeyBinding.Handle   s    HHQKr   r2   rR   rT   s   @r   rj   rj      s     r   rj   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )_InterruptKeyBinding   ziThe interrupt (ctrl-c) key binding.

Catches control-C and clears the prompt input buffer and completer.
c                 (   > [         [        U ]  US9  g Nr-   )rF   ru   r   rG   s     r   r   _InterruptKeyBinding.__init__   s    	
. / r   c                     UR                   R                  R                  5         UR                   R                  R                  5         g r   )r3   rK   reset	completerr7   s     r   r9   _InterruptKeyBinding.Handle   s.    	II""$	IIr   r2   rR   rT   s   @r   ru   ru      s    

   r   ru   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )_StopKeyBinding   zzThe stop (^Z) key binding.

This binding's sole purpose is to ignore ^Z and prevent it from echoing
in the prompt window.
c                 (   > [         [        U ]  US9  g rx   )rF   r   r   rG   s     r   r   _StopKeyBinding.__init__   s    	/4) * r   r2   rh   rT   s   @r   r   r      s     r   r   c                   .    \ rS rSrSrSS jrS rS rSrg)	KeyBindings   a  All key bindings.

Attributes:
  bindings: The list of key bindings in left to right order.
  help_key: The help visibility key binding. True for ON, false for
    OFF.
  context_key: The command prefix context key that sets the context to the
    command substring from the beginning of the input line to the current
    cursor position.
  web_help_key: The browse key binding that pops up the full reference
    doc in a browser.
  quit_key: The key binding that exits the shell.
c                 t   [        [        R                  R                  US9U l        [        [        R                  R                  5      U l        [        [        R                  R                  5      U l
        [        [        R                  R                  5      U l        [        [        R                  R                  5      U l        [#        [        R                  R$                  5      U l        U R                  U R                  U R                  U R                  U R                   U R&                  /U l        g)zEAssociates keys with handlers. Toggle states are reachable from here.)r   N)r`   r   KeysF2help_keyrV   F7context_keyrB   F8web_help_keyrj   F9quit_keyru   ControlCinterrupt_signalr   ControlZstop_signalbindings)r   	help_modes     r   r   KeyBindings.__init__   s    
 $DIILLCDM)$)),,7D*499<<8D#DIILL1DM01C1CDD&tyy'9'9:D 	DMr   c                     [         R                  " SSSSS9nU R                   H7  nUR                  R	                  UR
                  SS9" UR                  5        M9     UR                  $ )zEMakes and returns a key binding registry populated with the bindings.T)enable_abort_and_exit_bindingsenable_system_bindingsenable_searchenable_auto_suggest_bindings)eager)r   KeyBindingManagerr   registryadd_bindingr   r9   )r   mbindings      r   MakeRegistryKeyBindings.MakeRegistry   s^    !!'+#%)		,A ==jjW[[5gnnE ! ::r   c                 L    U R                    H  nUR                  U5        M     g)z+Initialize key binding defaults in the cli.N)r   r4   )r   r3   r   s      r   
InitializeKeyBindings.Initialize  s    ==ooc !r   )r   r   r   r   r   r   r   Nrg   )	r;   r<   r=   r>   r?   r   r   r   r@   r2   r   r   r   r      s    ,r   r   )r?   
__future__r   r   r   r   rq   &googlecloudsdk.command_lib.interactiver   prompt_toolkitr   prompt_toolkit.key_bindingr   r   objectr
   rB   rV   r`   rj   ru   r   r   r2   r   r   <module>r      s     + &  ' 	 
 :  . 
C& CLH H(> >6k k " ;   
k 
5& 5r   