No description
Find a file
2021-01-23 09:06:52 +01:00
.github Run black and codespell as Github actions 2021-01-23 09:06:52 +01:00
cwcwidth Fix comparison between signed and unsigned integer warning 2021-01-23 08:56:14 +01:00
tests Fix deprecation warnings 2021-01-23 08:51:46 +01:00
.gitignore Ignore build artefacts 2021-01-23 08:53:09 +01:00
CHANGELOG.md Initial commit 2021-01-23 02:18:15 +01:00
LICENSE Initial commit 2021-01-23 02:18:15 +01:00
MANIFEST.in Initial commit 2021-01-23 02:18:15 +01:00
pyproject.toml Run black and codespell as Github actions 2021-01-23 09:06:52 +01:00
README.md Initial commit 2021-01-23 02:18:15 +01:00
setup.py Run black and codespell as Github actions 2021-01-23 09:06:52 +01:00

Python bindings for wc(s)width

cwcwidth provides Python bindings based on Cython for libc's wcwidth and wcswidth functions which compute the printable length of a unicode character/string on a terminal.

The module provides the same functions as wcwidth and its behavior is compatible.

Dependencies

  • Cython >= 0.28 (only for building)

Quick installation guilde

cwcwidth can be installed via pip:

pip install cwcwidth

or by running:

python3 setup.py install

Usage

import cwcwidth
cwcwidth.wcwidth("a") # 1
cwcwidth.wcswidth("コ") # 2
cwcwidth.wcswidth("コンニチハ, セカイ!") # 19

Comparison with wcwidth

>>> import wcwidth, cwcwidth, timeit
>>> timeit.timeit(lambda: wcwidth.wcswidth("コンニチハ, セカイ!"))
19.14463168097427
>>> timeit.timeit(lambda: cwcwidth.wcswidth("コンニチハ, セカイ!"))
0.16294104099506512

License

The code is licensed under the MIT license.