prettytable
prettytable copied to clipboard
Support joined cells
Would supporting joining table cells be something you might consider?
I want to make tables like the following:
+-------------+-----------+--------------+---------------+------------------------+------------+
| byte | 0 | 1 | 2 | 3 | 4 .. End |
+-------------+-----------+--------------+---------------+----------+-------------+------------+
| bit | | 15 .. 8 | 7 .. 0 | |
+=============+===========+==============+===============+==========+=============+============+
| description | Report ID | Device Index | Feature Index | Function | Software ID | Parameters |
+-------------+-----------+--------------+---------------+----------+-------------+------------+
My use case is constructing packet structures, where a field might expand over several bytes or bits.
It could be useful.
What sort of API do you suggest? Would it be possible to support it for all the output styles?
Not sure yet, designing an API for this is a bit tricky. I will think about it and try to come back.
For ascii output in particular, you could create a new option of empty_vertical_char
, similar to vertical_char
, except this would be a single character to print between two empty (i.e., None
value) fields. The user could then just set it to be a " "
space to make it appear empty.
Then when they add rows, they'd do this to get your example row:
x.add_row(["bit", None, None, None, "15 .. 8", "7 .. 0", None])
Oh wait, no you really do want to "join cells", even if they contain data not just for empty ones. Sorry I didn't notice your top/header row doing that for "3
".
Yeah, that's hard.
One way might be to create a new class
in prettytable, like for example a JoinedColumn
.
The user could add rows like this:
from prettytable import JoinedColumn
x.add_row(["byte", 0, 1, 2, JoinedColumn(width=2, value=3), "4 .. End"])
Internally prettytable would check for that class type, and do what it needs to based on that.