
    Xi"#                        S r SSKJr  SSKJr  SSK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KJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SS jrSS jr\	 " S S5      5       rg)z4Helper functions for writing to terminals and files.    )annotations)SequenceN)final)Literal)TextIO)TerminalFormatter)Lexer)	DiffLexer)PythonLexer   )assert_never   )wcswidthc                 B    [         R                  " SS9u  pU S:  a  Sn U $ )N)P      )fallback(   r   )shutilget_terminal_size)width_s     M/var/www/html/venv/lib/python3.13/site-packages/_pytest/_io/terminalwriter.pyget_terminal_widthr      s'    '':HE rzL    c                   [         R                  R                  S5      S:X  a  g[         R                  R                  S5      S:X  a  g[         R                  R                  S5      (       a  g[         R                  R                  S5      (       a  g[        U S5      =(       a9    U R	                  5       =(       a"    [         R                  R                  S	5      S
:g  $ )N	PY_COLORS1T0FNO_COLORFORCE_COLORisattyTERMdumb)osenvirongethasattrr"   )files    r   should_do_markupr*   $   s    	zz~~k"c)	zz~~k"c)	zz~~j!!	zz~~m$$hVDKKMVbjjnnV6LPV6Vr   c                     \ rS rSr\" S70 SS_SS_SS_SS	_S
S_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_S S!_S"S#_S$S%_S&S'_S(S)_6rS=S>S+ jjr\S?S, j5       r\R                  S@S- j5       r\S?S. j5       r
SAS/ jr  SB         SCS0 jjrS1S2.SDS3 jjrS1S2.SES4 jjrSFSGS5 jjrSHS6 jrSISJS8 jjrSKS9 jrSLS: jr SM     SNS; jjrS<rg*)OTerminalWriter2   black   red   green    yellow!   blue"   purple#   cyan$   white%   Blackr   Red)   Green*   Yellow+   Blue,   Purple-   Cyan.   White/   boldr   lightr   blink   invert   Nc                `   Uc  [         R                  n[        US5      (       aO  UR                  5       (       a:  [         R                  S:X  a&   SS KnUR                  U5      R                  nUc   e Xl	        [        U5      U l        SU l        S U l        SU l        g ! [         a     N8f = f)Nr"   win32r    T)sysstdoutr(   r"   platformcoloramaAnsiToWin32streamImportError_filer*   	hasmarkup_current_line_terminal_widthcode_highlight)selfr)   rY   s      r   __init__TerminalWriter.__init__K   s    <::D4""t{{}}9P(  ++D188'''
)$/+/"  s   B   
B-,B-c                H    U R                   b  U R                   $ [        5       $ N)r`   r   rb   s    r   	fullwidthTerminalWriter.fullwidth\   s#    +'''!##r   c                    Xl         g rf   )r`   )rb   values     r   rh   ri   b   s    $r   c                ,    [        U R                  5      $ )z;Return an estimate of the width so far in the current line.)r   r_   rg   s    r   width_of_current_line$TerminalWriter.width_of_current_linef   s     **++r   c                @   U H!  nX0R                   ;  d  M  [        SU< 35      e   U R                  (       a_  UR                  5        VVs/ s H  u  p4U(       d  M  U R                   U   PM     nnnU(       a  SR	                  S U 5       5      U-   S-   nU$ s  snnf )Nzunknown markup: rU   c              3  .   #    U  H  nS U S3v   M     g7f)z[mN ).0cods     r   	<genexpr>(TerminalWriter.markup.<locals>.<genexpr>r   s     =#se1~s   [0m)	_esctable
ValueErrorr^   itemsjoin)rb   textmarkupnameonescs         r   r}   TerminalWriter.markupk   s    D>>) #3D8!<==  >>8>MHD"'4>>$'CMww===DyP Ns   BBc                   Uc  U R                   n[        R                  S:X  a  US-  nUb9  [        U[	        U5      -
  S-
  S[	        U5      -  -  S5      nX-  nU SU SU 3nOX[	        U5      -  -  n[	        U5      [	        UR                  5       5      -   U::  a  XqR                  5       -  nU R                  " U40 UD6  g )NrT   r   r    )rh   rV   rX   maxlenrstripline)rb   sepchartitlerh   r}   Nfillr   s           r   sepTerminalWriter.sepu   s     I <<7"
 NI
 YU+a/QW5EFJA;DV1UG1TF+D 3w<78D t9s7>>+,,	9NN$$D		$!&!r   Fflushc                   U(       aZ  UR                  SS5      S   nSU;   a  X@l        OU =R                  U-  sl        U R                  " U40 UD6nU R                  XS9  g g )N
r   r   )rsplitr_   r}   	write_raw)rb   msgr   r}   current_lines        r   writeTerminalWriter.write   s^    ::dA.r2Ls{%1"""l2"++c,V,CNN3N, r   c                   U R                   R                  U5        U(       a  U R                  5         g g ! [         a>    UR                  S5      R	                  S5      nU R                   R                  U5         N`f = f)Nzunicode-escapeascii)r]   r   UnicodeEncodeErrorencodedecoder   )rb   r   r   s      r   r   TerminalWriter.write_raw   sk    
	"JJS! JJL  " 	" **-.55g>CJJS!	"s   6 AA>=A>c                L    U R                   " U40 UD6  U R                  S5        g )Nr   )r   )rb   sr}   s      r   r   TerminalWriter.line   s    

1

4r   c                8    U R                   R                  5         g rf   )r]   r   rg   s    r   r   TerminalWriter.flush   s    

r   rr   c                b   U(       a<  [        U5      [        U5      :w  a$  [        S[        U5       S[        U5       S35      eU(       d  S/[        U5      -  nSR                  U5      nU R                  U5      R	                  5       n[        X$SS9 H  u  pVU R                  XV-   5        M     g)	a)  Write lines of source code possibly highlighted.

Keeping this private for now because the API is clunky. We should discuss how
to evolve the terminal writer so we can have more precise color support, for example
being able to write part of a line in one color and the rest in another, and so on.
zindents size (z") should have same size as lines ()rU   r   F)strictN)r   ry   r{   
_highlight
splitlineszipr   )rb   linesindentssource	new_linesindentnew_lines          r   _write_sourceTerminalWriter._write_source   s     s7|s5z1 W.PQTUZQ[P\\]^  dSZ'G5!OOF+668	 #Gu EFIIf'( !Fr   c                Z    US:X  a
  [        5       $ US:X  a
  [        5       $ [        U5        g )Npythondiff)r   r
   r   )rb   lexers     r   _get_pygments_lexer"TerminalWriter._get_pygments_lexer   s)    H= f_;r   c                >   SSK Jn  [        R                  " S5      n[        R                  " SS5      n [	        X2S9$ ! [
        R                  R                   a  nU" SU S35      UeS nAf[
        R                  R                   a  nU" S	U S
35      UeS nAff = f)Nr   )
UsageErrorPYTEST_THEMEPYTEST_THEME_MODEdark)bgstylez9PYTEST_THEME environment variable has an invalid value: 'zC'. Hint: See available pygments styles with `pygmentize -L styles`.z>PYTEST_THEME_MODE environment variable has an invalid value: 'z7'. The allowed values are 'dark' (default) and 'light'.)	_pytest.config.exceptionsr   r%   getenvr   pygmentsutilClassNotFoundOptionError)rb   r   theme
theme_modees        r   _get_pygments_formatter&TerminalWriter._get_pygments_formatter   s    8		.)YY2F;
	$
@@}}** 	KE7 SS S  }}(( 	PQ[P\ ]G G 	s!   > BA))!B
BBc                   U(       a"  U R                   (       a  U R                  (       d  U$ U R                  U5      nU R                  5       n[        R
                  " XU5      nUS   S:X  a  US   S:w  a  USS nSU-   nU$ )z5Highlight the given source if we have markup support.r   r   Nrw   )r^   ra   r   r   r   	highlight)rb   r   r   pygments_lexerpygments_formatterhighlighteds         r   r   TerminalWriter._highlight   s     T^^43F3FM11%8!99;#--$6

 r?d"vbzT'9%cr*K
  +-r   )r_   r]   r`   ra   r^   rf   )r)   zTextIO | NonereturnNoner   int)rk   r   r   r   )r|   strr}   boolr   r   )NN)
r   r   r   z
str | Nonerh   z
int | Noner}   r   r   r   )r   r   r   r   r}   r   r   r   )r   r   r   r   r   r   )rU   )r   r   r}   r   r   r   )r   r   )rr   )r   Sequence[str]r   r   r   r   )r   zLiteral['python', 'diff']r   r	   )r   r   )r   )r   r   r   zLiteral['diff', 'python']r   r   )__name__
__module____qualname____firstlineno__dictrx   rc   propertyrh   setterrm   r}   r   r   r   r   r   r   r   r   r   __static_attributes__rr   r   r   r,   r,   2   s      	
             !" #$ %& '( )I.#" $ $
 % % , , ! $	#"#" #" 	#"
 #" 
#"J 05 
- 49  )& ( ?G";	 r   r,   r   )r)   r   r   r   )__doc__
__future__r   collections.abcr   r%   r   rV   typingr   r   r   r   pygments.formatters.terminalr   pygments.lexerr	   pygments.lexers.diffr
   pygments.lexers.pythonr   compatr   wcwidthr   r   r*   r,   rr   r   r   <module>r      s[    : " $ 	  
     :   * . !  O O Or   