
    "Zj0                         d dl Z d dlZd dlZd dlZd dl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mZmZmZmZmZmZmZ ddlmZ ddlmZmZ dd	lmZmZmZmZ dd
lmZ  ddlm!Z!m"Z"m#Z#  G d de$          Z%dS )    N)Counter)contextmanager)Process)Any
CollectionDictNoReturnOptionalUnioncastoverload   )Literal)rowtable)COLORSICONSMESSAGES
can_render)color)locale_escapesupports_ansiwrapc                   p   e Zd Z	 	 	 	 	 	 	 	 	 	 	 d3ded	ed
ee         dee         dededededededefdZe	de
fd            Z	 	 	 	 	 d4dededededee         f
dZe	 	 	 	 	 d4dededededeed                  f
d            Ze	 	 	 	 	 d5dededededed         defd             Z	 	 	 	 	 d4dededededeeeef                  deedef         fd!Z	 	 	 	 	 d4dededededee         f
d"Z	 	 	 	 	 d4dededededee         f
d#Z	 	 	 	 	 	 	 	 	 d6deded$eeeef                  d%eeeef                  d&ee         deded	edee         fd'Z	 	 	 	 d7ded)eded&ee         fd*Zd+eeef         fd,Zd+efd-Zed8defd/            Zd8defd0Z	 	 	 	 d9deded1ee         dededee         fd2ZdS ):PrinterTFNP      ⠙⠹⠸⠼⠴⠦⠧⠇⠏|/-\WASABIprettyno_printcolorsiconsline_max	animationanimation_asciihide_animationignore_warnings
env_prefix	timestampc                 Z   t          j        d                    |
          d          }t          j        d                    |
          d          }t                      | _        |o| | _        || _        t                      o| | _        |p|| _	        |	| _
        || _        t          t                    | _        t          t                    | _        || _        |r| j                            |           |r| j                            |           t'          |          r|n|| _        dS )a  Initialize the command-line printer.

        pretty (bool): Pretty-print output (colors, icons).
        no_print (bool): Don't actually print, just return.
        colors (Optional[Dict]): Optional color values to add or overwrite, name mapped to value.
        icons (Optional[Dict]): Optional icons to add or overwrite. Name mapped to unicode icon.
        line_max (int): Maximum line length (for divider).
        animation (str): Steps of loading animation for loading() method.
        animation_ascii (str): Alternative animation for ASCII terminals.
        hide_animation (bool): Don't display animation, e.g. for logs.
        ignore_warnings (bool): Do not output messages of type MESSAGE.WARN.
        env_prefix (str): Prefix for environment variables, e.g.
            WASABI_LOG_FRIENDLY.
        timestamp (bool): Print a timestamp (default False).
        RETURNS (Printer): The initialized printer.
        z{}_LOG_FRIENDLYFz{}_NO_PRETTYN)osgetenvformatr   _countsr    r!   r   
show_colorr'   r(   r$   dictr   r"   r   r#   r*   updater   anim)selfr    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   env_log_friendlyenv_no_prettys                 Z/Users/jameslopez/projects/MentorCore/.venv/lib/python3.11/site-packages/wasabi/printer.py__init__zPrinter.__init__   s   < 9%6%=%=j%I%I5QQ	."7"7
"C"CUKK '		2]!2 '//B2B.B,@0@. 6ll%[[
" 	'Kv&&& 	%Je$$$!+I!6!6KIIO			    returnc                     | j         S )zGet the counts of how often the special printers were fired,
        e.g. MESSAGES.GOOD. Can be used to print an overview like "X warnings".
        )r/   )r4   s    r7   countszPrinter.countsD   s    
 |r9    titletextshowspacedexitsc                 L    |                      ||t          j        |||          S )a  Print a success message.

        title (Any): The main text to print.
        text (Any): Optional additional text to print.
        show (bool): Whether to print or not. Can be used to only output
            messages under certain condition, e.g. if --verbose flag is set.
        spaced (bool): Whether to add newlines around the output.
        exits (Optional[int]): Optional toggle to perform a system exit.
        styler@   rA   rB   )_get_msgr   GOODr4   r>   r?   r@   rA   rB   s         r7   goodzPrinter.goodK   .    " }}4x}4e  
 
 	
r9   )r   Fc                     d S N rH   s         r7   failzPrinter.fail`   	     	r9   )r   Tc                     d S rL   rM   rH   s         r7   rN   zPrinter.failk   rO   r9   c                 L    |                      ||t          j        |||          S )a  Print an error message.

        title (Any): The main text to print.
        text (Any): Optional additional text to print.
        show (bool): Whether to print or not. Can be used to only output
            messages under certain condition, e.g. if --verbose flag is set.
        spaced (bool): Whether to add newlines around the output.
        exits (Optional[int]): Optional toggle to perform a system exit.
        rD   )rF   r   FAILrH   s         r7   rN   zPrinter.failv   rJ   r9   c                 L    |                      ||t          j        |||          S )a  Print a warning message.

        title (Any): The main text to print.
        text (Any): Optional additional text to print.
        show (bool): Whether to print or not. Can be used to only output
            messages under certain condition, e.g. if --verbose flag is set.
        spaced (bool): Whether to add newlines around the output.
        exits (Optional[int]): Optional toggle to perform a system exit.
        rD   )rF   r   WARNrH   s         r7   warnzPrinter.warn   rJ   r9   c                 L    |                      ||t          j        |||          S )a  Print an informational message.

        title (Any): The main text to print.
        text (Any): Optional additional text to print.
        show (bool): Whether to print or not. Can be used to only output
            messages under certain condition, e.g. if --verbose flag is set.
        spaced (bool): Whether to add newlines around the output.
        exits (Optional[int]): Optional toggle to perform a system exit.
        rD   )rF   r   INFOrH   s         r7   infozPrinter.info   rJ   r9   r   bg_coloriconc
                    |sdS | j         r| j                            t          t          |          |          }| j                            t          t          |          |          }| j                            t          t          |                    }|r5t          d                    ||                                                    }| j	        rt          |||          }t          |d          }|r%d                    |t          |d                    }| j        rGt          j                                                            d          }
d                    |
|          }|	|rd	                    |          }| j        s|st#          |           |	t$          j                                         t$          j                                         | j        s|r|	dk    r	 t-          |                                          # t.          $ rV}d
                    t3          j                    dd                   }t7          d                    ||                    d}~ww xY wt%          j        |	           | j        s|r|S dS )a  Print a message.

        title (Any): The main text to print.
        text (Any): Optional additional text to print.
        color (Optional[Union[str, int]]): Optional foreground color.
        bg_color (Optional[Union[str, int]]): Optional background color.
        icon (Optional[str]): Optional name of icon to add.
        spaced (bool): Whether to add newlines around the output.
        show (bool): Whether to print or not. Can be used to only output
            messages under certain condition, e.g. if --verbose flag is set.
        no_print (bool): Don't actually print, just return.
        exits (Optional[int]): Perform a system exit. Optional.
        N{} {})fgbgr   )indentz{}
{}z%Y-%m-%d %H:%M:%Sz{}	{}z
{}

)r    r"   getr   strr#   r   r.   stripr0   _colorr   r*   datetimenowstrftimer!   printsysstdoutflushstderrRuntimeError	Exceptionjoin	tracebackformat_stack
SystemExitexit)r4   r>   r?   r   rY   rZ   rA   r@   r!   rB   rg   etbs                r7   r?   zPrinter.text   sd   2  	F; 	*KOODe$4$4e<<E{tC':':HEEH:>>$sD//22D K%gnnT5&A&ABBHHJJ =u8<<<q)))E 	AOOE4Q+?+?+?@@E> 	0#''))223FGGCOOC//EOOE**E} 	X 	%LLLJJ} = =UaZZ=&u{{}}555  = = =9#9#;#;CRC#@AAB$X__R%;%;<<<= HUOOO= 	H 	L	 	s   *!H 
I+AI&&I+=charc           	         |sdS t          |          dk    r"t          d                    |                    | j        r| j                            t          t          |                    }|r5t          d                    ||                    	                                }|t          t          | j        t          |          z
            dz            dz
  z  }|rd                    |          nd}t          d                    ||	          d
          }t          |          | j        k     r||| j        t          |          z
  z  z   }| j        r|S t          |           dS )ag  Print a divider with a headline:
        ============================ Headline here ===========================

        text (str): Headline text. If empty, only the line is printed.
        char (str): Line character to repeat, e.g. =.
        show (bool): Whether to print or not.
        icon (Optional[str]): Optional icon to display with title.
        Nr   z9Divider chars need to be one character long. Received: {}r\      z {} r=   z
{deco}{text}{deco})decor?   T)bold)len
ValueErrorr.   r    r#   rb   r   rc   r   rd   introundr$   re   r!   ri   )r4   r?   rx   r@   rZ   r{   s         r7   dividerzPrinter.divider   sa     	Ft99>>%vd||   ; 
	A:>>$sD//22D I$W^^D$%?%?@@FFHH3udmc$ii&?AAAEFFJKD*.66==&&&BD&--4d-CC$  D 4yy4=((ddmc$ii&?@@= 	Kdr9   datac                     |                     dd          }t          |fi |}|r|                     |           | j        r|S t	          |           dS )zPrint data as a table.

        data (Union[Collection, Dict]): The data to render. Either a list of lists
            (one per row) or a dict for two-column tables.
        kwargs: Table settings. See tables.table for details.
        r>   N)popr   r   r!   ri   )r4   r   kwargsr>   r?   s        r7   r   zPrinter.table  sd     

7D))T$$V$$ 	 LL= 	Kdr9   c                 P    t          |fi |}| j        r|S t          |           dS )zPrint a table row.

        data (Collection): The individual columns to format.
        kwargs: Row settings. See tables.row for details.
        N)r   r!   ri   )r4   r   r   r?   s       r7   r   zPrinter.row$  s7     4""6""= 	Kdr9   
Loading...c              #   *  K   | j         rd V  d S | j        rt          |           d V  d S t          j                                         t          | j        |f          }|                                 	 d V  nG# t          $ r:}|
                                 t          j                            d           |d }~ww xY w|
                                 t          j                            d           t          j                                         d S )N)targetargsr`   z[2K)r!   r'   ri   rj   rk   rl   r   _spinnerstartro   	terminatewrite)r4   r?   tru   s       r7   loadingzPrinter.loading/  s     = 	EEEEE  	$KKKEEEEEJt}D7;;;AGGIII   
  &&&		
 KKMMMJ[)))Js   6A; ;
B?5B::B?c                    t          j        | j                  D ]g}t          j                            d                    ||                     t          j                                         t          j	        d           hd S )Nz{} {}g?)
	itertoolscycler3   rj   rk   r   r.   rl   timesleep)r4   r?   rx   s      r7   r   zPrinter._spinnerE  sp    ODI.. 	 	DJY--dD99:::JJsOOOO	 	r9   rE   c           	          | j         r|t          j        k    rd}| j        |xx         dz  cc<   |                     |||||||          S )NFr   )r   rZ   r@   rA   rB   )r(   r   rT   r/   r?   )r4   r>   r?   rE   r@   rA   rB   s          r7   rF   zPrinter._get_msgK  si      	EX]$:$:DUq yy4u5tFRW  
 
 	
r9   )TFNNr   r   r   FFr   F)r=   r=   TFN)r=   r=   TFT)	r=   r=   NNNFTFN)r=   rw   TN)r   )NFFN)__name__
__module____qualname__boolr
   r   r   rc   r8   propertyr   r<   r   rI   r   r   rN   r	   r   rU   rX   r?   r   r   r   r   r   r   r   rF   rM   r9   r7   r   r      sq        !% $6&$ %".L .L.L .L 	.L
 ~.L .L .L .L .L .L .L .L .L .L .L`     X #
 

 
 	

 
 }
 
 
 
*  -1   	
  )*   X  "&   	
  w 
   X ,0
 

 
 	

 
 c4i()
 
sD("	#
 
 
 
. #
 

 
 	

 
 }
 
 
 
. #
 

 
 	

 
 }
 
 
 
. +/.2"#9 99 9 c3h(	9
 5c?+9 sm9 9 9 9 }9 9 9 9z "# ## # 	#
 sm# # # #J%
D 01    	
 	 	 	 	  C    ^* S      $#
 

 
 }	

 
 
 }
 
 
 
 
 
r9   r   )&rf   r   r,   rj   r   rq   collectionsr   
contextlibr   multiprocessingr   typingr   r   r   r	   r
   r   r   r   compatr   tablesr   r   utilr   r   r   r   r   re   r   r   r   objectr   rM   r9   r7   <module>r      so        				 



            % % % % % % # # # # # # S S S S S S S S S S S S S S S S S S S S               5 5 5 5 5 5 5 5 5 5 5 5 ! ! ! ! ! ! 4 4 4 4 4 4 4 4 4 4F
 F
 F
 F
 F
f F
 F
 F
 F
 F
r9   