| 1 |
Metadata-Version: 2.1 |
| 2 |
Name: wcwidth |
| 3 |
Version: 0.2.13 |
| 4 |
Summary: Measures the displayed width of unicode strings in a terminal |
| 5 |
Home-page: https://github.com/jquast/wcwidth |
| 6 |
Author: Jeff Quast |
| 7 |
Author-email: [email protected] |
| 8 |
License: MIT |
| 9 |
Keywords: cjk,combining,console,eastasian,emoji,emulator,terminal,unicode,wcswidth,wcwidth,xterm |
| 10 |
Classifier: Intended Audience :: Developers |
| 11 |
Classifier: Natural Language :: English |
| 12 |
Classifier: Development Status :: 5 - Production/Stable |
| 13 |
Classifier: Environment :: Console |
| 14 |
Classifier: License :: OSI Approved :: MIT License |
| 15 |
Classifier: Operating System :: POSIX |
| 16 |
Classifier: Programming Language :: Python :: 2.7 |
| 17 |
Classifier: Programming Language :: Python :: 3.5 |
| 18 |
Classifier: Programming Language :: Python :: 3.6 |
| 19 |
Classifier: Programming Language :: Python :: 3.7 |
| 20 |
Classifier: Programming Language :: Python :: 3.8 |
| 21 |
Classifier: Programming Language :: Python :: 3.9 |
| 22 |
Classifier: Programming Language :: Python :: 3.10 |
| 23 |
Classifier: Programming Language :: Python :: 3.11 |
| 24 |
Classifier: Programming Language :: Python :: 3.12 |
| 25 |
Classifier: Topic :: Software Development :: Libraries |
| 26 |
Classifier: Topic :: Software Development :: Localization |
| 27 |
Classifier: Topic :: Software Development :: Internationalization |
| 28 |
Classifier: Topic :: Terminals |
| 29 |
License-File: LICENSE |
| 30 |
Requires-Dist: backports.functools-lru-cache >=1.2.1 ; python_version < "3.2" |
| 31 |
|
| 32 |
|pypi_downloads| |codecov| |license| |
| 33 |
|
| 34 |
============ |
| 35 |
Introduction |
| 36 |
============ |
| 37 |
|
| 38 |
This library is mainly for CLI programs that carefully produce output for |
| 39 |
Terminals, or make pretend to be an emulator. |
| 40 |
|
| 41 |
**Problem Statement**: The printable length of *most* strings are equal to the |
| 42 |
number of cells they occupy on the screen ``1 character : 1 cell``. However, |
| 43 |
there are categories of characters that *occupy 2 cells* (full-wide), and |
| 44 |
others that *occupy 0* cells (zero-width). |
| 45 |
|
| 46 |
**Solution**: POSIX.1-2001 and POSIX.1-2008 conforming systems provide |
| 47 |
`wcwidth(3)`_ and `wcswidth(3)`_ C functions of which this python module's |
| 48 |
functions precisely copy. *These functions return the number of cells a |
| 49 |
unicode string is expected to occupy.* |
| 50 |
|
| 51 |
Installation |
| 52 |
------------ |
| 53 |
|
| 54 |
The stable version of this package is maintained on pypi, install using pip:: |
| 55 |
|
| 56 |
pip install wcwidth |
| 57 |
|
| 58 |
Example |
| 59 |
------- |
| 60 |
|
| 61 |
**Problem**: given the following phrase (Japanese), |
| 62 |
|
| 63 |
>>> text = u'コンニチハ' |
| 64 |
|
| 65 |
Python **incorrectly** uses the *string length* of 5 codepoints rather than the |
| 66 |
*printable length* of 10 cells, so that when using the `rjust` function, the |
| 67 |
output length is wrong:: |
| 68 |
|
| 69 |
>>> print(len('コンニチハ')) |
| 70 |
5 |
| 71 |
|
| 72 |
>>> print('コンニチハ'.rjust(20, '_')) |
| 73 |
_______________コンニチハ |
| 74 |
|
| 75 |
By defining our own "rjust" function that uses wcwidth, we can correct this:: |
| 76 |
|
| 77 |
>>> def wc_rjust(text, length, padding=' '): |
| 78 |
... from wcwidth import wcswidth |
| 79 |
... return padding * max(0, (length - wcswidth(text))) + text |
| 80 |
... |
| 81 |
|
| 82 |
Our **Solution** uses wcswidth to determine the string length correctly:: |
| 83 |
|
| 84 |
>>> from wcwidth import wcswidth |
| 85 |
>>> print(wcswidth('コンニチハ')) |
| 86 |
10 |
| 87 |
|
| 88 |
>>> print(wc_rjust('コンニチハ', 20, '_')) |
| 89 |
__________コンニチハ |
| 90 |
|
| 91 |
|
| 92 |
Choosing a Version |
| 93 |
------------------ |
| 94 |
|
| 95 |
Export an environment variable, ``UNICODE_VERSION``. This should be done by |
| 96 |
*terminal emulators* or those developers experimenting with authoring one of |
| 97 |
their own, from shell:: |
| 98 |
|
| 99 |
$ export UNICODE_VERSION=13.0 |
| 100 |
|
| 101 |
If unspecified, the latest version is used. If your Terminal Emulator does not |
| 102 |
export this variable, you can use the `jquast/ucs-detect`_ utility to |
| 103 |
automatically detect and export it to your shell. |
| 104 |
|
| 105 |
wcwidth, wcswidth |
| 106 |
----------------- |
| 107 |
Use function ``wcwidth()`` to determine the length of a *single unicode |
| 108 |
character*, and ``wcswidth()`` to determine the length of many, a *string |
| 109 |
of unicode characters*. |
| 110 |
|
| 111 |
Briefly, return values of function ``wcwidth()`` are: |
| 112 |
|
| 113 |
``-1`` |
| 114 |
Indeterminate (not printable). |
| 115 |
|
| 116 |
``0`` |
| 117 |
Does not advance the cursor, such as NULL or Combining. |
| 118 |
|
| 119 |
``2`` |
| 120 |
Characters of category East Asian Wide (W) or East Asian |
| 121 |
Full-width (F) which are displayed using two terminal cells. |
| 122 |
|
| 123 |
``1`` |
| 124 |
All others. |
| 125 |
|
| 126 |
Function ``wcswidth()`` simply returns the sum of all values for each character |
| 127 |
along a string, or ``-1`` when it occurs anywhere along a string. |
| 128 |
|
| 129 |
Full API Documentation at https://wcwidth.readthedocs.org |
| 130 |
|
| 131 |
========== |
| 132 |
Developing |
| 133 |
========== |
| 134 |
|
| 135 |
Install wcwidth in editable mode:: |
| 136 |
|
| 137 |
pip install -e . |
| 138 |
|
| 139 |
Execute unit tests using tox_:: |
| 140 |
|
| 141 |
tox -e py27,py35,py36,py37,py38,py39,py310,py311,py312 |
| 142 |
|
| 143 |
Updating Unicode Version |
| 144 |
------------------------ |
| 145 |
|
| 146 |
Regenerate python code tables from latest Unicode Specification data files:: |
| 147 |
|
| 148 |
tox -e update |
| 149 |
|
| 150 |
The script is located at ``bin/update-tables.py``, requires Python 3.9 or |
| 151 |
later. It is recommended but not necessary to run this script with the newest |
| 152 |
Python, because the newest Python has the latest ``unicodedata`` for generating |
| 153 |
comments. |
| 154 |
|
| 155 |
Building Documentation |
| 156 |
---------------------- |
| 157 |
|
| 158 |
This project is using `sphinx`_ 4.5 to build documentation:: |
| 159 |
|
| 160 |
tox -e sphinx |
| 161 |
|
| 162 |
The output will be in ``docs/_build/html/``. |
| 163 |
|
| 164 |
Updating Requirements |
| 165 |
--------------------- |
| 166 |
|
| 167 |
This project is using `pip-tools`_ to manage requirements. |
| 168 |
|
| 169 |
To upgrade requirements for updating unicode version, run:: |
| 170 |
|
| 171 |
tox -e update_requirements_update |
| 172 |
|
| 173 |
To upgrade requirements for testing, run:: |
| 174 |
|
| 175 |
tox -e update_requirements37,update_requirements39 |
| 176 |
|
| 177 |
To upgrade requirements for building documentation, run:: |
| 178 |
|
| 179 |
tox -e update_requirements_docs |
| 180 |
|
| 181 |
Utilities |
| 182 |
--------- |
| 183 |
|
| 184 |
Supplementary tools for browsing and testing terminals for wide unicode |
| 185 |
characters are found in the `bin/`_ of this project's source code. Just ensure |
| 186 |
to first ``pip install -r requirements-develop.txt`` from this projects main |
| 187 |
folder. For example, an interactive browser for testing:: |
| 188 |
|
| 189 |
python ./bin/wcwidth-browser.py |
| 190 |
|
| 191 |
==== |
| 192 |
Uses |
| 193 |
==== |
| 194 |
|
| 195 |
This library is used in: |
| 196 |
|
| 197 |
- `jquast/blessed`_: a thin, practical wrapper around terminal capabilities in |
| 198 |
Python. |
| 199 |
|
| 200 |
- `prompt-toolkit/python-prompt-toolkit`_: a Library for building powerful |
| 201 |
interactive command lines in Python. |
| 202 |
|
| 203 |
- `dbcli/pgcli`_: Postgres CLI with autocompletion and syntax highlighting. |
| 204 |
|
| 205 |
- `thomasballinger/curtsies`_: a Curses-like terminal wrapper with a display |
| 206 |
based on compositing 2d arrays of text. |
| 207 |
|
| 208 |
- `selectel/pyte`_: Simple VTXXX-compatible linux terminal emulator. |
| 209 |
|
| 210 |
- `astanin/python-tabulate`_: Pretty-print tabular data in Python, a library |
| 211 |
and a command-line utility. |
| 212 |
|
| 213 |
- `rspeer/python-ftfy`_: Fixes mojibake and other glitches in Unicode |
| 214 |
text. |
| 215 |
|
| 216 |
- `nbedos/termtosvg`_: Terminal recorder that renders sessions as SVG |
| 217 |
animations. |
| 218 |
|
| 219 |
- `peterbrittain/asciimatics`_: Package to help people create full-screen text |
| 220 |
UIs. |
| 221 |
|
| 222 |
- `python-cmd2/cmd2`_: A tool for building interactive command line apps |
| 223 |
|
| 224 |
- `stratis-storage/stratis-cli`_: CLI for the Stratis project |
| 225 |
|
| 226 |
- `ihabunek/toot`_: A Mastodon CLI/TUI client |
| 227 |
|
| 228 |
- `saulpw/visidata`_: Terminal spreadsheet multitool for discovering and |
| 229 |
arranging data |
| 230 |
|
| 231 |
=============== |
| 232 |
Other Languages |
| 233 |
=============== |
| 234 |
|
| 235 |
- `timoxley/wcwidth`_: JavaScript |
| 236 |
- `janlelis/unicode-display_width`_: Ruby |
| 237 |
- `alecrabbit/php-wcwidth`_: PHP |
| 238 |
- `Text::CharWidth`_: Perl |
| 239 |
- `bluebear94/Terminal-WCWidth`_: Perl 6 |
| 240 |
- `mattn/go-runewidth`_: Go |
| 241 |
- `grepsuzette/wcwidth`_: Haxe |
| 242 |
- `aperezdc/lua-wcwidth`_: Lua |
| 243 |
- `joachimschmidt557/zig-wcwidth`_: Zig |
| 244 |
- `fumiyas/wcwidth-cjk`_: `LD_PRELOAD` override |
| 245 |
- `joshuarubin/wcwidth9`_: Unicode version 9 in C |
| 246 |
|
| 247 |
======= |
| 248 |
History |
| 249 |
======= |
| 250 |
|
| 251 |
0.2.13 *2024-01-06* |
| 252 |
* **Bugfix** zero-width support for Hangul Jamo (Korean) |
| 253 |
|
| 254 |
0.2.12 *2023-11-21* |
| 255 |
* re-release to remove .pyi file misplaced in wheel files `Issue #101`_. |
| 256 |
|
| 257 |
0.2.11 *2023-11-20* |
| 258 |
* Include tests files in the source distribution (`PR #98`_, `PR #100`_). |
| 259 |
|
| 260 |
0.2.10 *2023-11-13* |
| 261 |
* **Bugfix** accounting of some kinds of emoji sequences using U+FE0F |
| 262 |
Variation Selector 16 (`PR #97`_). |
| 263 |
* **Updated** `Specification <Specification_from_pypi_>`_. |
| 264 |
|
| 265 |
0.2.9 *2023-10-30* |
| 266 |
* **Bugfix** zero-width characters used in Emoji ZWJ sequences, Balinese, |
| 267 |
Jamo, Devanagari, Tamil, Kannada and others (`PR #91`_). |
| 268 |
* **Updated** to include `Specification <Specification_from_pypi_>`_ of |
| 269 |
character measurements. |
| 270 |
|
| 271 |
0.2.8 *2023-09-30* |
| 272 |
* Include requirements files in the source distribution (`PR #82`_). |
| 273 |
|
| 274 |
0.2.7 *2023-09-28* |
| 275 |
* **Updated** tables to include Unicode Specification 15.1.0. |
| 276 |
* Include ``bin``, ``docs``, and ``tox.ini`` in the source distribution |
| 277 |
|
| 278 |
0.2.6 *2023-01-14* |
| 279 |
* **Updated** tables to include Unicode Specification 14.0.0 and 15.0.0. |
| 280 |
* **Changed** developer tools to use pip-compile, and to use jinja2 templates |
| 281 |
for code generation in `bin/update-tables.py` to prepare for possible |
| 282 |
compiler optimization release. |
| 283 |
|
| 284 |
0.2.1 .. 0.2.5 *2020-06-23* |
| 285 |
* **Repository** changes to update tests and packaging issues, and |
| 286 |
begin tagging repository with matching release versions. |
| 287 |
|
| 288 |
0.2.0 *2020-06-01* |
| 289 |
* **Enhancement**: Unicode version may be selected by exporting the |
| 290 |
Environment variable ``UNICODE_VERSION``, such as ``13.0``, or ``6.3.0``. |
| 291 |
See the `jquast/ucs-detect`_ CLI utility for automatic detection. |
| 292 |
* **Enhancement**: |
| 293 |
API Documentation is published to readthedocs.org. |
| 294 |
* **Updated** tables for *all* Unicode Specifications with files |
| 295 |
published in a programmatically consumable format, versions 4.1.0 |
| 296 |
through 13.0 |
| 297 |
|
| 298 |
0.1.9 *2020-03-22* |
| 299 |
* **Performance** optimization by `Avram Lubkin`_, `PR #35`_. |
| 300 |
* **Updated** tables to Unicode Specification 13.0.0. |
| 301 |
|
| 302 |
0.1.8 *2020-01-01* |
| 303 |
* **Updated** tables to Unicode Specification 12.0.0. (`PR #30`_). |
| 304 |
|
| 305 |
0.1.7 *2016-07-01* |
| 306 |
* **Updated** tables to Unicode Specification 9.0.0. (`PR #18`_). |
| 307 |
|
| 308 |
0.1.6 *2016-01-08 Production/Stable* |
| 309 |
* ``LICENSE`` file now included with distribution. |
| 310 |
|
| 311 |
0.1.5 *2015-09-13 Alpha* |
| 312 |
* **Bugfix**: |
| 313 |
Resolution of "combining_ character width" issue, most especially |
| 314 |
those that previously returned -1 now often (correctly) return 0. |
| 315 |
resolved by `Philip Craig`_ via `PR #11`_. |
| 316 |
* **Deprecated**: |
| 317 |
The module path ``wcwidth.table_comb`` is no longer available, |
| 318 |
it has been superseded by module path ``wcwidth.table_zero``. |
| 319 |
|
| 320 |
0.1.4 *2014-11-20 Pre-Alpha* |
| 321 |
* **Feature**: ``wcswidth()`` now determines printable length |
| 322 |
for (most) combining_ characters. The developer's tool |
| 323 |
`bin/wcwidth-browser.py`_ is improved to display combining_ |
| 324 |
characters when provided the ``--combining`` option |
| 325 |
(`Thomas Ballinger`_ and `Leta Montopoli`_ `PR #5`_). |
| 326 |
* **Feature**: added static analysis (prospector_) to testing |
| 327 |
framework. |
| 328 |
|
| 329 |
0.1.3 *2014-10-29 Pre-Alpha* |
| 330 |
* **Bugfix**: 2nd parameter of wcswidth was not honored. |
| 331 |
(`Thomas Ballinger`_, `PR #4`_). |
| 332 |
|
| 333 |
0.1.2 *2014-10-28 Pre-Alpha* |
| 334 |
* **Updated** tables to Unicode Specification 7.0.0. |
| 335 |
(`Thomas Ballinger`_, `PR #3`_). |
| 336 |
|
| 337 |
0.1.1 *2014-05-14 Pre-Alpha* |
| 338 |
* Initial release to pypi, Based on Unicode Specification 6.3.0 |
| 339 |
|
| 340 |
This code was originally derived directly from C code of the same name, |
| 341 |
whose latest version is available at |
| 342 |
https://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c:: |
| 343 |
|
| 344 |
* Markus Kuhn -- 2007-05-26 (Unicode 5.0) |
| 345 |
* |
| 346 |
* Permission to use, copy, modify, and distribute this software |
| 347 |
* for any purpose and without fee is hereby granted. The author |
| 348 |
* disclaims all warranties with regard to this software. |
| 349 |
|
| 350 |
.. _`Specification_from_pypi`: https://wcwidth.readthedocs.io/en/latest/specs.html |
| 351 |
.. _`tox`: https://tox.wiki/en/latest/ |
| 352 |
.. _`prospector`: https://github.com/landscapeio/prospector |
| 353 |
.. _`combining`: https://en.wikipedia.org/wiki/Combining_character |
| 354 |
.. _`bin/`: https://github.com/jquast/wcwidth/tree/master/bin |
| 355 |
.. _`bin/wcwidth-browser.py`: https://github.com/jquast/wcwidth/blob/master/bin/wcwidth-browser.py |
| 356 |
.. _`Thomas Ballinger`: https://github.com/thomasballinger |
| 357 |
.. _`Leta Montopoli`: https://github.com/lmontopo |
| 358 |
.. _`Philip Craig`: https://github.com/philipc |
| 359 |
.. _`PR #3`: https://github.com/jquast/wcwidth/pull/3 |
| 360 |
.. _`PR #4`: https://github.com/jquast/wcwidth/pull/4 |
| 361 |
.. _`PR #5`: https://github.com/jquast/wcwidth/pull/5 |
| 362 |
.. _`PR #11`: https://github.com/jquast/wcwidth/pull/11 |
| 363 |
.. _`PR #18`: https://github.com/jquast/wcwidth/pull/18 |
| 364 |
.. _`PR #30`: https://github.com/jquast/wcwidth/pull/30 |
| 365 |
.. _`PR #35`: https://github.com/jquast/wcwidth/pull/35 |
| 366 |
.. _`PR #82`: https://github.com/jquast/wcwidth/pull/82 |
| 367 |
.. _`PR #91`: https://github.com/jquast/wcwidth/pull/91 |
| 368 |
.. _`PR #97`: https://github.com/jquast/wcwidth/pull/97 |
| 369 |
.. _`PR #98`: https://github.com/jquast/wcwidth/pull/98 |
| 370 |
.. _`PR #100`: https://github.com/jquast/wcwidth/pull/100 |
| 371 |
.. _`Issue #101`: https://github.com/jquast/wcwidth/issues/101 |
| 372 |
.. _`jquast/blessed`: https://github.com/jquast/blessed |
| 373 |
.. _`selectel/pyte`: https://github.com/selectel/pyte |
| 374 |
.. _`thomasballinger/curtsies`: https://github.com/thomasballinger/curtsies |
| 375 |
.. _`dbcli/pgcli`: https://github.com/dbcli/pgcli |
| 376 |
.. _`prompt-toolkit/python-prompt-toolkit`: https://github.com/prompt-toolkit/python-prompt-toolkit |
| 377 |
.. _`timoxley/wcwidth`: https://github.com/timoxley/wcwidth |
| 378 |
.. _`wcwidth(3)`: https://man7.org/linux/man-pages/man3/wcwidth.3.html |
| 379 |
.. _`wcswidth(3)`: https://man7.org/linux/man-pages/man3/wcswidth.3.html |
| 380 |
.. _`astanin/python-tabulate`: https://github.com/astanin/python-tabulate |
| 381 |
.. _`janlelis/unicode-display_width`: https://github.com/janlelis/unicode-display_width |
| 382 |
.. _`rspeer/python-ftfy`: https://github.com/rspeer/python-ftfy |
| 383 |
.. _`alecrabbit/php-wcwidth`: https://github.com/alecrabbit/php-wcwidth |
| 384 |
.. _`Text::CharWidth`: https://metacpan.org/pod/Text::CharWidth |
| 385 |
.. _`bluebear94/Terminal-WCWidth`: https://github.com/bluebear94/Terminal-WCWidth |
| 386 |
.. _`mattn/go-runewidth`: https://github.com/mattn/go-runewidth |
| 387 |
.. _`grepsuzette/wcwidth`: https://github.com/grepsuzette/wcwidth |
| 388 |
.. _`jquast/ucs-detect`: https://github.com/jquast/ucs-detect |
| 389 |
.. _`Avram Lubkin`: https://github.com/avylove |
| 390 |
.. _`nbedos/termtosvg`: https://github.com/nbedos/termtosvg |
| 391 |
.. _`peterbrittain/asciimatics`: https://github.com/peterbrittain/asciimatics |
| 392 |
.. _`aperezdc/lua-wcwidth`: https://github.com/aperezdc/lua-wcwidth |
| 393 |
.. _`joachimschmidt557/zig-wcwidth`: https://github.com/joachimschmidt557/zig-wcwidth |
| 394 |
.. _`fumiyas/wcwidth-cjk`: https://github.com/fumiyas/wcwidth-cjk |
| 395 |
.. _`joshuarubin/wcwidth9`: https://github.com/joshuarubin/wcwidth9 |
| 396 |
.. _`python-cmd2/cmd2`: https://github.com/python-cmd2/cmd2 |
| 397 |
.. _`stratis-storage/stratis-cli`: https://github.com/stratis-storage/stratis-cli |
| 398 |
.. _`ihabunek/toot`: https://github.com/ihabunek/toot |
| 399 |
.. _`saulpw/visidata`: https://github.com/saulpw/visidata |
| 400 |
.. _`pip-tools`: https://pip-tools.readthedocs.io/ |
| 401 |
.. _`sphinx`: https://www.sphinx-doc.org/ |
| 402 |
.. |pypi_downloads| image:: https://img.shields.io/pypi/dm/wcwidth.svg?logo=pypi |
| 403 |
:alt: Downloads |
| 404 |
:target: https://pypi.org/project/wcwidth/ |
| 405 |
.. |codecov| image:: https://codecov.io/gh/jquast/wcwidth/branch/master/graph/badge.svg |
| 406 |
:alt: codecov.io Code Coverage |
| 407 |
:target: https://app.codecov.io/gh/jquast/wcwidth/ |
| 408 |
.. |license| image:: https://img.shields.io/pypi/l/wcwidth.svg |
| 409 |
:target: https://pypi.org/project/wcwidth/ |
| 410 |
:alt: MIT License |