Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for combining characters #19

Closed
wants to merge 1 commit into from
Closed

add support for combining characters #19

wants to merge 1 commit into from

Conversation

tos-kamiya
Copy link

Add support for combining characters of Unicode.

This patch uses wcwidth package to compute width of characters,
in order to render strings including combining characters such as "ā".

E.g., the code:

from texttable import Texttable
table = Texttable()
table.set_cols_align(["l", "r", "r"])
table.add_rows([
    ["str", "code-point\nlength", "display\nwidth"],
    ["a\u0304", 2, 1],
    ["a", 1, 1],
])
print(table.draw())

will output:

+-----+------------+---------+
| str | code-point | display |
|     |   length   |  width  |
+=====+============+=========+
| ā   |          2 |       1 |
+-----+------------+---------+
| a   |          1 |       1 |
+-----+------------+---------+

Regards,

@foutaise
Copy link
Owner

Hi tos-kamiya,

Thanks for your PR. I've made a simple commit (0708de4) in order to fix the combining char issue, without the need to depend on another external package. Will consider using wcwidth if other corner cases arise. A new release will follow.

Best regards,

@tos-kamiya
Copy link
Author

Hi @foutaise ,

I'm glad to hear that Texttable will renders such characters in the next release.

Thank you for this pretty useful product and making it care about multi-byte characters!

Regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants