o
    rri                     @   s   d dl Z ddlmZmZmZmZmZ G dd dZdd Zdd	d
Z	dd Z
dd Zdd Zg dddfddZedkrFd dlZe  dS dS )    N   )colorizeget_short_namesjoin
text_width
wrap_alignc                   @   sZ   e Zd Zg dZddddddddddZedd Zdd	 Zd
d Zdd Z	dd Z
dS )_Node)alignformatwrapmissingshortenN)groupsdisplayr	   r
   r   r   r   c          
      C   s@   || _ || _|d u r|n|| _tjD ]}	t| |	t |	  qd S N)keyr   r   r   _propertiessetattrlocals)
selfr   r   r   r	   r
   r   r   r   prop r   C/home/ubuntu/.local/lib/python3.10/site-packages/treetable/table.py__init__	   s   

z_Node.__init__c                 C   s*   | j d u rdS dtdd | j D dd S )Nr   r   c                 s   s    | ]}|j V  qd S r   )depth.0childr   r   r   	<genexpr>   s    z_Node.depth.<locals>.<genexpr>default)r   maxr   r   r   r   r      s   
z_Node.depthc                 C   s
   t | jS r   )iterr   r"   r   r   r   __iter__    s   
z_Node.__iter__c                 C   s@   i }t jD ]}t| |}|d u rt||||< q| jdi |S )Nr   )r   r   getattrupdate)r   parentupdatesr   my_valuer   r   r   inherit#   s   

z_Node.inheritc                 K   sD   | j | j| jd}tjD ]	}t| |||< q|| tdi |S )N)r   r   r   r   )r   r   r   r   r   r%   r&   )r   r(   kwargsr   r   r   r   r&   +   s   

z_Node.updatec           	      C   s   g }| j d ur|| j  | j| j kr|d| j  tjD ]}t| |}|d ur4|| d|  q| jd u r=d}n
| jd u rEd}nd}| }|rW|dd| d7 }| jd ur{g }| jD ]}|t	t
|d	 qad
|}|d| 7 }|S )Nzkey==tableleafgroup(z, )  
z:
)r   appendr   r   r   r%   r   r   textwrapindentrepr)	r   
repr_partsr   valuenamemy_reprchild_reprsr   
child_reprr   r   r   __repr__7   s2   







z_Node.__repr__)__name__
__module____qualname__r   r   propertyr   r$   r*   r&   r>   r   r   r   r   r      s     
r   c                 K      t d| |d|S N)r   r   r   r   )r   r   r+   r   r   r   r/   T      r/    c                 K   rC   )N)r   r
   r   rE   )r   r
   r+   r   r   r   r.   X   rF   r.   c                 K   s   t dd | d|S rD   rE   )r   r+   r   r   r   r-   \   rF   r-   c                 C   s@   g }| D ]}|d u r|j pd}nt||jpd}|| q|S )NrG   )r   r
   r4   )linesr.   	formattedlinecontentr   r   r   _treetable_terminal`   s   rL   c                    s  |j }|d u rt| |S |j}|d t|kr$td| dt| ddd |D }|jr3t|}n|}g }t||D ]\ } |  j d urRt j dkrRq< j}	||	 }
 j d u  fdd| D }rpt| }nt	| |d	}t
d
d |D ddt
t| j d u r jd urt jr jd  }n
 jd  }dg|
d  |g | } fdd|D }|| q<t|||d  dS )Nr   z2Not enough separators for depth of tree (depth is z	 but got z separators)c                 S   s   g | ]}|j qS r   )r   r   r   r   r   
<listcomp>v   s    z_treetable.<locals>.<listcomp>r   c                    s"   g | ]}|  jrd ni qS r   )getr   r   rJ   )r   terminalr   r   rM      s    )r/   
separatorsc                 s   s    | ]}t |V  qd S r   )r   rO   r   r   r   r      s    z_treetable.<locals>.<genexpr>r   rG   c                    s    g | ]}t | jpd dqS )<)width	alignment)r   r	   rO   )r   rS   r   r   rM      s    )	separator)r   rL   r   len
ValueErrorr   r   zipr*   
_treetabler!   r   minr   centerr4   r   )rH   r/   rQ   r   r   displaysshort_namescolumns
short_namechild_depthdelta_depthchild_lineschild_formatteddisplay_namer   )r   rP   rS   r   rY   k   s^   



rY   )r2   z | z  ||  Fc                    sx   t | ||d}  dur7 fddt| D } |j}| d| }dd |D }|| d|< |r7| |ddd 7 } d| S )a"  
    Pretty-print `lines` using the `table` structure.

    `separators` give the list of sub-tables separators. It needs to be
    as long as the maximum depth of `groups`. Deepest separators comes first.
    If longer than the maximum depth of `groups`, the first ones will be used.

    )rH   r/   rQ   Nc                    s&   g | ]\}}t | |t   qS r   )r   rV   )r   indexrJ   colorsr   r   rM      s    ztreetable.<locals>.<listcomp>c                 S   s   g | ]}t |d qS )1)r   rO   r   r   r   rM      s    r3   )rY   	enumerater   r   )rH   r-   rQ   rg   header_downr   headerr   rf   r   	treetable   s   	

rm   __main__)rG   )r5   textr   r   r   r   r   r   r/   r.   r-   rL   rY   rm   r?   doctesttestmodr   r   r   r   <module>   s    N
5