python-tabulate icon indicating copy to clipboard operation
python-tabulate copied to clipboard

Table with hyperlink text with space and maxcolwidths not working

Open bendanye opened this issue 2 years ago • 0 comments

Hi there,

I was trying to create a table with clickable text inside the table. Not sure if i did anything wrong.

My expected result:

+----------------+--------+---------------+
| This is a link | 696000 |    1.9891e+09 |
+----------------+--------+---------------+
| This is a link |   6371 | 5973.6        |
+----------------+--------+---------------+
| This is a link |   1737 |   73.5        |
+----------------+--------+---------------+
| This is a link |   3390 |  641.85       |
+----------------+--------+---------------+

Actual result:

+----------------------+--------+---------------+
| This is        |        |               |
| alink         |        |               |
+----------------------+--------+---------------+
| This is        |        |               |
| alink         |        |               |
+----------------------+--------+---------------+
| This is        |        |               |
| alink         |        |               |
+----------------------+--------+---------------+
| This is        |        |               |
| alink         |        |               |
+----------------------+--------+---------------+

Sample Codes

from tabulate import tabulate


def clickable(text: str, target: str):
    return "\x1b]8;;https://example.com\x1b\\This is a link\x1b]8;;\x1b\\"


table = [
    [clickable("test abc", "http://example.org"), 696000, 1989100000],
    [clickable("test bbb", "http://example.org"), 6371, 5973.6],
    [clickable("test ccc", "http://example.org"), 1737, 73.5],
    [clickable("test dddd", "http://example.org"), 3390, 641.85],
]

print(tabulate(table, tablefmt="grid", maxcolwidths=[20, 20, 20])),

bendanye avatar Feb 02 '23 12:02 bendanye