No description
Find a file
2022-08-15 14:34:53 +02:00
.github GA: run build before sdist to ensure _impl.c is available (fixes #4) 2022-08-15 14:25:25 +02:00
cwcwidth Bump version to 0.1.6 2021-12-25 12:39:29 +01:00
docs Add sphinx-based documentation 2021-02-06 23:02:45 +01:00
tests Test \r 2021-05-13 11:21:06 +02:00
.gitignore Ignore more artefacts 2021-01-23 15:02:21 +01:00
CHANGELOG.md Bump version to 0.1.6 2021-12-25 12:39: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 Drop support for Python 3.6 2021-12-25 11:52:26 +01:00
README.md Remove tidelift 2022-03-07 21:05:50 +01:00
setup.cfg Fix deprecation warning 2022-08-15 14:34:53 +02: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.