You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

251 lines
8.3 KiB

4 years ago
  1. Metadata-Version: 2.0
  2. Name: wcwidth
  3. Version: 0.1.7
  4. Summary: Measures number of Terminal column cells of wide-character codes
  5. Home-page: https://github.com/jquast/wcwidth
  6. Author: Jeff Quast
  7. Author-email: contact@jeffquast.com
  8. License: MIT
  9. Keywords: terminal,emulator,wcwidth,wcswidth,cjk,combining,xterm,console
  10. Platform: UNKNOWN
  11. Classifier: Intended Audience :: Developers
  12. Classifier: Natural Language :: English
  13. Classifier: Development Status :: 3 - Alpha
  14. Classifier: Environment :: Console
  15. Classifier: License :: OSI Approved :: MIT License
  16. Classifier: Operating System :: POSIX
  17. Classifier: Programming Language :: Python :: 2.7
  18. Classifier: Programming Language :: Python :: 3.4
  19. Classifier: Programming Language :: Python :: 3.5
  20. Classifier: Topic :: Software Development :: Libraries
  21. Classifier: Topic :: Software Development :: Localization
  22. Classifier: Topic :: Software Development :: Internationalization
  23. Classifier: Topic :: Terminals
  24. .. image:: https://img.shields.io/travis/jquast/wcwidth.svg
  25. :target: https://travis-ci.org/jquast/wcwidth
  26. :alt: Travis Continous Integration
  27. .. image:: https://img.shields.io/coveralls/jquast/wcwidth.svg
  28. :target: https://coveralls.io/r/jquast/wcwidth
  29. :alt: Coveralls Code Coverage
  30. .. image:: https://img.shields.io/pypi/v/wcwidth.svg
  31. :target: https://pypi.python.org/pypi/wcwidth/
  32. :alt: Latest Version
  33. .. image:: https://img.shields.io/github/license/jquast/wcwidth.svg
  34. :target: https://pypi.python.org/pypi/wcwidth/
  35. :alt: License
  36. .. image:: https://img.shields.io/pypi/wheel/wcwidth.svg
  37. :alt: Wheel Status
  38. .. image:: https://img.shields.io/pypi/dm/wcwidth.svg
  39. :target: https://pypi.python.org/pypi/wcwidth/
  40. :alt: Downloads
  41. ============
  42. Introduction
  43. ============
  44. This Library is mainly for those implementing a Terminal Emulator, or programs
  45. that carefully produce output to be interpreted by one.
  46. **Problem Statement**: When printed to the screen, the length of the string is
  47. usually equal to the number of cells it occupies. However, there are
  48. categories of characters that occupy 2 cells (full-wide), and others that
  49. occupy 0.
  50. **Solution**: POSIX.1-2001 and POSIX.1-2008 conforming systems provide
  51. `wcwidth(3)`_ and `wcswidth(3)`_ C functions of which this python module's
  52. functions precisely copy. *These functions return the number of cells a
  53. unicode string is expected to occupy.*
  54. This library aims to be forward-looking, portable, and most correct. The most
  55. current release of this API is based on the Unicode Standard release files:
  56. ``DerivedGeneralCategory-9.0.0.txt``
  57. *Date: 2016-06-01, 10:34:26 GMT*
  58. © 2016 Unicode®, Inc.
  59. ``EastAsianWidth-9.0.0.txt``
  60. *Date: 2016-05-27, 17:00:00 GMT [KW, LI]*
  61. © 2016 Unicode®, Inc.
  62. Installation
  63. ------------
  64. The stable version of this package is maintained on pypi, install using pip::
  65. pip install wcwidth
  66. Example
  67. -------
  68. To Display ``u'コンニチハ'`` right-adjusted on screen of 80 columns::
  69. >>> from wcwidth import wcswidth
  70. >>> text = u'コンニチハ'
  71. >>> text_len = wcswidth(text)
  72. >>> print(u' ' * (80 - text_len) + text)
  73. wcwidth, wcswidth
  74. -----------------
  75. Use function ``wcwidth()`` to determine the length of a *single unicode
  76. character*, and ``wcswidth()`` to determine the length of a several, or a
  77. *string of unicode characters*.
  78. Briefly, return values of function ``wcwidth()`` are:
  79. ``-1``
  80. Indeterminate (not printable).
  81. ``0``
  82. Does not advance the cursor, such as NULL or Combining.
  83. ``2``
  84. Characters of category East Asian Wide (W) or East Asian
  85. Full-width (F) which are displayed using two terminal cells.
  86. ``1``
  87. All others.
  88. Function ``wcswidth()`` simply returns the sum of all values for each character
  89. along a string, or ``-1`` when it occurs anywhere along a string.
  90. More documentation is available using pydoc::
  91. $ pydoc wcwidth
  92. =======
  93. Caveats
  94. =======
  95. This library attempts to determine the printable width by an unknown targeted
  96. terminal emulator. It does not provide any ability to discern what the target
  97. emulator software, version, of level of support is. Results may vary!
  98. A `crude method
  99. <http://blessed.readthedocs.org/en/latest/examples.html#detect-multibyte-py>`_
  100. of determining the level of unicode support by the target emulator may be
  101. performed using the VT100 Query Cursor Position sequence.
  102. The libc version of `wcwidth(3)`_ is often several unicode releases behind,
  103. and therefor several levels of support lower than this python library. You
  104. may determine an exacting list of these discrepancies using the project
  105. file `wcwidth-libc-comparator.py
  106. <https://github.com/jquast/wcwidth/tree/master/bin/wcwidth-libc-comparator.py>`_.
  107. ==========
  108. Developing
  109. ==========
  110. Install wcwidth in editable mode::
  111. pip install -e.
  112. Install developer requirements::
  113. pip install -r requirements-develop.txt
  114. Execute unit tests using tox::
  115. tox
  116. Updating Tables
  117. ---------------
  118. The command ``python setup.py update`` will fetch the following resources:
  119. - http://www.unicode.org/Public/UNIDATA/EastAsianWidth.txt
  120. - http://www.unicode.org/Public/UNIDATA/extracted/DerivedGeneralCategory.txt
  121. And generates the table files:
  122. - `wcwidth/table_wide.py <https://github.com/jquast/wcwidth/tree/master/wcwidth/table_wide.py>`_
  123. - `wcwidth/table_zero.py <https://github.com/jquast/wcwidth/tree/master/wcwidth/table_zero.py>`_
  124. Uses
  125. ----
  126. This library is used in:
  127. - `jquast/blessed`_, a simplified wrapper around curses.
  128. - `jonathanslenders/python-prompt-toolkit`_, a Library for building powerful
  129. interactive command lines in Python.
  130. Additional tools for displaying and testing wcwidth are found in the `bin/
  131. <https://github.com/jquast/wcwidth/tree/master/bin>`_ folder of this project's
  132. source code. They are not distributed.
  133. =======
  134. History
  135. =======
  136. 0.1.7 *2016-07-01*
  137. * **Updated** tables to Unicode Specification 9.0.0. (`PR #18`_).
  138. 0.1.6 *2016-01-08 Production/Stable*
  139. * ``LICENSE`` file now included with distribution.
  140. 0.1.5 *2015-09-13 Alpha*
  141. * **Bugfix**:
  142. Resolution of "combining_ character width" issue, most especially
  143. those that previously returned -1 now often (correctly) return 0.
  144. resolved by `Philip Craig`_ via `PR #11`_.
  145. * **Deprecated**:
  146. The module path ``wcwidth.table_comb`` is no longer available,
  147. it has been superseded by module path ``wcwidth.table_zero``.
  148. 0.1.4 *2014-11-20 Pre-Alpha*
  149. * **Feature**: ``wcswidth()`` now determines printable length
  150. for (most) combining_ characters. The developer's tool
  151. `bin/wcwidth-browser.py`_ is improved to display combining_
  152. characters when provided the ``--combining`` option
  153. (`Thomas Ballinger`_ and `Leta Montopoli`_ `PR #5`_).
  154. * **Feature**: added static analysis (prospector_) to testing
  155. framework.
  156. 0.1.3 *2014-10-29 Pre-Alpha*
  157. * **Bugfix**: 2nd parameter of wcswidth was not honored.
  158. (`Thomas Ballinger`_, `PR #4`_).
  159. 0.1.2 *2014-10-28 Pre-Alpha*
  160. * **Updated** tables to Unicode Specification 7.0.0.
  161. (`Thomas Ballinger`_, `PR #3`_).
  162. 0.1.1 *2014-05-14 Pre-Alpha*
  163. * Initial release to pypi, Based on Unicode Specification 6.3.0
  164. This code was originally derived directly from C code of the same name,
  165. whose latest version is available at
  166. http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c::
  167. * Markus Kuhn -- 2007-05-26 (Unicode 5.0)
  168. *
  169. * Permission to use, copy, modify, and distribute this software
  170. * for any purpose and without fee is hereby granted. The author
  171. * disclaims all warranties with regard to this software.
  172. .. _`prospector`: https://github.com/landscapeio/prospector
  173. .. _`combining`: https://en.wikipedia.org/wiki/Combining_character
  174. .. _`bin/wcwidth-browser.py`: https://github.com/jquast/wcwidth/tree/master/bin/wcwidth-browser.py
  175. .. _`Thomas Ballinger`: https://github.com/thomasballinger
  176. .. _`Leta Montopoli`: https://github.com/lmontopo
  177. .. _`Philip Craig`: https://github.com/philipc
  178. .. _`PR #3`: https://github.com/jquast/wcwidth/pull/3
  179. .. _`PR #4`: https://github.com/jquast/wcwidth/pull/4
  180. .. _`PR #5`: https://github.com/jquast/wcwidth/pull/5
  181. .. _`PR #11`: https://github.com/jquast/wcwidth/pull/11
  182. .. _`PR #18`: https://github.com/jquast/wcwidth/pull/18
  183. .. _`jquast/blessed`: https://github.com/jquast/blessed
  184. .. _`jonathanslenders/python-prompt-toolkit`: https://github.com/jonathanslenders/python-prompt-toolkit
  185. .. _`wcwidth(3)`: http://man7.org/linux/man-pages/man3/wcwidth.3.html
  186. .. _`wcswidth(3)`: http://man7.org/linux/man-pages/man3/wcswidth.3.html