Skip to content

New feature: provide a means of obtaining table geometry. #369

@minitchoup

Description

@minitchoup
  • g.w: table width with frame elements,
  • g.h: table height with frame elements,
  • g.c_w: width of each column without frame elements,
  • g.r_h: height of each row without frame elements,
  • g.f_w: width of horizontal frame elements,
  • g.f_h: the height of vertical frame elements.

Example:

>>> print(tabulate(table, headers, tablefmt="simple"))
item      qty
------  ----- )1
spam       42
eggs      451
bacon       0
      ╰╯
       2

>>> g = geometry(table, headers, tablefmt="simple"))
>>> g.w
13
>>> g.h
5
>>> g.c_w
(6, 5)
>>> g.r_h
(1, 1, 1, 1)
>>> g.f_w
(0, 2, 0)
>>> g.f_h
(0, 1, 0, 0, 0)

>>> print(tabulate(table, headers, tablefmt="grid"))
+--------+-------+ )1
| item   |   qty |
+========+=======+ )1
| spam   |    42 |
+--------+-------+ )1
| eggs   |   451 |
+--------+-------+ )1
| bacon  |     0 |
+--------+-------+ )1
╰╯      ╰─╯     ╰╯
2        3       2

>>> g = geometry(table, headers, tablefmt="grid"))
>>> g.w
18
>>> g.h
9
>>> g.c_w
(6, 5)
>>> g.r_h
(1, 1, 1, 1)
>>> g.f_w
(2, 3, 2)
>>> g.f_h
(1, 1, 1, 1, 1)

Thanks to the information provided, I'm able to configure the table generation correctly, for example, so that it doesn't exceed a maximum width...

Thank you for your work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions