
    AHj+                       d dl mZ d dlmZ d dlmZ d dlmZ d dlZ	d dl
mZ d dlmZ d dlmZ d d	lmZ d d
lmZmZ d dlmZ d dlmZ d dlmZ erd dlmZ e	j:                  j<                   G d de             Ze	j:                  j<                   G d de             Z  G d de      Z!e	j:                  j<                   G d dedd             Z"y)    )annotations)defaultdict)groupby)TYPE_CHECKINGN)Text)events)ComposeResult)Binding)HorizontalGroupScrollableContainer)reactive)Widget)Label)Screenc                      e Zd ZdZy)KeyGroupz7
    KeyGroup {
        width: auto;        
    }
    N)__name__
__module____qualname__DEFAULT_CSS     O/root/tools/cai/cai_env/lib/python3.12/site-packages/textual/widgets/_footer.pyr   r      s	    Kr   r   c                  |     e Zd ZdZddhZdZ ed      Z	 	 	 	 d
	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZddZ	ddZ
dd	Z xZS )	FooterKeyFfooter-key--keyfooter-key--descriptionaq  
    FooterKey {
        width: auto;
        height: 1;
        text-wrap: nowrap;
        background: $footer-item-background;
        .footer-key--key {
            color: $footer-key-foreground;
            background: $footer-key-background;
            text-style: bold;
            padding: 0 1;
        }

        .footer-key--description {
            padding: 0 1 0 0;
            color: $footer-description-foreground;
            background: $footer-description-background;
        }

        &:hover {
            color: $footer-key-foreground;
            background: $block-hover-background;
        }

        &.-disabled {
            text-style: dim;
        }

        &.-compact {
            .footer-key--key {
                padding: 0;
            }
            .footer-key--description {
                padding: 0 0 0 1;
            }
        }
    }
    Tc                    || _         || _        || _        || _        || _        |r|dz  }t
        |   |       d| _        |r|| _        y y )Nz
 -disabledclassesF)	keykey_displaydescriptionaction	_disabledsuper__init__shrinktooltip)	selfr!   r"   r#   r$   disabledr)   r    	__class__s	           r   r'   zFooterKey.__init__Q   s]     &&!|#G)"DL r   c                   | j                  d      }| j                  d      }| j                  }| j                  d      j                  }| j                  d      j                  }| j                  }|r[t        j                  d|j                  z  |z   d|j                  z  z   |fd|j                  z  |z   d|j                  z  z   |f      }nt        j                  ||f      }|j                  | j                         |S )Nr   r    )get_component_rich_styler"   get_component_stylespaddingr#   r   assembleleftrightstylize_before
rich_style)r*   	key_styledescription_styler"   key_paddingdescription_paddingr#   
label_texts           r   renderzFooterKey.renderg   s   112CD	 99:ST&&//0ABJJ"77%

' 	 &&+***[83ARAR;RR
 -222!"/5556 &	J Y'?@J!!$//2r   c                    | j                   r| j                  j                          y | j                  j                  | j                         y N)r%   appbellsimulate_keyr!   r*   s    r   on_mouse_downzFooterKey.on_mouse_down   s,    >>HHMMOHH!!$((+r   c                (    | j                  |d       y )N-compact)	set_class)r*   compacts     r   _watch_compactzFooterKey._watch_compact   s    w
+r   )F rI   )r!   strr"   rJ   r#   rJ   r$   rJ   r+   boolr)   rJ   returnNone)rL   r   rL   rM   )rG   rK   rL   rM   )r   r   r   ALLOW_SELECTCOMPONENT_CLASSESr   r   rG   r'   r<   rC   rH   __classcell__r,   s   @r   r   r      s    L!
%KN tnG  ## # 	#
 # # # 
#,:,,r   r   c                      e Zd ZdZy)FooterLabelz6Text displayed in the footer (used by binding groups).N)r   r   r   __doc__r   r   r   rT   rT      s    @r   rT   c                       e Zd ZdZdZ edd      Z	  edd      Z	  ed      Z	  ed      Z		 ddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fd	Z
dd
ZddZddZddZddZddZ xZS )FooterFa  
    Footer {
        layout: horizontal;        
        color: $footer-foreground;
        background: $footer-background;
        dock: bottom;
        height: 1;
        scrollbar-size: 0 0;
        &.-compact {
            FooterLabel {
                margin: 0;
            }
            FooterKey {
                margin-right: 1;
            }
            FooterKey.-grouped {
                margin: 0 1;            
            }
            FooterKey.-command-palette  {
                padding-right: 0;
            }
        }
        FooterKey.-command-palette  {
            dock: right;
            padding-right: 1;
            border-left: vkey $foreground 20%;
        }
        HorizontalGroup.binding-group {            
            width: auto;
            height: 1;
            layout: horizontal;
        }
        KeyGroup.-compact {            
            FooterKey.-grouped {
                margin: 0;
            }
            margin: 0 1 0 0;
            padding-left: 1;
        }

        FooterKey.-grouped {
            margin: 0 1;            
        }
        FooterLabel {
            margin: 0 1 0 0;            
            color: $footer-description-foreground;
            background: $footer-description-background;
        }

        &:ansi {
            background: ansi_default;
            .footer-key--key {
                background: ansi_default;
                color: ansi_magenta;
            }
            .footer-key--description {
                background: ansi_default;
                color: ansi_default;
            }
            FooterKey:hover {
                text-style: underline;
                background: ansi_default;
                color: ansi_default;
                .footer-key--key {
                    background: ansi_default;
                }
            }
            FooterKey.-command-palette {
                background: ansi_default;
                border-left: vkey ansi_black;
            }
        }
        
    }
    rE   )toggle_class)repaintTN)nameidr    r+   show_command_paletterG   c               x    t        |   |||||d | j                  t        j                  |       || _        y)a  A footer to show key bindings.

        Args:
            *children: Child widgets.
            name: The name of the widget.
            id: The ID of the widget in the DOM.
            classes: The CSS classes for the widget.
            disabled: Whether the widget is disabled or not.
            show_command_palette: Show key binding to invoke the command palette, on the right of the footer.
            compact: Display a compact style (less whitespace) footer.
        )rZ   r[   r    r+   N)r&   r'   set_reactiverW   r\   rG   )	r*   rZ   r[   r    r+   r\   rG   childrenr,   s	           r   r'   zFooter.__init__   sA    * 		
 	&557KLr   c              #    K   | j                   sy | j                  j                  }|j                         D cg c]  \  }}}}|j                  r|||f }}}}}t        t              }|D ]'  \  }}}||j                     j                  |||f       ) t        |      | j                  _        t        |j                         d       D ]T  \  }}	t        |	      }
|t        |
      dkD  rt        |j                  rdnd      5  |
D ]y  }
|
d   \  }}}t        |j                   | j"                  j%                  |      d|j                  | |xs |j&                  d      j)                  t*        j                  	       { 	 d d d        t-        |j&                         |
D ]t  }
|
d   \  }}}t        |j                   | j"                  j%                  |      |j&                  |j                  | |
      j)                  t*        j                  	       v W | j.                  r| j"                  j0                  r	 || j"                  j2                     \  }}}}t        |j                   | j"                  j%                  |      |j&                  |j                  d| |j4                  xs |j&                         y y y c c}}}}w # 1 sw Y   NxY w# t6        $ r Y y w xY ww)Nc                &    | d   d   j                   S )Nr   )group)multi_bindings_s    r   <lambda>z Footer.compose.<locals>.<lambda>  s    OA$6q$9$?$? r      rE   rI   r   r   z-grouped)r+   r)   r    )rG   )r+   r)   z-command-palette)r    r+   r)   )_bindings_readyscreenactive_bindingsvaluesshowr   listr$   appendlenstylesgrid_size_columnsr   r   rG   r   r!   r?   get_key_displayr#   	data_bindrW   rT   r\   ENABLE_COMMAND_PALETTECOMMAND_PALETTE_BINDINGr)   KeyError)r*   rh   _bindingenabledr)   bindingsaction_to_bindingsrb   multi_bindings_iterablemulti_bindings_nodes               r   composezFooter.compose	  s    ##++55 3B2H2H2J
 
.GWg|| gw'
 
 ).)1 	S%GWgw~~.55w6QR	S ),,>(?%.5%%'?/
 	8*E* ""9:N S%81%<EMMjrJ <*8 
<4B14E1''#KK HH44W=#NN)0[$+$Bw/B/B$. $)FNN);<
<< "%"3"344&4 	8N0>q0A-GWg#009++%, '  ii78	8)	8< $$)H)H3BHH4440w  KKHH,,W5''NN.!([#OOBw/B/B  *I$U
$< <:  sP   9K1K
B1K1	A?K	B>K1K" &A/K1K	K1"	K.+K1-K..K1c                    d| _         |j                  j                  sy | j                  r+|| j                  u r| j                  | j                         y y y )NT)rf   r?   	app_focusis_attachedrg   call_after_refresh	recompose)r*   rg   s     r   bindings_changedzFooter.bindings_changedI  sH    #zz##$++ 5##DNN3 !6r   c                    | j                   rD| j                          | j                  d      r!|j                          |j	                          y y y NT)animate)allow_horizontal_scrollrelease_anchor_scroll_right_for_pointerstopprevent_defaultr*   events     r   _on_mouse_scroll_downzFooter._on_mouse_scroll_downP  sG    ''!--d-;

%%' < (r   c                    | j                   rD| j                          | j                  d      r!|j                          |j	                          y y y r   )r   r   _scroll_left_for_pointerr   r   r   s     r   _on_mouse_scroll_upzFooter._on_mouse_scroll_upW  sG    ''!,,T,:

%%' ; (r   c                d    | j                   j                  j                  | | j                         y r>   )rg   bindings_updated_signal	subscriber   rB   s    r   on_mountzFooter.on_mount^  s"    ++55dD<Q<QRr   c                N    | j                   j                  j                  |        y r>   )rg   r   unsubscriberB   s    r   
on_unmountzFooter.on_unmounta  s    ++77=r   )r_   r   rZ   
str | Noner[   r   r    r   r+   rK   r\   rK   rG   rK   rL   rM   )rL   r	   )rg   r   rL   rM   )r   zevents.MouseScrollDownrL   rM   )r   zevents.MouseScrollUprL   rM   rN   )r   r   r   rO   r   r   rG   rf   r\   combine_groupsr'   r}   r   r   r   r   r   rQ   rR   s   @r   rW   rW      s    LJKX u:6G#ue4O9#D>5d^N-
  "%)  	
   #  
>>@4((S>r   rW   F)	can_focuscan_focus_children)#
__future__r   collectionsr   	itertoolsr   typingr   	rich.reprrich	rich.textr   textualr   textual.appr	   textual.bindingr
   textual.containersr   r   textual.reactiver   textual.widgetr   textual.widgetsr   textual.screenr   reprautor   r   rT   rW   r   r   r   <module>r      s    " #       % # C % ! !%    k, k, k,\A% A O> Ee O> O>r   