o
    =Ѯa                     @   s6   d Z ddlmZ dd ZdddZdd	 Zd
d ZdS )zCombine cells into rows.    )visible_widthc                 c   s    |r|V  |rVzt | t|  d dD ]\}}|V  |r |V  qW n; tyU   zt| }W n	 ty8   Y nw 	 |V  zt| }W n	 tyL   Y nw |V  |}q:Y n	w | D ]}|V  qX|re|V  dS dS )a  Zip borders between items in `line`.

    e.g. ('l', '1', 'c', '2', 'c', '3', 'r')

    :param iter line: List to iterate.
    :param left: Left border.
    :param intersect: Column separator.
    :param right: Right border.

    :return: Yields combined objects.
       )startTN)	enumeratelen	TypeErrornextStopIteration)lineleft	intersectrightjiitempeek r   8usr/lib/python3.10/site-packages/terminaltables/build.pycombine   sD   
r   Nc           
         s  d}|dur2| r2zt |}W n ty   t|}t |}Y nw |t| t|t| d   kr2d}|du s:| r: sHt fdd| D |||S || d krct|g fdd| dd D  |||S || d k r| | d |   g fdd| dd D  }t||||S |g}t| dt|dD ]?}	|dk r||	d	u r|n |	  q|	d	u r|dkrd}q|	d	u r|d8 }q|	|kr|d   |	|  7  < d}q||	8 }qt||d|S )
a  Build the top/bottom/middle row. Optionally embed the table title within the border.

    Title is hidden if it doesn't fit between the left/right characters/edges.

    Example return value:
    ('<', '-----', '+', '------', '+', '-------', '>')
    ('<', 'My Table', '----', '+', '------->')

    :param iter outer_widths: List of widths (with padding) for each column.
    :param str horizontal: Character to stretch across each column.
    :param str left: Left border.
    :param str intersect: Column separator.
    :param str right: Right border.
    :param title: Overlay the title on the border between the left and right characters.

    :return: Returns a generator of strings representing a border.
    :rtype: iter
    r   Nr   c                 3   s    | ]} | V  qd S Nr   .0c
horizontalr   r   	<genexpr>U       zbuild_border.<locals>.<genexpr>c                       g | ]} | qS r   r   r   r   r   r   
<listcomp>Y       z build_border.<locals>.<listcomp>c                    r   r   r   r   r   r   r   r   [   r   T)r   r   strsumr   r   boolappend)
Zouter_widthsr   r   r   r   titlelengthcolumnsZcolumns_and_intersectswidthr   r   r   build_border4   s<    *0

r(   c                 #   sZ    | r| d st d|||V  dS tt| d D ] t  fdd| D |||V  qdS )a<  Combine single or multi-lined cells into a single row of list of lists including borders.

    Row must already be padded and extended so each cell has the same number of lines.

    Example return value:
    [
        ['>', 'Left ', '|', 'Center', '|', 'Right', '<'],
        ['>', 'Cell1', '|', 'Cell2 ', '|', 'Cell3', '<'],
    ]

    :param iter row: List of cells for one row.
    :param str left: Left border.
    :param str center: Column separator.
    :param str right: Right border.

    :return: Yields other generators that yield strings.
    :rtype: iter
    r   r   Nc                 3   s    | ]}|  V  qd S r   r   r   Z	row_indexr   r   r      r   zbuild_row.<locals>.<genexpr>)r   ranger   )rowr   centerr   r   r)   r   	build_rowu   s    r-   c                 C   s   d dd | D S )zFlatten table data into a single string with newlines.

    :param iter table: Padded and bordered table data.

    :return: Joined rows/cells.
    :rtype: str
    
c                 s   s    | ]}d  |V  qdS ) Njoin)r   rr   r   r   r      s    zflatten.<locals>.<genexpr>r0   )tabler   r   r   flatten   s   r4   r   )__doc__Z"terminaltables.width_and_alignmentr   r   r(   r-   r4   r   r   r   r   <module>   s    
.A