o
    
i\                     @   s(  d dl Z d dlZd dlZd dlZd dlmZmZmZmZ e	ej
dr&ej
jndZep+dZe dvZdZG dd deZejd	ejd
ejdejddd
dd	ddddddddddddddiZejesbdndejesidndejespdnd ejeswd!nd"iZd#Zd$Z			%	%dMd&ed'eeeef  d(eeeef  d)ed*ed+efd,d-ZdNd&ed/ed0ed+efd1d2ZdOd5ed6ed7ed+efd8d9Z 		:	%dPd;ed<ed'eeef d(eeeef eeef f d=ed+efd>d?Z!	dQd@edAeeeef  d0ed+efdBdCZ"dRdEedFed+efdGdHZ#dEed+efdIdJZ$d+efdKdLZ%dS )S    N)AnyOptionalTupleUnionencodingascii)utf8zutf-8ANSI_COLORS_DISABLEDc                   @   s   e Zd ZdZdZdZdZdS )MESSAGESgoodfailwarninfoN)__name__
__module____qualname__GOODFAILWARNINFO r   r   ?/home/ubuntu/.local/lib/python3.10/site-packages/wasabi/util.pyr
      s
    r
               redgreenyellowbluepink   cyan   white   grey   black   u   ✔z[+]u   ✘z[x]u   ⚠z[!]u   ℹz[i]+-Ftextfgbgbold	underlinereturnc                 C   s   t ||}t ||}t|||gs| S g }|r|d |r%|d |r/|d| |r9|d| dd|| S )a  Color text by applying ANSI escape sequence.

    text (str): The text to be formatted.
    fg (Optional[Union[str, int]]): Optional foreground color. String name or 0 - 256 (see COLORS).
    bg (Optional[Union[str, int]]): Optional background color. String name or 0 - 256 (see COLORS).
    bold (bool): Format text in bold.
    underline (bool): Underline text.
    RETURNS (str): The formatted text.
    14z38;5;{}z48;5;{}z[{}m{}[0m;)COLORSgetanyappendformatjoin)r,   r-   r.   r/   r0   stylesr   r   r   color3   s   

r<   P   wrap_maxindentc                 C   s2   |d }|t | }t| } tj| |||dddS )a$  Wrap text at given width using textwrap module.

    text (Any): The text to wrap.
    wrap_max (int): Maximum line width, including indentation. Defaults to 80.
    indent (int): Number of spaces used for indentation. Defaults to 4.
    RETURNS (str): The wrapped text with line breaks.
     F)widthinitial_indentsubsequent_indentbreak_long_wordsbreak_on_hyphens)lenstrtextwrapfill)r,   r>   r?   
indent_str
wrap_widthr   r   r   wrapS   s   rL   2   ...objmax_lenellipsisc                 C   sD   t | }t||kr t|d }d|d| ||| d S |S )av  Wrapper around `repr()` to print shortened and formatted string version.

    obj: The object to represent.
    max_len (int): Maximum string length. Longer strings will be cut in the
        middle so only the beginning and end is displayed, separated by ellipsis.
    ellipsis (str): Ellipsis character(s), e.g. "...".
    RETURNS (str): The formatted representation.
    r   z{} {} {}N)reprrF   intr9   )rO   rP   rQ   stringhalfr   r   r   format_reprh   s
   	 rV   r   r   abadd_symbolsc              	   C   s  |  d}| d}g }td||}| D ]g\}	}
}}}|	dkr0||
| D ]}|| q(|	dks8|	dkrW||| D ]}|rHdt|n|}|t|||d d q>|	d	ks_|	dkr~||
| D ]}|rodt|n|}|t|||d
 d qeqd	|S )aO  Compare two strings and return a colored diff with red/green background
    for deletion and insertions.

    a (str): The first string to diff.
    b (str): The second string to diff.
    fg (Union[str, int]): Foreground color. String name or 0 - 256 (see COLORS).
    bg (Union[Tuple[str, str], Tuple[int, int]]): Background colors as
        (insert, delete) tuple of string name or 0 - 256 (see COLORS).
    add_symbols (bool): Whether to add symbols before the diff lines. Uses '+'
        for inserts and '-' for deletions. Default is False.
    RETURNS (str): The formatted diff.
    
Nequalinsertreplacez{} {}r   )r-   r.   deleter   )
splitdifflibSequenceMatcherget_opcodesr8   r9   INSERT_SYMBOLr<   DELETE_SYMBOLr:   )rX   rY   r-   r.   rZ   a_listb_listoutputmatcheropcodea0a1b0b1itemr   r   r   diff_stringsy   s$   


rp   descriptiondefaultc                 C   s2   |rd |nd}td | ||d}t|}|S )a  Get user input from the command line via raw_input / input.

    description (str): Text to display before prompt.
    default (Optional[Union[str, bool]]): Optional default value to display with prompt.
    indent (int): Indentation in spaces.
    RETURNS (str): User input.
    z (default: {}) z{}{}: )r?   )r9   rL   input)rq   rr   r?   
additionalprompt
user_inputr   r   r   get_raw_input   s   
rx   r^   rT   errorsc                 C   s   t | } | t|d} | S )zMangle non-supported characters, for savages with ASCII terminals.

    string (Any): The string to escape.
    errors (str): The str.encode errors setting. Defaults to `"replace"`.
    RETURNS (str): The escaped string.
    r   )rG   encodeENCODINGdecode)rT   ry   r   r   r   locale_escape   s   r}   c                 C   s&   z|  t W dS  ty   Y dS w )zCheck if terminal can render unicode characters, e.g. special loading
    icons. Can be used to display fallbacks for ASCII terminals.

    string (str): The string to render.
    RETURNS (bool): Whether the terminal can render the text.
    TF)rz   r{   UnicodeEncodeError)rT   r   r   r   
can_render   s   
r   c                  C   s^   t trdS zddlm}  W n ty)   tjdkr#dt jvr&Y dS Y dS Y dS w |   dS )zReturns True if the running system's terminal supports ANSI escape
    sequences for color, formatting etc. and False otherwise.

    RETURNS (bool): Whether the terminal supports ANSI colors.
    Fr   just_fix_windows_consolewin32ANSICONT)	osgetenvENV_ANSI_DISABLEDcoloramar   ImportErrorsysplatformenvironr   r   r   r   supports_ansi   s   
r   )NNFF)r=   r   )rM   rN   )r(   rW   F)Fr   )r^   )&ra   r   r   rH   typingr   r   r   r   hasattrstdoutr   STDOUT_ENCODINGr{   lowerNO_UTF8r   objectr
   r   r   r   r   r5   ICONSrd   re   rG   rS   boolr<   rL   rV   rp   rx   r}   r   r   r   r   r   r   <module>   s    
 

'
