diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..8cd490c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,104 @@ +Changelog +========= + +This project adheres to `Semantic Versioning `_. + +2.2.1 - 2021-12-08 +------------------ + +Added + * Publishin wheels + +2.2.0 - 2016-05-14 +------------------ + +Added + * ``disable_if_no_tty()`` function to conditionally disable colors when STDERR and STDOUT are not streams. + +Changed + * Colors enabled by default always, like it was before v2.0.0. + +2.1.1 - 2016-05-10 +------------------ + +Fixed + * Printing box drawing characters on Windows from Python 2.6. + +2.1.0 - 2016-05-07 +------------------ + +Added + * ``keep_tags`` boolean keyword argument to Color(). Prevents colorclass from parsing curly brackets. + * Automatically skip replacing stderr/stdout streams on latest Windows 10 versions with native ANSI color support. + +Changed + * Refactored most of windows.py. + * Background color determined from either stderr or stdout, instead of just one stream (e.g. piping stderr to file). + +Fixed + * https://github.com/Robpol86/colorclass/issues/16 + * https://github.com/Robpol86/colorclass/issues/18 + +2.0.0 - 2016-04-10 +------------------ + +Added + * Python 3.5 support. + * ``enable_all_colors()``, ``is_enabled()``, and ``is_light()`` toggle functions. + * Library can be used as a script (e.g. ``echo "{red}Red{/red}" |python -m colorclass``). + * Ability to add/multiply Color instances just like str. + * Ability to iterate a Color instance and have each character keep its color codes. + +Changed + * Converted library from Python module to a package. + * ``set_light_background()`` and ``set_dark_background()`` no longer enable colors. Use ``enable_all_colors()``. + * Colors are disabled by default when STDERR and STDOUT are not streams (piped to files/null). Similar to ``grep``. + * Reduce size of ANSI escape sequences by removing codes that have no effect. e.g. ``\033[31;35m`` to ``\033[35m``. + * Color methods that return strings now return Color instances instead of str instances. + +Fixed + * https://github.com/Robpol86/colorclass/issues/15 + * https://github.com/Robpol86/colorclass/issues/17 + +1.2.0 - 2015-03-19 +------------------ + +Added + * Convenience single-color methods by `Marc Abramowitz `_. + +1.1.2 - 2015-01-07 +------------------ + +Fixed + * Maintaining ``Color`` type through ``.encode()`` and ``.decode()`` chains. + +1.1.1 - 2014-11-03 +------------------ + +Fixed + * Python 2.7 64-bit original colors bug on Windows. + * resetting colors when ``reset_atexit`` is True. + * Improved sorting of ``list_tags()``. + +1.1.0 - 2014-11-01 +------------------ + +Added + * Native Windows support and automatic background colors. + +1.0.2 - 2014-10-20 +------------------ + +Added + * Ability to disable/strip out all colors. + +1.0.1 - 2014-09-11 +------------------ + +Fixed + * ``splitlines()`` method. + +1.0.0 - 2014-09-01 +------------------ + +* Initial release. diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000..b65ea42 --- /dev/null +++ b/Pipfile @@ -0,0 +1,13 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] + +[dev-packages] +pytest = "*" +vermin = "*" + +[requires] +python_version = "3.10" diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 0000000..068d0d5 --- /dev/null +++ b/Pipfile.lock @@ -0,0 +1,108 @@ +{ + "_meta": { + "hash": { + "sha256": "98f4caac4a46252f166ade98a8f70e0a01ea0f6a24ad1f3292f8549c6faf81f7" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.10" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": { + "vermin": { + "hashes": [ + "sha256:ef38dedab8cf7b68f8037f531b82222153ab21d3c54b91dd80776bbf95637ae5" + ], + "index": "pypi", + "version": "==1.3.1" + } + }, + "develop": { + "atomicwrites": { + "hashes": [ + "sha256:6d1784dea7c0c8d4a5172b6c620f40b6e4cbfdf96d783691f2e1302a7b88e197", + "sha256:ae70396ad1a434f9c7046fd2dd196fc04b12f9e91ffb859164193be8b6168a7a" + ], + "markers": "sys_platform == 'win32'", + "version": "==1.4.0" + }, + "attrs": { + "hashes": [ + "sha256:149e90d6d8ac20db7a955ad60cf0e6881a3f20d37096140088356da6c716b0b1", + "sha256:ef6aaac3ca6cd92904cdd0d83f629a15f18053ec84e6432106f7a4d04ae4f5fb" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'", + "version": "==21.2.0" + }, + "colorama": { + "hashes": [ + "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b", + "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2" + ], + "markers": "sys_platform == 'win32'", + "version": "==0.4.4" + }, + "iniconfig": { + "hashes": [ + "sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3", + "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32" + ], + "version": "==1.1.1" + }, + "packaging": { + "hashes": [ + "sha256:dd47c42927d89ab911e606518907cc2d3a1f38bbd026385970643f9c5b8ecfeb", + "sha256:ef103e05f519cdc783ae24ea4e2e0f508a9c99b2d4969652eed6a2e1ea5bd522" + ], + "markers": "python_version >= '3.6'", + "version": "==21.3" + }, + "pluggy": { + "hashes": [ + "sha256:4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159", + "sha256:74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3" + ], + "markers": "python_version >= '3.6'", + "version": "==1.0.0" + }, + "py": { + "hashes": [ + "sha256:51c75c4126074b472f746a24399ad32f6053d1b34b68d2fa41e558e6f4a98719", + "sha256:607c53218732647dff4acdfcd50cb62615cedf612e72d1724fb1a0cc6405b378" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'", + "version": "==1.11.0" + }, + "pyparsing": { + "hashes": [ + "sha256:04ff808a5b90911829c55c4e26f75fa5ca8a2f5f36aa3a51f68e27033341d3e4", + "sha256:d9bdec0013ef1eb5a84ab39a3b3868911598afa494f5faa038647101504e2b81" + ], + "markers": "python_version >= '3.6'", + "version": "==3.0.6" + }, + "pytest": { + "hashes": [ + "sha256:131b36680866a76e6781d13f101efb86cf674ebb9762eb70d3082b6f29889e89", + "sha256:7310f8d27bc79ced999e760ca304d69f6ba6c6649c0b60fb0e04a4a77cacc134" + ], + "index": "pypi", + "version": "==6.2.5" + }, + "toml": { + "hashes": [ + "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b", + "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f" + ], + "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==0.10.2" + } + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..83f704e --- /dev/null +++ b/README.md @@ -0,0 +1,99 @@ +# colorclass + +Yet another ANSI color text library for Python. Provides "auto colors" for dark/light terminals. Works on Linux, OS X, +and Windows. For Windows support you just need to call ``Windows.enable()`` in your application. + +On Linux/OS X ``autocolors`` are toggled by calling ``set_light_background()`` and ``set_dark_background()``. On Windows +this can be done automatically if you call ``Windows.enable(auto_colors=True)``. Even though the latest Windows 10 does +support ANSI color codes natively, you still need to run Windows.enable() to take advantage of automatically detecting +the console's background color. + +In Python2.x this library subclasses ``unicode``, while on Python3.x it subclasses ``str``. + +* Python 2.6, 2.7, PyPy, PyPy3, 3.3, 3.4, and 3.5 supported on Linux and OS X. +* Python 2.6, 2.7, 3.3, 3.4, and 3.5 supported on Windows (both 32 and 64 bit versions of Python). + +## Quickstart +Install: +```bash + pip install colorclass +``` + +## Piped Command Line +It is possible to pipe curly-bracket tagged (or regular ANSI coded) text to Python in the command line to produce color +text. Some examples: + +```bash + echo "{red}Red{/red}" |python -m colorclass # Red colored text. + echo -e "\033[31mRed\033[0m" | COLOR_DISABLE=true python -m colorclass # Strip colors + echo -e "\033[31mRed\033[0m" | COLOR_ENABLE=true python -m colorclass &> file.txt # Force colors. +``` +Export these environment variables as "true" to enable/disable some features: + + =============== ============================================ + Env Variable Description + =============== ============================================ + COLOR_ENABLE Force colors even when piping to a file. + COLOR_DISABLE Strip all colors from incoming text. + COLOR_LIGHT Use light colored text for dark backgrounds. + COLOR_DARK Use dark colored text for light backgrounds. + =============== ============================================ + +## Example Implementation + +![Example Script Screenshot](https://github.com/Robpol86/colorclass/raw/master/example.png?raw=true) + +![Example Windows Screenshot](https://github.com/Robpol86/colorclass/raw/master/example_windows.png?raw=true) + +Source code for the example code is: [example.py](https://github.com/Robpol86/colorclass/blob/master/example.py) + +## Usage + +Different colors are chosen using curly-bracket tags, such as ``{red}{/red}``. For a list of available colors, call +``colorclass.list_tags()``. + +The available "auto colors" tags are: + +* autoblack +* autored +* autogreen +* autoyellow +* autoblue +* automagenta +* autocyan +* autowhite +* autobgblack +* autobgred +* autobggreen +* autobgyellow +* autobgblue +* autobgmagenta +* autobgcyan +* autobgwhite + +Methods of Class instances try to return sane data, such as: + +```python + from colorclass import Color + color_string = Color('{red}Test{/red}') + + >>> color_string + u'\x1b[31mTest\x1b[39m' + + >>> len(color_string) + 4 + + >>> color_string.istitle() + True +``` +There are also a couple of helper attributes for all Color instances: + +```python + >>> color_string.value_colors + '\x1b[31mTest\x1b[39m' + + >>> color_string.value_no_colors + 'Test' +``` + +[Change Log](https://github.com/matthewdeanmartin/colorclass/blob/master/CHANGELOG.md) \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..12bb762 --- /dev/null +++ b/build.sh @@ -0,0 +1,11 @@ +echo assuming we still want to support python 2! +PROJECT="colorclass" +export PYTHONPATH=$PYTHONPATH:. +pylint "$PROJECT" +flake8 "$PROJECT" +python -m pytest "$PROJECT" +python -m pytest --doctest-glob="$PROJECT/**/*.py" +pytest tests -v --cov-report html:coverage --cov="$PROJECT" +echo not bumping version here, just checking if we can create the wheel +poetry build +check-wheel-contents dist/*.whl \ No newline at end of file diff --git a/colorclass/codes.py b/colorclass/codes.py index b0ecb03..a69958d 100644 --- a/colorclass/codes.py +++ b/colorclass/codes.py @@ -1,7 +1,10 @@ """Handles mapping between color names and ANSI codes and determining auto color codes.""" import sys -from collections import Mapping +try: + from collections import Mapping +except ImportError: + from collections.abc import Mapping BASE_CODES = { '/all': 0, 'b': 1, 'f': 2, 'i': 3, 'u': 4, 'flash': 5, 'outline': 6, 'negative': 7, 'invis': 8, 'strike': 9, diff --git a/.travis.yml b/dead_code/.travis.yml similarity index 100% rename from .travis.yml rename to dead_code/.travis.yml diff --git a/README.rst b/dead_code/README.rst similarity index 100% rename from README.rst rename to dead_code/README.rst diff --git a/appveyor.yml b/dead_code/appveyor.yml similarity index 100% rename from appveyor.yml rename to dead_code/appveyor.yml diff --git a/setup.py b/dead_code/setup.py old mode 100755 new mode 100644 similarity index 100% rename from setup.py rename to dead_code/setup.py diff --git a/publish.sh b/publish.sh new file mode 100644 index 0000000..8ad6022 --- /dev/null +++ b/publish.sh @@ -0,0 +1 @@ +rm -rf dist && poetry version patch && poetry build && twine upload dist/* diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..65eaec9 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,66 @@ +[tool.poetry] +name = "colorclass" +version = "2.2.2" +description = "Colorful worry-free console applications for Linux, Mac OS X, and Windows." +authors = [ + "Robpol86 ", + "Matthew Martin " +] +keywords = ["Shell", "Bash", "ANSI", "ASCII", "terminal", "console", "colors", "automatic"] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Environment :: Console", + "Environment :: MacOS X", + "Environment :: Win32 (MS Windows)", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Operating System :: MacOS :: MacOS X", + "Operating System :: Microsoft :: Windows", + "Operating System :: POSIX :: Linux", + "Operating System :: POSIX", + "Programming Language :: Python :: 2.6", + "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 3.3", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: Implementation :: PyPy", + "Topic :: Software Development :: Libraries", + "Topic :: Terminals", + "Topic :: Text Processing :: Markup" +] +packages = [ + { include = "colorclass" }, +] +include = [ + "colorclass/**/*.py", +] +exclude = [ +] +license = "MIT" +readme = "README.md" +repository = "https://github.com/matthewdeanmartin/colorclass" +homepage = "https://github.com/matthewdeanmartin/colorclass" +documentation = "https://github.com/matthewdeanmartin/colorclass" + +[tool.poetry.urls] +"Bug Tracker" = "https://github.com/matthewdeanmartin/colorclass/issues" +"Change Log" = "https://github.com/matthewdeanmartin/colorclass/blob/master/CHANGELOG.md" + +[tool.poetry.scripts] + + +[tool.poetry.dependencies] +# per vermin's estimation +python = ">=2.6 || >=3.0" + +[tool.poetry.dev-dependencies] +pytest = "==6.0.1" + +[build-system] +requires = ["poetry>=0.12"] +build-backend = "poetry.masonry.api" diff --git a/tests/screenshot.py b/tests/screenshot.py index cc391eb..eef06b9 100644 --- a/tests/screenshot.py +++ b/tests/screenshot.py @@ -174,7 +174,7 @@ class RunNewConsole(object): def iter_rows(pil_image): """Yield tuple of pixels for each row in the image. - itertools.izip in Python 2.x and zip in Python 3.x are writen in C. Much faster than anything else I've found + itertools.izip in Python 2.x and zip in Python 3.x are written in C. Much faster than anything else I've found written in pure Python. From: