
    AHjo8                    H   d 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
 ddlmZ ddlmZmZmZ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 erddlmZ  eddddddddddddd      Zej@                  jC                          ed       G d d                    Z e       Z"y)a  
The Style class contains all the information needed to generate styled terminal output.

You won't often need to create Style objects directly, if you are using [Content][textual.content.Content] for output.
But you might want to use styles for more customized widgets.
    )annotations)	dataclass)cached_property	lru_cache)dumpsloads)
attrgetter)TYPE_CHECKINGAnyIterableMappingN)Style)TerminalTheme)
active_app)Color)
StylesBase
background
foregroundbolddimitalic	underline
underline2reversestrikeblinklink
auto_color_metaT)frozenc                  L   e Zd ZU dZdZded<   dZded<   dZded<   dZded<   dZ	ded	<   dZ
ded
<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   d/dZed0d       Zed1d       Zd1dZd2dZd0dZd3dZed3d       Zed3d       Z ed       d4d!       ZeZed5d"       Z ed6d7d#       Z!ed8d$       Z"e	 d6	 	 	 	 	 d9d%       Z#ed:d&       Z$ed;d'       Z%ed<d(       Z&d=d)Z'ed5d*       Z(ed5d+       Z)e*d0d,       Z+ed>d-       Z,ed?d.       Z-y)@r   zRepresents a style in the Visual interface (color and other attributes).

    Styles may be added together, which combines their style attributes.

    NzColor | Noner   r   zbool | Noner   r   r   r   r   r   r   r   z
str | Noner   zbytes | Noner   Fboolr   c              #    K   d| j                   d f d| j                  d f d| j                  d f d| j                  d f d| j                  d f d| j
                  d f d| j                  d f d| j                  d f d	| j                  d f d
| j                  d f d| j                  d f | j                  d| j                  f y y w)Nr   r   r   r   r   r   r   r   r   r   r   meta)r   r   r   r   r   r   r   r   r   r   r   r   r$   selfs    E/root/tools/cai/cai_env/lib/python3.12/site-packages/textual/style.py__rich_repr__zStyle.__rich_repr__C   s     DOOT11DOOT11dii%%TXXt##T))4>>4//DOOT11t++T))tzz4''dii%%::!$))## "s   CCc                ~   | j                   d u xr | j                  d u xr | j                  d u xr | j                  d u xr~ | j                  d u xrn | j
                  d u xr^ | j                  d u xrN | j                  d u xr> | j                  d u xr. | j                  d u xr | j                  d u xr | j                  d u S N)r   r   r   r   r   r   r   r   r   r   r   r   r%   s    r'   _is_nullzStyle._is_nullS   s     OOt# #4'#		T!# D # t#	#
 $&# 4'# $# t## 

d"# 		T!# 

d"	
    c                *    t        t        |             S )z!A hash of the style's attributes.)hash_get_hash_attributesr%   s    r'   r.   z
Style.hashd   s     (.//r,   c                    | j                   S r*   )r.   r%   s    r'   __hash__zStyle.__hash__i   s    yyr,   c                `    t        |t              st        S | j                  |j                  k(  S r*   )
isinstancer   NotImplementedr.   )r&   others     r'   __eq__zStyle.__eq__l   s%    %'!!yyEJJ&&r,   c                    | j                    S r*   )r+   r%   s    r'   __bool__zStyle.__bool__q   s    ==  r,   c                    | j                   S r*   )style_definitionr%   s    r'   __str__zStyle.__str__t   s    $$$r,   c                j   g }|j                   }| j                   || j                  j                         | j                   |d| j                  j                          | j                   || j                  rdnd       | j
                   || j
                  rdnd       | j                   || j                  rdnd       | j                   || j                  rdnd	       | j                   || j                  rd
nd       | j                   || j                  rdnd       | j                   || j                  rdnd       | j                  Id| j                  vr |d| j                   d       n$d| j                  vr |d| j                   d       | j                  s| j                  j                         D ]V  \  }}t        |t               r4d|vr || d| d       )d|vr || d| d       < || d|       J || d|       X dj#                  |      S )z=Style encoded in a string (may be parsed from `Style.parse`).on r   not boldr   not dimr   
not italicr   not underliner   not underline2r   
not striker   	not blink'zlink='"zlink="z='z="= appendr   cssr   r   r   r   r   r   r   r   r   r   r$   itemsr3   strjoinr&   outputoutput_appendkeyvalues        r'   r:   zStyle.style_definitionw   s    ??&$//--.??&C 3 345699 DII&:>88488%;;;"dkk(|D>>%+_M??&$//,?OP;;"dkk(|D::!TZZ'[A99 $))#tyyk34DII%tyyk34::!"iioo/ 	6
UeS)#~%Rwa&89C%Rwa&89%Qui&89!SE5)"45	6 xxr,   c                ~   g }|j                   }| j                   || j                  j                         | j                   |d| j                  j                          | j                   || j                  rdnd       | j
                   || j
                  rdnd       | j                   || j                  rdnd       | j                   || j                  rdnd	       | j                   || j                  rd
nd       | j                   || j                  rdnd       | j                   || j                  rdnd       | j                   |d       | j                  >| j                  j                         D ]!  \  }}t        |t               s || d       # dj#                  |      S )z(Identifier used to close tags in markup.r=   r   r>   r   r?   r   r@   r   rA   r   rB   r   rC   r   rD   r   rG   rH   rI   rO   s        r'   
markup_tagzStyle.markup_tag   sl    ??&$//--.??&C 3 345699 DII&:>88488%;;;"dkk(|D>>%+_M??&$//,?OP;;"dkk(|D::!TZZ'[A99 &!::!"iioo/ -
UeS)!SE),- xxr,   i   )maxsizec                   t        |t              r6t        | j                  | j                  j                  dk(  r|j                  n| j                  |j                  z   |j                  |j                  j                  dk(  r| j                  n|j                  |j
                  | j
                  n|j
                  |j                  | j                  n|j                  |j                  | j                  n|j                  |j                  | j                  n|j                  |j                  | j                  n|j                  |j                  | j                  n|j                  |j                  | j                  n|j                  |j                  | j                  n|j                  |j                  | j                  n|j                  | j                  5|j                  )t        i | j                   |j                               }|S |j                  | j                        }|S |j                        }|S || S t"        S )Nr   )r3   r   r   ar   r   r   r   r   r   r   r   r   r   r   r   r$   r4   )r&   r5   	new_styles      r'   __add__zStyle.__add__   s   eU# /4??3D3D3I $$5+;+;; ((0E4D4D4F4F!4K OO))"ZZ/		UZZ!II-599$||3"'//"9u#(#3#3#;AQAQ % 55==$||3#kk1

u{{"ZZ/		UZZ zz-%++2I 5TYY5%**56+I4  ).(;$**/I4  BG/I4 ]K!!r,   c                    t         S )z%Get a null (no color or style) style.)
NULL_STYLE)clss    r'   nullz
Style.null   s
     r,   c                    ddl m} 	 t        j                         }|j
                  j                  |      S # t        $ r  |||      cY S w xY w)zParse a style from text.

        Args:
            text_style: A style encoded in a string.
            variables: Optional mapping of CSS variables. `None` to get variables from the app.

        Returns:
            New style.
        r   )parse_style)textual.markupr`   r   getLookupError
stylesheet)r]   
text_style	variablesr`   apps        r'   parsezStyle.parse   sM     	/	6.."C ~~))*55  	6z955	6s   7 AAc                |    	 | j                  |      }|j                  S # t        $ r |j                         cY S w xY w)zProduces a normalized from of a style, used to match closing tags with opening tags.

        Args:
            text_style: Style to normalize.

        Returns:
            Normalized markup tag.
        )rh   	ExceptionstriprU   )r]   re   styles      r'   _normalize_markup_tagzStyle._normalize_markup_tag   sC    	&IIj)E   	&##%%	&s    ;;c                   t        |j                  dnt        j                  |j                  |      |j                  dnt        j                  |j                  |      |j
                  |j                  |j                  |j                  |j                  |j                  |j                  |j                  |j                  |j                        S )zBuild a Style from a (Rich) Style.

        Args:
            rich_style: A Rich Style object.
            theme: Optional Rich [terminal theme][rich.terminal_theme.TerminalTheme].

        Returns:
            New Style.
        N
r   r   r   r   r   r   r   r   r   r   )r   bgcolorr   from_rich_colorcolorr   r   r   r   r   r   r   r   r   r   )r]   
rich_stylethemes      r'   from_rich_stylezStyle.from_rich_style  s      %%- **:+=+=uE ##+ **:+;+;UC$$ **!,,&&$$"""")
 	
r,   c                l   |j                   }t        |j                  |j                  r$t	        ddd|j
                  j                  d      n|j
                  |j                  |j                  |j                  |j                  |j                  |j                  |j                  |j                  
      S )zCreate a Visual Style from a Textual styles object.

        Args:
            styles: A Styles object, such as `my_widget.styles`.

        r   T)auto)r   r   r   r   r   r   r   r   )re   r   r   r   r   rr   rX   r   r   r   r   r   r   )r]   stylesre   s      r'   from_styleszStyle.from_styles3  s     &&
 $$ aAv||~~D9\\!!$$ **!,,&&$$((
 	
r,   c                0    t        t        i |            S )zCreate a Visual Style containing meta information.

        Args:
            meta: A dictionary of meta information.

        Returns:
            A new Style.
        r   )r   r   )r]   r$   s     r'   	from_metazStyle.from_metaM  s     5D?++r,   c                   | j                   dn| j                  | j                   z   }t        |dn|j                  | j                  dn| j                  j                  | j                  | j
                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  d      S | j                        S )zbConvert this Styles into a Rich style.

        Returns:
            A Rich style object.
        Nrr   rp   r   r   r   r   r   r   r   r   r   r$   )r   r   	RichStyle
rich_colorr   r   r   r   r   r   r   r   r   r   r$   )r&   rr   s     r'   rs   zStyle.rich_styleY  s     /T__t5V-$U-=-= OO3D9S9S;;nnLL;;**+
 	
 26
 	
r,   c                   | j                   dn| j                  | j                   z   }t        |dn|j                  | j                  dn| j                  j                  | j                  | j
                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  i | j                  d||fi      S )zGet a Rich style with the given offset included in meta.

        This is used in text seleciton.

        Args:
            x: X coordinate.
            y: Y coordinate.

        Returns:
            A Rich Style object.
        Noffsetr~   )r   r   r   r   r   r   r   r   r   r   r   r   r   r$   )r&   xyrr   s       r'   rich_style_with_offsetzStyle.rich_style_with_offsetp  s     /T__t5V-$U-=-= OO3D9S9S;;nnLL;;**0DII0x!Q0
 	
r,   c                    t        | j                  | j                  | j                  | j                  | j
                  | j                  | j                  | j                  | j                  | j                  
      S )zThe style without any colors.ro   )r   r   r   r   r   r   r   r   r   r   r   r%   s    r'   without_colorzStyle.without_color  sW     ;;nnLL;;****
 	
r,   c                D    t        | j                  | j                        S )z4Just the background color, with no other attributes.r{   )r   r   r   r%   s    r'   background_stylezStyle.background_style  s     T__DJJ77r,   c                T    | j                   du xs | j                   j                  dk(  S )z+Is the foreground transparent (or not set)?Nr   )r   rX   r%   s    r'   has_transparent_foregroundz Style.has_transparent_foreground  s'     $&@$//*;*;q*@@r,   c                B    t        |      }t        |t        |            S )z*Add a number of styles and get the result.)itersumnext)r]   rx   iter_styless      r'   combinezStyle.combine  s     6l;[ 122r,   c                H    | j                   i S t        | j                         S )z=Get meta information (can not be changed after construction).)r   r   r%   s    r'   r$   z
Style.meta  s!     ZZ'r>U4::->>r,   )returnzrich.repr.Result)r   r"   )r   int)r5   r   r   r"   )r   rM   )r5   zobject | Noner   r   )r   r   r*   )re   rM   rf   zdict[str, str] | Noner   r   )re   rM   r   rM   )rs   r   rt   zTerminalTheme | Noner   r   )rx   r   r   r   )r$   Mapping[str, Any]r   r   )r   r   )r   r   r   r   r   r   )rx   zIterable[Style]r   r   )r   r   ).__name__
__module____qualname____doc__r   __annotations__r   r   r   r   r   r   r   r   r   r   r   r   r(   r   r+   r.   r1   r6   r8   r;   r:   rU   r   rZ   __radd__classmethodr^   rh   rm   ru   ry   r|   rs   r   r   r   propertyr   r   r$    r,   r'   r   r   ,   s'     $J##J#D+CFK!I{!"J"G[FKE;D*E<J$  
 
  0 0'
!% '  ' R    > x  " ! "D H  6 6$     BF"
""
+?"
	"
 "
H 
 
2 	, 	, 
 
,
8 
 
 8 8 A A 3 3
 ? ?r,   r   )#r   
__future__r   dataclassesr   	functoolsr   r   marshalr   r   operatorr	   typingr
   r   r   r   	rich.reprrich
rich.styler   r   rich.terminal_themer   textual._contextr   textual.colorr   textual.css.stylesr   r/   reprrw   r\   r   r,   r'   <module>r      s    # ! 0    8 8  ) - ' - "
	
 " 
$A? A?  A?H W
r,   