o
    
i0                     @   s   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 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                   @   s  e Zd Z											d@d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dZe	de
fddZ					dAdededededee f
ddZe					dAdededededeed   f
d!d"Ze					dBdededededed# defd$d"Z					dAdededededeeeef  deedef fd%d"Z					dAdededededee f
d&d'Z					dAdededededee f
d(d)Z									dCd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-d.Z		/		dDded0eded,ee fd1d2Zd3eeef fd4d5Zd3efd6d7ZedEdefd9d:ZdEdefd;d<Z				dFdeded=ee dededee fd>d?ZdS )GPrinterTFNP      ⠙⠹⠸⠼⠴⠦⠧⠇⠏|/-\WASABIprettyno_printcolorsiconsline_max	animationanimation_asciihide_animationignore_warnings
env_prefix	timestampc                 C   s   t d|
d}t d|
d}t | _|o| | _|| _t o$| | _|p)|| _	|	| _
|| _tt| _tt| _|| _|rF| j| |rN| j| t|rW|| _dS || _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_pretty r4   B/home/ubuntu/.local/lib/python3.10/site-packages/wasabi/printer.py__init__   s"   


zPrinter.__init__returnc                 C   s   | 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,   )r1   r4   r4   r5   countsD   s   zPrinter.counts titletextshowspacedexitsc                 C      | j ||tj|||d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<   r=   r>   )_get_msgr   GOODr1   r:   r;   r<   r=   r>   r4   r4   r5   goodK      zPrinter.good)r   Fc                 C      d S Nr4   rD   r4   r4   r5   fail`      	zPrinter.fail)r   Tc                 C   rG   rH   r4   rD   r4   r4   r5   rI   k   rJ   c                 C   r?   )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.
        r@   )rB   r   FAILrD   r4   r4   r5   rI   v   rF   c                 C   r?   )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.
        r@   )rB   r   WARNrD   r4   r4   r5   warn   rF   zPrinter.warnc                 C   r?   )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.
        r@   )rB   r   INFOrD   r4   r4   r5   info   rF   zPrinter.infor   bg_coloriconc
              
   C   sx  |sdS | j r@| jtt||}| jtt||}| jtt|}|r0td|| }| j	r:t
|||d}t|dd}|rLd|t|dd}| jr]tj d}
d|
|}|	dusc|rhd	|}| jsq|sqt| |	durtj  tj  | js|r|	dkrzt|  ty } zd
t dd }td||d}~ww t|	 | 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+   stripr-   _colorr   r(   datetimenowstrftimer   printsysstdoutflushstderrRuntimeError	Exceptionjoin	tracebackformat_stack
SystemExitexit)r1   r:   r;   r   rP   rQ   r=   r<   r   r>   r]   etbr4   r4   r5   r;      sF   





zPrinter.text=charc                 C   s   |sdS t |dkrtd|| jr`| jtt|}|r)td||	 }|t
t| jt | d d  }|rAd|nd}tdj||d	d
d}t || jk r`||| jt |   }| jre|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: {}rR      z {} r9   z
{deco}{text}{deco})decor;   T)bold)len
ValueErrorr+   r   r!   rX   r   rY   r   rZ   introundr"   r[   r   r_   )r1   r;   rn   r<   rQ   rp   r4   r4   r5   divider   s*   "zPrinter.dividerdatac                 K   s@   | 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   rv   r   r_   )r1   rw   kwargsr:   r;   r4   r4   r5   r     s   
zPrinter.tablec                 K   s&   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   r_   )r1   rw   ry   r;   r4   r4   r5   r   $  s   zPrinter.row
Loading...c              
   c   s    | j r	d V  d S | jrt| d V  d S tj  t| j|fd}|  zd V  W n t	yC } z|
  tjd |d }~ww |
  tjd tj  d S )N)targetargsrV   z[2K)r   r%   r_   r`   ra   rb   r   _spinnerstartre   	terminatewrite)r1   r;   trk   r4   r4   r5   loading/  s(   



zPrinter.loadingc                 C   s>   t | jD ]}tjd|| tj  t	d qd S )Nz{} {}g?)
	itertoolscycler0   r`   ra   r   r+   rb   timesleep)r1   r;   rn   r4   r4   r5   r}   E  s
   
zPrinter._spinnerrA   c              	   C   s>   | j r
|tjkr
d}| j|  d7  < | j|||||||dS )NFr   )r   rQ   r<   r=   r>   )r&   r   rL   r,   r;   )r1   r:   r;   rA   r<   r=   r>   r4   r4   r5   rB   K  s   	zPrinter._get_msg)TFNNr   r   r   FFr   F)r9   r9   TFN)r9   r9   TFT)	r9   r9   NNNFTFN)r9   rm   TN)rz   )NFFN)__name__
__module____qualname__boolr	   r   rt   rY   r6   propertyr   r8   r   rE   r   r   rI   r   r
   rM   rO   r;   rv   r   r   r   r   r   r}   rB   r4   r4   r4   r5   r      s   	

0





	

=
%
r   )&r\   r   r)   r`   r   rg   collectionsr   
contextlibr   multiprocessingr   typingr   r   r   r   r	   r
   r   r   compatr   tablesr   r   utilr   r   r   r   r   r[   r   r   r   objectr   r4   r4   r4   r5   <module>   s     (