Add sphinx-based documentation
This commit is contained in:
parent
dfecf4c7bd
commit
67a0e284b6
3 changed files with 123 additions and 0 deletions
1
docs/.gitignore
vendored
Normal file
1
docs/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
_build
|
||||
63
docs/conf.py
Normal file
63
docs/conf.py
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
# Configuration file for the Sphinx documentation builder.
|
||||
#
|
||||
# This file only contains a selection of the most common options. For a full
|
||||
# list see the documentation:
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html
|
||||
|
||||
# -- Path setup --------------------------------------------------------------
|
||||
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||
#
|
||||
# import os
|
||||
# import sys
|
||||
# sys.path.insert(0, os.path.abspath('.'))
|
||||
|
||||
import sys, os
|
||||
|
||||
import distutils.command.build
|
||||
from distutils.dist import Distribution
|
||||
|
||||
b = distutils.command.build.build(Distribution())
|
||||
b.initialize_options()
|
||||
b.finalize_options()
|
||||
|
||||
sys.path.insert(0, os.path.abspath(os.path.join("../", b.build_lib)))
|
||||
|
||||
# -- Project information -----------------------------------------------------
|
||||
|
||||
project = 'cwcwidth'
|
||||
copyright = '2021, Sebastian Ramacher'
|
||||
author = 'Sebastian Ramacher'
|
||||
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
|
||||
# Add any Sphinx extension module names here, as strings. They can be
|
||||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
||||
# ones.
|
||||
extensions = [
|
||||
"sphinx.ext.autodoc"
|
||||
]
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
templates_path = ['_templates']
|
||||
|
||||
# List of patterns, relative to source directory, that match files and
|
||||
# directories to ignore when looking for source files.
|
||||
# This pattern also affects html_static_path and html_extra_path.
|
||||
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
|
||||
|
||||
|
||||
# -- Options for HTML output -------------------------------------------------
|
||||
|
||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||
# a list of builtin themes.
|
||||
#
|
||||
html_theme = 'alabaster'
|
||||
|
||||
# Add any paths that contain custom static files (such as style sheets) here,
|
||||
# relative to this directory. They are copied after the builtin static files,
|
||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||
html_static_path = ['_static']
|
||||
59
docs/index.rst
Normal file
59
docs/index.rst
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
|
||||
cwcwidth -- bindings for wc(s)wdith
|
||||
===================================
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
:caption: Contents:
|
||||
|
||||
To compute the number of columns needed to print a string, POSIX.1-2001 and POSIX.1-2008 define two
|
||||
functions: ``wcwidth`` and ``wcswidth``. Given a character or string, they return the required
|
||||
number of columns or error out with ``-1`` if they encounter a nonprintable character. These
|
||||
functions are not available per default in Python, but are quite useful when the width plays a role
|
||||
for formatting outputs on a terminal.
|
||||
|
||||
Module documentation
|
||||
--------------------
|
||||
|
||||
The ``cwcwidth`` module provides the following two functions:
|
||||
|
||||
.. py:function:: cwcwidth.wcwidth(wc: str) -> int
|
||||
|
||||
Return the printable length of a unicode character.
|
||||
|
||||
.. py:function:: cwcwidth.wcswidth(pwcs: str, n: Optional[int]=None) -> int
|
||||
|
||||
Return the printable length of a unicode string. If the optional argument ``n`` is provided, only
|
||||
the first ``n`` characters of the string are considered.
|
||||
|
||||
Both functions behave in the same way as the functions with the same signture from the `wcwidth`_
|
||||
module.
|
||||
|
||||
.. _wcwidth: https://pypi.org/project/wcwidth/
|
||||
|
||||
Example usage
|
||||
-------------
|
||||
|
||||
::
|
||||
|
||||
>>> from cwcwidth import wcwidth, wcswidth
|
||||
>>> wcwidth("a")
|
||||
1
|
||||
>>> wcswidth("コ")
|
||||
2
|
||||
>>> wcswidth("コンニチハ, セカイ!")
|
||||
19
|
||||
>>> wcswidth("コンニチハ, セカイ!", 5)
|
||||
10
|
||||
|
||||
|
||||
Users
|
||||
-----
|
||||
|
||||
``cwcwidth`` is currently used by the following projects:
|
||||
|
||||
* `curtsies`_
|
||||
* `bpython`_
|
||||
|
||||
.. _curtsies: https://pypi.org/project/curtsies/
|
||||
.. _bpython: https://pypi.org/project/bpython/
|
||||
Loading…
Add table
Add a link
Reference in a new issue