thombashi / pytablewriter

pytablewriter is a Python library to write a table in various formats: AsciiDoc / CSV / Elasticsearch / HTML / JavaScript / JSON / LaTeX / LDJSON / LTSV / Markdown / MediaWiki / NumPy / Excel / Pandas / Python / reStructuredText / SQLite / TOML / TSV.
https://pytablewriter.rtfd.io/
MIT License
611 stars 43 forks source link

Emoji causing misalignment on Linux #7

Closed hugovk closed 4 years ago

hugovk commented 6 years ago

pytablewriter 0.36.0

Here's a table using emoji:

#!/usr/bin/env python
#  encoding: utf-8
import pytablewriter

writer = pytablewriter.MarkdownTableWriter()
# writer = pytablewriter.SpaceAlignedTableWriter()

writer.header_list = ["int", "float", "str", "bool", "mix", "time"]
writer.value_matrix = [
    ["✅", 0.1, "hoge", True, 0, "2017-01-01 03:04:05+0900"],
    [None, -9.9, "", "FALSE", "nan", "2017-01-01 00:00:00+0900"],
    ["🔺", "-2.23", "foo", False, None, "2017-12-23 45:01:23+0900"],
    [None, -9.9, "", "FALSE", "nan", "2017-01-01 00:00:00+0900"],
]
writer.margin = 1  # add a whitespace for both sides of each cell

writer.write_table()

It renders fine on macOS High Sierra / Python 3.7.0 / iTerm:

image

But on our CI (Linux / Python 3.4.3) the emoji are causing some misalignment:

image

https://travis-ci.org/hugovk/test/jobs/442039626#L363

thombashi commented 6 years ago

@hugovk Thank you for your report.

I'm not sure how to solve the issue right now. Unicode 9 or newer version (which improve Unicode emoji width precision) may work around the issue. However, Unicode 9 supported since Python 3.6.1 or later. Furthermore, you would get unstable width by environments, even if you use Unicode 9. I'm not sure how to get stable Unicode emojis width that independent to environments.

hugovk commented 6 years ago

At least Python 3.4 is quite old, and will reach end-of-life in six months, so I wouldn't worry about that one and good to hear Unicode 9 may improve things.

In our particular use case the table is quite wide and long and the emoji is in a column near the right edge, so the table is not as untidy as the example above, and it's not a big issue.

Feel free to close this if there's no clear fix, and thank you for taking the time to investigate.

hugovk commented 4 years ago

Our CI now has Python 3.6.9 and this is much less of a problem, so I'm happy to close this now:

image