
    Cj5                       % S r SSKJr  SSKrSSKJr  SSKJrJrJrJ	r	J
r
  SSKrSSKJr  \(       a  SSKJr  SSKJr  S	rS
\S'    \rS
\S'    \rS
\S'    \	\\4   r  " S S\5      r " S S\5      r " S S\5      r\" SS9 " S S5      5       r " S S\
5      r\R>                  R@                   " S S5      5       r! " S S\
5      r"g)z

This module contains the `Binding` class and related objects.

See [bindings](/guide/input#bindings) in the guide for details.
    )annotationsN)	dataclass)TYPE_CHECKINGIterableIteratorMapping
NamedTuple)_character_to_key)	TypeAlias)DOMNodez0Binding | tuple[str, str] | tuple[str, str, str]r   BindingTypeBindingIDString	KeyStringc                      \ rS rSrSrSrg)BindingError*   zA binding related error. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       a/home/rurouni/.local/share/pipx/venvs/strix-agent/lib/python3.13/site-packages/textual/binding.pyr   r   *       "r   r   c                      \ rS rSrSrSrg)	NoBinding.   zA binding was not found.r   Nr   r   r   r   r   r   .   r   r   r   c                      \ rS rSrSrSrg)InvalidBinding2   z$Binding key is in an invalid format.r   Nr   r   r   r   r"   r"   2   s    .r   r"   Tfrozenc                     \ rS rSr% SrS\S'    S\S'    SrS\S'    SrS	\S
'    SrS\S'    Sr	S	\S'    Sr
S\S'    SrS\S'    SrS	\S'    \" SS9 " S S5      5       rSrS\S'    SS jrSSS jjr\SS j5       rSrg) Binding6   z#The configuration of a key binding.strkeyaction descriptionTboolshowN
str | Nonekey_displayFprioritytooltipidsystemr$   c                  8    \ rS rSr% SrSrS\S'    SrS\S'   S	rg
)Binding.GroupW   zIA binding group causes the keys to be grouped under a single description.r,   r)   r-   Fr.   compactr   N)	r   r   r   r   r   r-   __annotations__r9   r   r   r   r   Groupr7   W   s    WS'4r   r;   zGroup | Nonegroupc                B    U R                   R                  S5      Gt pX4$ )ziParse a key into a list of modifiers, and the actual key.

Returns:
    A tuple of (MODIFIER LIST, KEY).
+)r*   split)self	modifiersr*   s      r   	parse_keyBinding.parse_keyd   s      ((..-~r   c                ,    [         R                  " XUS9$ )zReturn a new binding with the key and key_display set to the specified values.

Args:
    key: The new key to set.
    key_display: The new key display to set.

Returns:
    A new binding with the key set to the specified value.
r*   r1   )dataclassesreplace)r@   r*   r1   s      r   with_keyBinding.with_keym   s     ""4kJJr   c              #    #    [        U5      nU GH5  n[        U[        5      (       a&  [        U5      S;  a  [	        SU< 35      e[        U6 nUR                  R                  S5       H  nUR                  5       nU(       d  [        SUR                  < 35      e[        U5      S:X  a  [        U5      n[        UUR                  UR                  [        UR                  =(       a    UR                  5      UR                  UR                   UR"                  UR$                  UR&                  UR(                  S9
v   M     GM8     g7f)a
  Convert a list of BindingType (the types that can be specified in BINDINGS)
into an Iterable[Binding].

Compound bindings like "j,down" will be expanded into 2 Binding instances.

Args:
    bindings: An iterable of BindingType.

Returns:
    An iterable of Binding.
)      z;BINDINGS must contain a tuple of two or three strings, not ,zCan not bind empty string in    )
r*   r+   r-   r/   r1   r2   r3   r4   r5   r<   N)list
isinstancetuplelenr   r'   r*   r?   stripr"   r
   r+   r-   r.   r/   r1   r2   r3   r4   r5   r<   )clsbindingsbindingr*   s       r   make_bindingsBinding.make_bindingsy   s     >G'5))w<v-&UV]U`a  "7+
 {{((-iik(7G  s8q=+C0C">> ' 3 3g11BgllC ' 3 3$--#OOzz">>!--  .  s   E	Er   )returnztuple[list[str], str]N)r*   r)   r1   r0   rY   r'   )rU   zIterable[BindingType]rY   zIterable[Binding])r   r   r   r   r   r:   r-   r/   r1   r2   r3   r4   r5   r   r;   r<   rB   rH   classmethodrW   r   r   r   r   r'   r'   6   s    -	HoKK D$6"K" Hd/GS-B

 FDRd5 5 5 E<P
K . .r   r'   c                  L    \ rS rSr% SrS\S'    S\S'    S\S'    S	rS
\S'   Srg)ActiveBinding   zmInformation about an active binding (returned from [active_bindings][textual.screen.Screen.active_bindings]).r   noder'   rV   r.   enabledr,   r)   r3   r   N)r   r   r   r   r   r:   r3   r   r   r   r   r]   r]      s+    w
M0"MOGS+r   r]   c                      \ rS rSrSr S   SS jjrSS jrSS jr\SS j5       r	SS jr
SS	 jr\SS
 j5       rSS jr\SS j5       r    S             SS jjrSS jrSrg)BindingsMap   zManage a set of bindings.Nc                    0 U l          [        R                  U=(       d    0 5       H8  nU R                   R                  UR                  / 5      R                  U5        M:     g)a  Initialise a collection of bindings.

Args:
    bindings: An optional set of initial bindings.

Note:
    The iterable of bindings can contain either a `Binding`
    instance, or a tuple of 3 values mapping to the first three
    properties of a `Binding`.
N)key_to_bindingsr'   rW   
setdefaultr*   append)r@   rU   rV   s      r   __init__BindingsMap.__init__   sM     :<N,,X^<G  ++GKK<CCGL =r   c                n    U R                   R                  UR                  / 5      R                  U5        g)z;Add a new binding.

Args:
    binding: New Binding to add.
N)re   rf   r*   rg   )r@   rV   s     r   _add_bindingBindingsMap._add_binding   s)     	''R8??Hr   c           
         [        U R                  R                  5        VVVs/ s H  u  pU  H  nX4PM     M     snnn5      $ s  snnnf )z7Iterating produces a sequence of (KEY, BINDING) tuples.)iterre   items)r@   r*   rU   rV   s       r   __iter__BindingsMap.__iter__   sQ     &*%9%9%?%?%A%AMC'G ' %A
 	
s   Ac                     U " 5       nXl         U$ )zConstruct a BindingsMap from a dict of keys and bindings.

Args:
    keys: A dict that maps a key on to a list of `Binding` objects.

Returns:
    New `BindingsMap`
re   )rT   keysrU   s      r   	from_keysBindingsMap.from_keys   s     5#' r   c                X    [        5       nU R                  R                  5       Ul        U$ )zBReturn a copy of this instance.

Return:
    New bindings object.
)rb   re   copy)r@   rx   s     r   rx   BindingsMap.copy   s'     }#3388:r   c              #  (   #    U R                   v   g 7frZ   rs   )r@   s    r   __rich_repr__BindingsMap.__rich_repr__   s     """s   c                    0 nU HG  nUR                   R                  5        H&  u  pEUR                  U/ 5      R                  U5        M(     MI     [        R                  U5      $ )z^Merge a bindings.

Args:
    bindings: A number of bindings.

Returns:
    New `BindingsMap`.
)re   ro   rf   extendrb   ru   )rT   rU   rt   	_bindingsr*   key_bindingss         r   mergeBindingsMap.merge   s\     *,!I%.%>%>%D%D%F!R(//= &G " $$T**r   c           
       ^ [        5       n0 n[        U R                  R                  5       5      nU GH  u  pVU GH  nUR                  mTc  M  UR                  T5      =n(       d  M/  UR                  S5      n	U HO  u  pZUR                  5       n[        U4S jU
 5       5      (       d  M1  XPR                  ;   d  MB  U R                  U	 MQ     U	 H  nXR                  ;   d  X;   d  M  U R                  R                  U/ 5      UR                  U/ 5      -   nU HP  nUR                  (       a+  UR                  UR                  5      UR                  :w  a  M?  UR                  U5        MR     XR                  ;   d  M  U R                  U	 M     U	 H2  nUR                  U/ 5      R                  UR                  USS95        M4     GM     GM     U R                  R                  U5        [        U5      $ )a  Replace bindings for keys that are present in `keymap`.

Preserves existing bindings for keys that are not in `keymap`.

Args:
    keymap: A keymap to overlay.

Returns:
    KeymapApplyResult: The result of applying the keymap, including any clashed bindings.
NrM   c              3  @   >#    U  H  oR                   T:H  v   M     g 7frZ   )r4   ).0rV   
binding_ids     r   	<genexpr>+BindingsMap.apply_keymap.<locals>.<genexpr>+  s     T|GzzZ7|s   rE   )setrO   re   ro   r4   getr?   rS   anyr*   addrf   rg   rH   updateKeymapApplyResult)r@   keymapclashed_bindingsnew_bindingsre   r*   rU   rV   keymap_key_stringkeymap_keysr   
keymap_keyclashing_bindingsclashed_bindingr   s                 @r   apply_keymapBindingsMap.apply_keymap  s    *-13t3399;<,MC#$ZZ
% )/

:(>>$>"3"9"9#">K .=)!iikT|TTT"&:&::$($8$8$=	 .= '2
&*>*>>)9
 150D0D0H0H *B1 , 0 0R @1A- 4E %4$6$6(.

?3E3E(F'6':':); %5$8$8$I 4E  *-A-AA$($8$8$D+ '2. '2
$//
B?FF#,,,N '2Q $ -^ 	##L1 !122r   c                    U R                   R                  5        VVs/ s H"  nU  H  nUR                  (       d  M  UPM     M$     nnnU$ s  snnf )z"A list of bindings for shown keys.)re   valuesr/   )r@   rU   rV   rt   s       r   
shown_keysBindingsMap.shown_keysO  sS    
 !00779
9#|| # 9 	 
 
s
   A
Ac                   UR                  S5       Vs/ s H  owR                  5       PM     nnU HL  nU R                  R                  U/ 5      R	                  [        UUU[        U=(       a    U5      UUS95        MN     gs  snf )a  Bind keys to an action.

Args:
    keys: The keys to bind. Can be a comma-separated list of keys.
    action: The action to bind the keys to.
    description: An optional description for the binding.
    show: A flag to say if the binding should appear in the footer.
    key_display: Optional string to display in the footer for the key.
    priority: Is this a priority binding, checked form app down to focused widget?
rM   )r/   r1   r2   N)r?   rS   re   rf   rg   r'   r.   )	r@   rt   r+   r-   r/   r1   r2   r*   all_keyss	            r   bindBindingsMap.bindZ  sx    & ,0::c?;?CIIK?;C  ++C4;;k2d3 +%	  <s   Bc                \     U R                   U   $ ! [         a    [        SU 35      Sef = f)zGet a list of bindings for a given key.

Args:
    key: Key to look up.

Raises:
    NoBinding: If the binding does not exist.

Returns:
    A list of bindings associated with the key.
zNo binding for N)re   KeyErrorr   )r@   r*   s     r   get_bindings_for_key BindingsMap.get_bindings_for_keyz  s;    	?'',, 	?ocU34$>	?s    +rs   rZ   )rU   zIterable[BindingType] | NonerY   None)rV   r'   rY   r   )rY   zIterator[tuple[str, Binding]])rt   zdict[str, list[Binding]]rY   rb   )rY   rb   )rY   zrich.repr.Result)rU   zIterable[BindingsMap]rY   rb   )r   KeymaprY   r   )rY   list[Binding])r,   TNF)rt   r)   r+   r)   r-   r)   r/   r.   r1   r0   r2   r.   rY   r   )r*   r)   rY   r   )r   r   r   r   r   rh   rk   rp   r[   ru   rx   r{   r   r   propertyr   r   r   r   r   r   r   rb   rb      s    # 26M.M 
M*I
  # + +?3B   "&  	
     
@?r   rb   c                  $    \ rS rSr% SrS\S'   Srg)r   i  z The result of applying a keymap.zset[Binding]r   r   N)r   r   r   r   r   r:   r   r   r   r   r   r     s    *""Jr   r   )#r   
__future__r   rF   r   typingr   r   r   r   r	   	rich.reprrichtextual.keysr
   typing_extensionsr   textual.domr   r   r:   r)   r   r   r   	Exceptionr   r   r"   r'   r]   reprautorb   r   r   r   r   <module>r      s    #  ! I I  *+#KY K M   
 	9 
 
)+	, X#9 ##	 #/Y / $q q qh
,J 
, P? P? P?fK
 Kr   