o
    pf                     @   s   d Z ddlmZmZ ddlZddlZddlmZmZm	Z	 ej
r9ddlmZmZmZmZmZ ddlmZ ddlmZ 					
				dddZdS )zNRender a FS object as text tree views.

Color is supported on UNIX terminals.
    )print_functionunicode_literalsN)abspathjoinnormpath)ListOptionalTextTextIOTuple   )FS)Info/   Tc	                    s:  pt j|du rtddpd}tdo }	du r*t jd}
|
r(dn|	| dkr;r;d}dd	d
 nd}ddd d|d fddfddfdd	fdd
fdddd dd ddd 	
fd d!tt	|g  d" d# fS )$a  Render a directory structure in to a pretty tree.

    Arguments:
        fs (~fs.base.FS): A filesystem instance.
        path (str): The path of the directory to start rendering
            from (defaults to root folder, i.e. ``'/'``).
        file (io.IOBase): An open file-like object to render the
            tree, or `None` for stdout.
        encoding (str, optional): Unicode encoding, or `None` to
            auto-detect.
        max_levels (int, optional): Maximum number of levels to
            display, or `None` for no maximum.
        with_color (bool, optional): Enable terminal color output,
            or `None` to auto-detect terminal.
        dirs_first (bool): Show directories first.
        exclude (list, optional): Option list of directory patterns
            to exclude from the tree render.
        filter (list, optional): Optional list of files patterns to
            match in the tree render.

    Returns:
        (int, int): A tuple of ``(<directory count>, <file count>)``.

    Nencodingzutf-8isattywinFu   │u   ├u   ──u   └|z--`z    z   c                    s   t |  d dS )zWrite a line to the output.fileN)print)liner    @/home/ertert/spirit/venv/lib/python3.10/site-packages/fs/tree.pywriteP   s   zrender.<locals>.writec                        s| S d|  S )zFormat the prefix lines.z[32m%s[0mr   )prefix
with_colorr   r   format_prefixX      zrender.<locals>.format_prefixc                    r   )zFormat a directory name.z[1;34m%s[0mr   )dirnamer   r   r   format_dirname_   r"   zrender.<locals>.format_dirnamec                    r   )zFormat an error.z[31m%s[0mr   )msgr   r   r   format_errorf   r"   zrender.<locals>.format_errorc                    s    s| S |  drd|  } | S )zFormat a filename..z[33m%s[0m)
startswith)fnamer   r   r   format_filenamem   s
   
zrender.<locals>.format_filenamec                 S   s   | j  | j fS )z2Get the info sort function with directories first.)is_dirnamelowerinfor   r   r   sort_key_dirs_firstv   s   z#render.<locals>.sort_key_dirs_firstc                 S   s
   | j  S )z7Get the default info sort function using resource name.)r,   r-   r.   r   r   r   sort_key{   s   
zrender.<locals>.sort_keyr   )dirsfilesc           	         sj  zt j| drnd}W n3 tyE } z'dfdd|D    }d|	d| W Y d}~dS d}~ww t|d	 }t|D ]b\}}||k}|jr^d
nd  d	7  < dfdd|D }||rw n7 }|jrd| |j du st|k rt| |j||g  qPd| 
|j qPdS )zRecursive directory function.)exclude_dirsr3   )key c                 3       | ]	}|r nV  qd S Nr   .0lastindentline_indentr   r   	<genexpr>       z3render.<locals>.format_directory.<locals>.<genexpr>z{} {}z
error ({})Nr   r2   r3   c                 3   r7   r8   r   r9   r<   r   r   r?      r@   )	sorted	filterdir	Exceptionr   formatlen	enumerater+   r,   )	pathlevels	directoryerrorr   _lastir/   is_last_entry)char_corner	char_linechar_newnodecounts
dirs_firstexcludefilterformat_directoryr$   r&   r*   r!   fsr=   r>   
max_levelsr1   r0   r   r   r   rU      sR   

z render.<locals>.format_directoryr2   r3   )
sysstdoutgetattrhasattrr   platformr(   r-   r   r   )rV   rG   r   r   rW   r    rR   rS   rT   is_tty
is_windowschar_vertliner   )rN   rO   rP   rQ   rR   rS   r   rT   rU   r$   r&   r*   r!   rV   r=   r>   rW   r1   r0   r    r   r   render   s:   
$	
0)r`   )r   NNr   NTNN)__doc__
__future__r   r   rX   typingfs.pathr   r   r   TYPE_CHECKINGr   r   r	   r
   r   baser   r/   r   r`   r   r   r   r   <module>   s$   