1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
.. contents:: **tcolorpy**
:backlinks: top
:depth: 2
Summary
============================================
tcolopy is a Python library to apply true color for terminal text.
|PyPI pkg ver| |conda pkg ver| |Supported Python implementations| |Supported Python versions| |CI status| |CodeQL| |coverage|
.. |PyPI pkg ver| image:: https://badge.fury.io/py/tcolorpy.svg
:target: https://badge.fury.io/py/tcolorpy
:alt: PyPI package version
.. |conda pkg ver| image:: https://anaconda.org/conda-forge/tcolorpy/badges/version.svg
:target: https://anaconda.org/conda-forge/tcolorpy
:alt: conda-forge package version
.. |Supported Python implementations| image:: https://img.shields.io/pypi/implementation/tcolorpy.svg
:target: https://pypi.org/project/tcolorpy
:alt: Supported Python implementations
.. |Supported Python versions| image:: https://img.shields.io/pypi/pyversions/tcolorpy.svg
:target: https://pypi.org/project/tcolorpy
:alt: Supported Python versions
.. |CI status| image:: https://github.com/thombashi/tcolorpy/actions/workflows/ci.yml/badge.svg
:target: https://github.com/thombashi/tcolorpy/actions/workflows/ci.yml
:alt: CI status of Linux/macOS/Windows
.. |CodeQL| image:: https://github.com/thombashi/tcolorpy/actions/workflows/github-code-scanning/codeql/badge.svg
:target: https://github.com/thombashi/tcolorpy/actions/workflows/github-code-scanning/codeql
:alt: CodeQL
.. |coverage| image:: https://coveralls.io/repos/github/thombashi/tcolorpy/badge.svg?branch=master
:target: https://coveralls.io/github/thombashi/tcolorpy?branch=master
:alt: Test coverage: coveralls
Installation
============================================
Installation: pip
------------------------------
::
pip install tcolorpy
Installation: conda
------------------------------
::
conda install -c conda-forge tcolorpy
Usage
============================================
Library usage
--------------------------------------------
:Sample Code:
.. code-block:: python
from tcolorpy import tcolor
print(tcolor("tcolopy example", color="#ee1177", styles=["bold", "italic", "underline"]))
:Output:
.. figure:: https://cdn.jsdelivr.net/gh/thombashi/tcolorpy@master/ss/oneline.png
:scale: 60%
:alt: https://github.com/thombashi/tcolorpy/blob/master/ss/oneline.png
You can set the following ``tcolor`` arguments:
- ``color``/``bg_color``
- color names (``"red"``, ``"green"``, etc.) or color code (``"#RRGGBB"``)
- ``styles``
- ``"bold"``, ``"italic"``, etc.
Other examples
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Apply true color and styles to text:
.. figure:: https://cdn.jsdelivr.net/gh/thombashi/tcolorpy@master/ss/styles.png
:scale: 60%
:alt: https://github.com/thombashi/tcolorpy/blob/master/ss/styles.png
`example source code <https://github.com/thombashi/tcolorpy/blob/master/examples/ansi_styles.py>`__
You can also specify colors by name:
.. figure:: https://cdn.jsdelivr.net/gh/thombashi/tcolorpy@master/ss/ansi_colors.png
:scale: 60%
:alt: https://github.com/thombashi/tcolorpy/blob/master/ss/ansi_colors.png
`example source code <https://github.com/thombashi/tcolorpy/blob/master/examples/ansi_colors.py>`__
CLI usage
--------------------------------------------
``tcolorpy`` can be used via CLI:
::
$ python3 -m tcolorpy "tcolopy example" -c "#ee1177" -s bold,italic,underline
Command help
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
::
usage: __main__.py [-h] [-c COLOR] [-b BG_COLOR] [-s STYLES] [--encode ENCODE] string
positional arguments:
string string to apply styles.
options:
-h, --help show this help message and exit
-c COLOR, --color COLOR
specify a color code (#XXXXXX) or a name. valid names are: black, red, green, yellow, blue, magenta, cyan, white, lightblack, lightred, lightgreen, lightyellow, lightblue, lightmagenta, lightcyan, lightwhite
-b BG_COLOR, --bg-color BG_COLOR
specify a background color code (#XXXXXX) or a name. valid names are: black, red, green, yellow, blue, magenta, cyan, white, lightblack, lightred, lightgreen, lightyellow, lightblue, lightmagenta, lightcyan, lightwhite
-s STYLES, --styles STYLES
specify a comma-separated style. valid values are: bold, dim, italic, underline, blink, invert, strike
--encode ENCODE output a text encoded with the specified encoding
Dependencies
============================================
Python 3.7+
no external dependencies.
|