petercorke/ansitable

fgcolor and bgcolor does not seem to work

Opened this issue · 2 comments

Using the example from the README:

from ansitable import ANSITable, Column, Cell

table = ANSITable("col1", "column 2 has a big header", "column 3")
table.row("aaaaaaaaa", 2.2, 3)
table.row("bbbbbbbbbbbbb", Cell(-5.5, bgcolor="blue"), 6, bgcolor="yellow")
table.row("ccccccc", 8.8, 9)
table.print()

Results in the following using the current master of ansitable:

[fedora]$ python3 test.py
Traceback (most recent call last):
  File "/home/bluecmd/work/linkinsane/test.py", line 7, in <module>
    table.print()
  File "/home/bluecmd/work/linkinsane/ansitable/table.py", line 828, in print
    print(str(self), file=file)
          ^^^^^^^^^
  File "/home/bluecmd/work/linkinsane/ansitable/table.py", line 870, in __str__
    text += self._row(i)  # add a row
            ^^^^^^^^^^^^
  File "/home/bluecmd/work/linkinsane/ansitable/table.py", line 788, in _row
    text += c._formatcolumn(
            ^^^^^^^^^^^^^^^^
  File "/home/bluecmd/work/linkinsane/ansitable/table.py", line 266, in _formatcolumn
    text = self.table.BG(bgcolor) + text + self.table.BG(0)
           ^^^^^^^^^^^^^
AttributeError: 'ANSITable' object has no attribute 'BG'. Did you mean: '_BG'?

It is the same issue with using fgcolor, with the error being that no attribute named FG exists.

OK, I think this might be an issue with the package colored which might not be up to date. I am using v2.2.4 and there were breaking changes between v1 and v2, that got fixed in later minor releases of v2. For that reason I didn't put a version dependency in the build file, perhaps I should have.

Your example gives me:

image

Fixed a bug that likely impacts on Cell(). Give it a go now.