No description
Find a file
2021-02-03 00:24:50 +01:00
.github Also build wheels with cibuildwheel 2021-01-28 22:08:11 +01:00
cwcwidth Let setuptools handle Cython files 2021-02-03 00:24:50 +01:00
tests Fix deprecation warnings 2021-01-23 08:51:46 +01:00
.gitignore Ignore more artefacts 2021-01-23 15:02:21 +01:00
CHANGELOG.md Bump version to 0.1.2 2021-01-28 22:18:22 +01:00
LICENSE Use Markus Kuhn's wc(s)width implementation of not provided by libc 2021-01-23 10:06:22 +01:00
MANIFEST.in Fix inclusion of data files 2021-01-29 20:42:05 +01:00
pyproject.toml Also list wheel as build dependency 2021-01-30 22:20:41 +01:00
README.md If Cython is not available, do not regenerate _impl.c 2021-01-24 15:32:34 +01:00
setup.py Let setuptools handle Cython files 2021-02-03 00:24:50 +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

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 Expat license.