petercorke/ansitable

Long header should apply colbgcolor to same width as header

erhhung opened this issue · 1 comments

This issue is related to, and may be irrelevant once resolved by #8 (headbgcolor and colbgcolor should not be affected by colsep).

The natural column width is determined by the widest column value, whether that's the header or one of the rows. That same column width should be applied to both headbgcolor and colbgcolor, but it is currently not being applied to colbgcolor.

In the example below, the "Date" header is padded—as expected—by the longer "2023-07-28" values, but the wider "Column 2" header is not reflected in the padding of shorter version numbers like "1.0.0". The same is true with column 1 row values.

image

from ansitable import ANSITable, Column # ansitable 0.9.7

table = ANSITable(
  Column("Column 1", headalign="<", headcolor="white", headstyle="bold", headbgcolor="blue",
                      colalign="<",  colcolor="white",  colstyle="bold",  colbgcolor="blue"),
  Column("Column 2", headalign="^", headcolor="white", headstyle="bold", headbgcolor="blue",
                      colalign="<",  colcolor="light_magenta",            colbgcolor="blue"),
  Column("Date",     headalign="^", headcolor="white", headstyle="bold", headbgcolor="blue",
                      colalign="^",  colcolor="chartreuse_3b"),
  border="thick", bordercolor="cornflower_blue", colsep=4,
)
table.row("hello-world", "1.0.0", "2023-07-28")
table.row("foo-bar",     "0.1.0", "2023-07-28")
table.print()

I'm looking at this as part of general maintenance caused by changes to the colored package. What behavior do you want to see? Should the colsep space have bgcolor? Should only the unpadded text have bgcolor?