No description
Find a file
2021-02-07 23:38:10 +01:00
.github Enforce UTF-8 locale for tests 2021-02-07 23:01:29 +01:00
cwcwidth Bump version to 0.1.3 2021-02-07 23:01:29 +01:00
docs Add sphinx-based documentation 2021-02-06 23:02:45 +01:00
tests Fix typo 2021-02-07 17:56:08 +01:00
.gitignore Ignore more artefacts 2021-01-23 15:02:21 +01:00
CHANGELOG.md Bump version to 0.1.3 2021-02-07 23:01:29 +01:00
LICENSE Update LICENSE info 2021-02-05 21:42:57 +01:00
MANIFEST.in Include _impl.c again 2021-02-07 23:38:10 +01:00
pyproject.toml Ignore sphinx configuration 2021-02-06 23:20:49 +01:00
README.md Reformat usage 2021-02-06 22:08:37 +01:00
setup.cfg Bump version to 0.1.3 2021-02-07 23:01:29 +01:00
setup.py Enforce UTF-8 locale for tests 2021-02-07 23:01:29 +01:00

Python bindings for wc(s)width

cwcwidth provides Python bindings for wcwidth and wcswidth functions defined in POSIX.1-2001 and POSIX.1-2008 based on Cython. These functions 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.

On systems not conforming to POSIX.1-2001 and POSIX.1-2008, Markus Kuhn's implementation is used to provide the functionality.

Dependencies

  • Cython >= 0.28 (optional, only for building). If Cython is not available, the C files are not regenerated from their source.

Quick installation guide

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
>>> cwcwidth.wcswidth("コンニチハ, セカイ!", 5)
10

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.

Tidelift

Security contact information

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coorindate the fix and disclosure.

Commercial support

cwcwidth and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source packages you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact packages you use. Learn more.