
    P                         S 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.    N)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.GetName3   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.GetLabel8   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.GetHelpP   s@    >>
,,.CMM#c>>  S ))r   c                     Ag)z Sets the toggle mode in the cli.N )r   clis     r   SetMode_KeyBinding.SetModeY   s    r   c                 f    U R                   (       + U l         U R                  UR                  5        g)zHandles a bound key event.N)r   r1   r0   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,   r1   r6   __static_attributes__r/   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$ )_WebHelpKeyBindingc   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   )superr?   r   r   r   	__class__s     r   r   _WebHelpKeyBinding.__init__f   s#    	
d,*	 - 	r   c                     UR                   R                  R                  n[        R                  " UR                   UR
                  UR                  5        g r
   )r0   current_bufferdocumentr   OpenReferencePagetextcursor_position)r   r5   docs      r   r6   _WebHelpKeyBinding.Handler   s7    
))
"
"
+
+Ceii33F3FGr   r/   	r8   r9   r:   r;   r<   r   r6   r=   __classcell__rE   s   @r   r?   r?   c   s    !
H Hr   r?   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )_ContextKeyBindingw   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.rB   )rC   rS   r   rD   s     r   r   _ContextKeyBinding.__init__z   s$    	
d,
O	 - r   c                     UR                   R                  R                  R                  UR                   R                  l        g r
   )r0   rH   rI   text_before_cursorconfigrV   r4   s     r   r6   _ContextKeyBinding.Handle   s-    		  ))<< 
IIr   r/   rO   rQ   s   @r   rS   rS   w   s     &> >r   rS   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   )rC   r]   r   )r   r   r   rE   s      r   r   _HelpKeyBinding.__init__   s,    	/4)e48 * r   r/   Tr8   r9   r:   r;   r<   r   r=   rP   rQ   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.rB   )rC   rg   r   rD   s     r   r   _QuitKeyBinding.__init__   s     	/4)	 * r   c                 2    A[         R                  " S5        g )N   )sysexitr4   s     r   r6   _QuitKeyBinding.Handle   s    HHQKr   r/   rO   rQ   s   @r   rg   rg      s     r   rg   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*   )rC   rr   r   rD   s     r   r   _InterruptKeyBinding.__init__   s    	
. / r   c                     UR                   R                  R                  5         UR                   R                  R                  5         g r
   )r0   rH   reset	completerr4   s     r   r6   _InterruptKeyBinding.Handle   s.    	II""$	IIr   r/   rO   rQ   s   @r   rr   rr      s    

   r   rr   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 ru   )rC   r|   r   rD   s     r   r   _StopKeyBinding.__init__   s    	/4) * r   r/   re   rQ   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_keyrS   F7context_keyr?   F8web_help_keyrg   F9quit_keyrr   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   r6   )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   r1   )r   r0   r   s      r   
InitializeKeyBindings.Initialize  s    ==ooc !r   )r   r   r   r   r   r   r   Nrd   )	r8   r9   r:   r;   r<   r   r   r   r=   r/   r   r   r   r      s    ,r   r   )r<   r   rn   &googlecloudsdk.command_lib.interactiver   prompt_toolkitr   prompt_toolkit.key_bindingr   r   objectr   r?   rS   r]   rg   rr   r|   r   r/   r   r   <module>r      s     + 
 
 :  . 
C& CLH H(> >6k k " ;   
k 
5& 5r   