Robpol86 / terminaltables

Project no longer maintained.
https://github.com/matthewdeanmartin/terminaltables
MIT License
689 stars 70 forks source link

Fix the bug that the column width miscalculated. #8

Closed zqqf16 closed 9 years ago

zqqf16 commented 9 years ago

The width of East Asian character takes on either of two values: narrow or wide. For wide characters, they takes double widths than narrow. (Reference: http://unicode.org/reports/tr11/)

So, we can't calculate the column width by Python function len, which just returns the number of characters.

For example, the width of 中文 should be 4, but len('中文') returns 2.

Robpol86 commented 9 years ago
  1. Please add tests with these unicode characters.
  2. Please fix broken tests.
  3. I think a better approach would be to use _get_width() for everything (completely replacing len throughout terminaltables.py) and have that return the "terminal length" of every string and unicode character.
Robpol86 commented 9 years ago

Merged https://github.com/Robpol86/terminaltables/pull/9