from collatex.display_module import Table, TableCell, fill, TableRow


def visualize_table_vertically_with_colors(table, collation):
    """ patch of `collatex.display_module.visualize_table_vertically_with_colors` function
    """
    # print the table vertically
    # switch columns and rows
    rows = []
    for column in table.columns:
        cells = []
        for witness in collation.witnesses:
            cell = column.tokens_per_witness.get(witness.sigil)
            cells.append(
                TableCell(
                    text=fill("".join(item.token_data["t"] for item in cell) if cell else "-", 20),
                    bgcolor="white" if column.variant else "00FFFF"
                )
            )
        rows.append(TableRow(cells=cells))
    sigli = []
    for witness in collation.witnesses:
        sigli.append(witness.sigil)
    x = Table(header_row=sigli, rows=rows)
    return str(x)
