src/lsi/utils/table.py
def render_columns(columns, write_borders=True, column_colors=None):
    """
    Renders a list of columns.

    :param columns: A list of columns, where each column is a list of strings.
    :type columns: [[``str``]]
    :param write_borders: Whether to write the top and bottom borders.
    :type write_borders: ``bool``
    :param column_colors: A list of coloring functions, one for each column.
                          Optional.
    :type column_colors: [``str`` -> ``str``] or ``NoneType``

    :return: The rendered columns.
    :rtype: ``str``
    """
    if column_colors is not None and len(column_colors) != len(columns):
        raise ValueError('Wrong number of column colors')
    widths = [max(len(cell) for cell in column) for column in columns]
    max_column_length = max(len(column) for column in columns)
    result = '\n'.join(render_row(i, columns, widths, column_colors)
                       for i in range(max_column_length))
    if write_borders:
        border = '+%s+' % '|'.join('-' * (w + 2) for w in widths)
        return '%s\n%s\n%s' % (border, result, border)
    else:
        return result
def render_columns(columns, write_borders=True, column_colors=None):
    if column_colors is not None and len(column_colors) != len(columns):
        raise ValueError('Wrong number of column colors')
    widths = [max(len(cell) for cell in column) for column in columns]
    max_column_length = max(len(column) for column in columns)
    result = '\n'.join(render_row(i, columns, widths, column_colors)
                       for i in range(max_column_length))
    if write_borders:
        border = '+%s+' % '|'.join('-' * (w + 2) for w in widths)
        return '%s\n%s\n%s' % (border, result, border)
    else:
        return result
def render_columns ( columns , write_borders = True , column_colors = None ) : if column_colors is not None and len ( column_colors ) != len ( columns ) : raise ValueError ( 'Wrong number of column colors' ) widths = [ max ( len ( cell ) for cell in column ) for column in columns ] max_column_length = max ( len ( column ) for column in columns ) result = '\n' . join ( render_row ( i , columns , widths , column_colors ) for i in range ( max_column_length ) ) if write_borders : border = '+%s+' % '|' . join ( '-' * ( w + 2 ) for w in widths ) return '%s\n%s\n%s' % ( border , result , border ) else : return result
Renders a list of columns.

    :param columns: A list of columns, where each column is a list of strings.
    :type columns: [[``str``]]
    :param write_borders: Whether to write the top and bottom borders.
    :type write_borders: ``bool``
    :param column_colors: A list of coloring functions, one for each column.
                          Optional.
    :type column_colors: [``str`` -> ``str``] or ``NoneType``

    :return: The rendered columns.
    :rtype: ``str``
Renders a list of columns .