o
    =Ѯa
&                     @   s<   d Z ddlmZmZmZ ddlmZmZ G dd deZ	dS )z?Base table class. Define just the bare minimum to build tables.    )build_border	build_rowflatten)align_and_pad_cellmax_dimensionsc                   @   s   e Zd ZdZdZdZdZdZdZdZ	dZ
dZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dddZ!dd	 Z"d
d Z#dd Z$e%dd Z&dS )	BaseTableaC  Base table class.

    :ivar iter table_data: List (empty or list of lists of strings) representing the table.
    :ivar str title: Optional title to show within the top border of the table.
    :ivar bool inner_column_border: Separates columns.
    :ivar bool inner_footing_row_border: Show a border before the last row.
    :ivar bool inner_heading_row_border: Show a border after the first row.
    :ivar bool inner_row_border: Show a border in between every row.
    :ivar bool outer_border: Show the top, left, right, and bottom border.
    :ivar dict justify_columns: Horizontal justification. Keys are column indexes (int). Values are right/left/center.
    :ivar int padding_left: Number of spaces to pad on the left side of every cell.
    :ivar int padding_right: Number of spaces to pad on the right side of every cell.
    -+|Nc                 C   sB   || _ || _d| _d| _d| _d| _d| _t | _d| _	d| _
dS )zConstructor.

        :param iter table_data: List (empty or list of lists of strings) representing the table.
        :param title: Optional title to show within the top border of the table.
        TF   N)
table_datatitleinner_column_borderinner_footing_row_borderinner_heading_row_borderinner_row_borderouter_borderdictjustify_columnspadding_leftpadding_right)selfr   r    r   =usr/lib/python3.10/site-packages/terminaltables/base_table.py__init__4   s   
zBaseTable.__init__c                 C   s6  |dkr| j }| j}| jr| jnd}| j}| j}ny|dkr1| j}| j}| jr)| jnd}| j	}d}na|dkrS| j
}| jr>| jnd}| jrF| jnd}| jrN| jnd}d}n?|dkru| j}| jr`| jnd}| jrh| jnd}| jrp| jnd}d}n| j}| jr~| jnd}| jr| jnd}| jr| jnd}d}t||||||S )a  Build any kind of horizontal border for the table.

        :param str style: Type of border to return.
        :param iter outer_widths: List of widths (with padding) for each column.

        :return: Prepared border as a tuple of strings.
        :rtype: tuple
        top bottomNheadingfooting)CHAR_OUTER_TOP_HORIZONTALCHAR_OUTER_TOP_LEFTr   CHAR_OUTER_TOP_INTERSECTCHAR_OUTER_TOP_RIGHTr   CHAR_OUTER_BOTTOM_HORIZONTALCHAR_OUTER_BOTTOM_LEFTCHAR_OUTER_BOTTOM_INTERSECTCHAR_OUTER_BOTTOM_RIGHTCHAR_H_INNER_HORIZONTALr   CHAR_H_OUTER_LEFT_INTERSECTCHAR_H_INNER_INTERSECTCHAR_H_OUTER_RIGHT_INTERSECTCHAR_F_INNER_HORIZONTALCHAR_F_OUTER_LEFT_INTERSECTCHAR_F_INNER_INTERSECTCHAR_F_OUTER_RIGHT_INTERSECTCHAR_INNER_HORIZONTALCHAR_OUTER_LEFT_INTERSECTCHAR_INNER_INTERSECTCHAR_OUTER_RIGHT_INTERSECTr   )r   styleouter_widthsZ
horizontalleftZ	intersectrightr   r   r   r   horizontal_borderG   s<   	zBaseTable.horizontal_borderc                 c   sD   t  }t|t|kr|dgt|t|   }t|D ]#\}}| j|f}|| |f}	| j| jddf}
|t|||	|
 q|dkr^| j	rK| j
nd}| jrS| jnd}| j	r[| jnd}n5|dkr{| j	rh| jnd}| jrp| jnd}| j	rx| jnd}n| j	r| jnd}| jr| jnd}| j	r| jnd}t||||D ]}|V  qdS )a  Combine cells in row and group them into lines with vertical borders.

        Caller is expected to pass yielded lines to ''.join() to combine them into a printable line. Caller must append
        newline character to the end of joined line.

        In:
        ['Row One Column One', 'Two', 'Three']
        Out:
        [
            ('|', ' Row One Column One ', '|', ' Two ', '|', ' Three ', '|'),
        ]

        In:
        ['Row One\nColumn One', 'Two', 'Three'],
        Out:
        [
            ('|', ' Row One    ', '|', ' Two ', '|', ' Three ', '|'),
            ('|', ' Column One ', '|', '     ', '|', '       ', '|'),
        ]

        :param iter row: One row in the table. List of cells.
        :param str style: Type of border characters to use.
        :param iter inner_widths: List of widths (no padding) for each column.
        :param int height: Inner height (no padding) (number of lines) to expand row to.

        :return: Yields lines split into components in a list. Caller must ''.join() line.
        r   r   r   r   N)listlen	enumerater   getr   r   appendr   r   CHAR_H_OUTER_LEFT_VERTICALr   CHAR_H_INNER_VERTICALCHAR_H_OUTER_RIGHT_VERTICALCHAR_F_OUTER_LEFT_VERTICALCHAR_F_INNER_VERTICALCHAR_F_OUTER_RIGHT_VERTICALCHAR_OUTER_LEFT_VERTICALCHAR_INNER_VERTICALCHAR_OUTER_RIGHT_VERTICALr   )r   rowr4   inner_widthsheightZcells_in_rowicellZalignZinner_dimensionspaddingr6   centerr7   liner   r   r   gen_row_linesp   s.   zBaseTable.gen_row_linesc                 c   s
   | j r| d|V  t| j}|d |d }}t| jD ]X\}}| jr,|dkr,d}	n| jr6||kr6d}	nd}	| ||	||| D ]}
|
V  qB||krN n)| jr]|dkr]| d|V  q| jrl||krl| d|V  q| jrv| d|V  q| j r| d|V  d	S d	S )
aR  Combine everything and yield every line of the entire table with borders.

        :param iter inner_widths: List of widths (no padding) for each column.
        :param iter inner_heights: List of heights (no padding) for each row.
        :param iter outer_widths: List of widths (with padding) for each column.
        :return:
        r   r      r   r   r   rG   r   N)	r   r8   r:   r   r;   r   r   rO   r   )r   rH   Zinner_heightsr5   Z	row_countZlast_row_indexZbefore_last_row_indexrJ   rG   r4   rN   r   r   r   	gen_table   s2   	
zBaseTable.gen_tablec                 C   s(   t | j| j| jdd }t| j| S )zNReturn a large string of the entire table ready to be printed to the terminal.N   )r   r   r   r   r   rQ   )r   Z
dimensionsr   r   r   table   s   zBaseTable.table)N)'__name__
__module____qualname____doc__r,   r.   rB   r-   rA   r/   rC   r(   r*   r?   r)   r>   r+   r@   r0   r2   rE   r$   r&   r%   r'   r1   rD   r3   rF   r    r"   r!   r#   r   r8   rO   rQ   propertyrS   r   r   r   r   r      sJ    
);*r   N)
rW   Zterminaltables.buildr   r   r   Z"terminaltables.width_and_alignmentr   r   objectr   r   r   r   r   <module>   s    