{ "info": { "author": "S\u00e9bastien MB", "author_email": "seb@essembeh.org", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Console", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3 :: Only", "Topic :: Software Development :: Libraries", "Topic :: Terminals :: Terminal Emulators/X Terminals", "Topic :: Utilities" ], "description": "\n![Github](https://img.shields.io/github/tag/essembeh/pytput.svg)\n![PyPi](https://img.shields.io/pypi/v/pytput.svg)\n![Python](https://img.shields.io/pypi/pyversions/pytput.svg)\n\n\n\n# PyTput\n\n> TL;DR: You can format your message with `{message:bold,underline,purple}`\n> \nSimple executable and *Python3 API* to format messages using colors and styles from `tput`:\n- `pytput` executable to be used in any *shell-like* script\n- *Python3* module to format messages directly in any python application\n\n![help](images/help.gif)\n\n\n# Install\n\nInstall via `pip`:\n\n```sh\n# Install pip for python3\n$ sudo apt install python3-pip\n$ pip install pytput\n```\n\nOr you can clone the project and install it via `setup.py`:\n\n```sh\n# Install python3\n$ sudo apt install python3 python3-setuptools\n# Clone repository\n$ git clone https://github.com/essembeh/pytput\n$ cd pytput\n# If you are in a virtualenv, install it with\n$ python3 setup.py install\n# or use --user if you want to install it in userland\n$ python3 setup.py install --user\n```\n\nTo setup a development environment:\n\n```sh\n$ git clone https://github.com/essembeh/pytput\n$ cd pytput\n$ make venv\n$ source venv/bin/activate\n(venv) $ make install # equivalent to ./setup.py install\n(venv) $ make # To run the tests, coverage and flake8\n(venv) $ make watch # to reinstall automatically if you modify the source code\n```\n\n# Usage\n\n## Using a *TputFormatter* class\nYou can use the `TputFormatter` class to decorate variables with *styles*.\n\n```python\nfrom pytput import TputFormatter\ntf = TputFormatter()\n\n# Build a colored string and print it\ntext = tf.format(\"{hello:bg_yellow,bold} {world:cyan,underline}!\", hello=\"Hello\", world=\"World\")\nprint(text)\n\n# You can combine multiple styles and common str.format spec\ntext = tf.format(\"{hello:.2,bg_yellow,underline} {myvalue:04d,cyan}!\", hello=\"Hello\", myvalue=42)\nprint(text)\n```\n\n![TputFormatter](images/formatter.png)\n\nHere is the list of available styles\n\n| Formatter keyword | tput command |\n| ----------------- | -------------- |\n| *bold* | `tput bold` |\n| *dim* | `tput dim` |\n| *underline* | `tput smul` |\n| *blink* | `tput blink` |\n| *standout* | `tput smso` |\n| *reverse* | `tput rev` |\n| *reset* | `tput sgr0` |\n| *black* | `tput setaf 0` |\n| *red* | `tput setaf 1` |\n| *green* | `tput setaf 2` |\n| *yellow* | `tput setaf 3` |\n| *blue* | `tput setaf 4` |\n| *purple* | `tput setaf 5` |\n| *cyan* | `tput setaf 6` |\n| *white* | `tput setaf 7` |\n| *bg_black* | `tput setab 0` |\n| *bg_red* | `tput setab 1` |\n| *bg_green* | `tput setab 2` |\n| *bg_yellow* | `tput setab 3` |\n| *bg_blue* | `tput setab 4` |\n| *bg_purple* | `tput setab 5` |\n| *bg_cyan* | `tput setab 6` |\n| *bg_white* | `tput setab 7` |\n\n\n> Styles can be combined with `','` like `{message:underline,bold,yellow}`\n\n> You can also reuse `string.Formatter` format specification like `{myint:05d,underline,bold,yellow}` or `{mystr:.10,underline,dim,red}`\n\n## Using *format-like* and *print-like* functions\n\nSome utility functions can be used to simply print lines with *styles*\n\n```python\nfrom pytput import print_red, print_color, tput_format, tput_print, Color\n\n# These functions work like *print* builtin function\nprint_red(\"My message is red\")\nprint_color(\"green\", \"This message is green\")\nprint_color(Color.PURPLE, \"This message is purple\")\nprint_color(4, \"This message is blue\")\n\n# Simply format a message usinf a TputFormatter\ntext = tput_format(\"Build a string: {hello:bg_yellow} {world:cyan}!\", hello=\"Hello\", world=\"World\")\nprint(text)\n\n# Or simply use tc_print to replace the two lines above\ntput_print(\"Directly print: {hello:bg_yellow} {world:cyan}!\", hello=\"Hello\", world=\"World\")\n```\n![utils](images/utils.png)\n\n\n## Using *pytput* executable\n\n*PyTput* comes with an handy executable to use colors and styles directly from the command line. This is usefull to customize messages in shell scripts for example.\n\n```sh\n$ pytput '{0:red} {1:green}!' 'Hello' 'World'\n$ pytput \"{0:bold,red} {1:underline,dim,yellow} {2:bg_purple,yellow,blink}\" \"This is\" \"a message\" \"with styles ;)\"\n$ pytput \"{0:red,bold,underline}\" \"Simple error message\"\n$ pytput \"{0:bg_purple,white,bold}\" \"Another message\"\n```\n\n![CLI](images/cli.png)\n\n> See `pytput --help` for more details.\n\n## Disabling *pytput*\n\nBy default, *pytput API* is disabled if `sys.stdout.isatty()` is `False`, so you won't write any color nor style if you pipe the output or redirect it in a file.\n\nUsing `pytput` executable, you can force colors and styles using the `--force` argument.\n\n```sh\n# You get colors by default\n$ pytput '{0:red} {1:green}!' 'Hello' 'World'\n# Colors will be disabled\n$ pytput '{0:red} {1:green}!' 'Hello' 'World' | cat \n$ pytput '{0:red} {1:green}!' 'Hello' 'World' > /tmp/pytput.txt\n$ cat /tmp/pytput.txt\n# Colors will be enabled\n$ pytput --force '{0:red} {1:green}!' 'Hello' 'World' | cat \n$ pytput --force '{0:red} {1:green}!' 'Hello' 'World' > /tmp/pytput.txt\n$ cat /tmp/pytput.txt\n```\n\n![force](images/force.png)\n\nUsing *pytput python3 API*, you can force styles and colors even if `sys.stdout` is not a TTY using `TputFormatter`:\n```python\nfrom pytput import TputFormatter, tput_print\n\n# These lines won't have colors if you redirect stdout to a file\nprint(TputFormatter().format(\"{0:red} {1:green}!\\n\", \"Hello\", \"World\"))\ntput_print(\"{0:red} {1:green}!\\n\", \"Hello\", \"World\"))\n\n# These line will have colors even if stdout is redirected \nprint(TputFormatter(check_tty=False).format(\"{0:red} {1:green}!\\n\", \"Hello\", \"World\"))\ntput_print(\"{0:red} {1:green}!\\n\", \"Hello\", \"World\", check_tty=False))\n```\n\nYou can totally disable `pytput` by setting `PYTPUT_DISABLE` variable in environment.\n```sh\n# Colors will be enabled\n$ pytput '{0:red} {1:green}!' 'Hello' 'World'\n# Colors will be disabled\n$ PYTPUT_DISABLE=1 pytput '{0:red} {1:green}!' 'Hello' 'World'\n```\n![env](images/env.png)\n\n> Note: If your program uses *pytput API* like the class `TputFormatter`, setting the environment variable `PYTPUT_DISABLE=1` will disable all colors and styles.\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/essembeh/pytput", "keywords": "", "license": "Mozilla Public License Version 2.0", "maintainer": "", "maintainer_email": "", "name": "pytput", "package_url": "https://pypi.org/project/pytput/", "platform": "", "project_url": "https://pypi.org/project/pytput/", "project_urls": { "Homepage": "https://github.com/essembeh/pytput" }, "release_url": "https://pypi.org/project/pytput/0.1.2/", "requires_dist": null, "requires_python": "", "summary": "Python3 API to format messages using colors and styles", "version": "0.1.2" }, "last_serial": 5574434, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "a11319625068123732667b231999164a", "sha256": "b3e1200a4e03000444fafa0d48f9a48cb36f037f4de9ac1009e2dbc4cc582548" }, "downloads": -1, "filename": "pytput-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "a11319625068123732667b231999164a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 14121, "upload_time": "2019-07-20T20:01:10", "url": "https://files.pythonhosted.org/packages/9e/df/386e4066fe8f37e02f738d482f27cb4cd53227b22a861f88f981a0ba3876/pytput-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a3a9f81b84a67d5637559e90a842cf28", "sha256": "f890b28310eb935c9d8c79c5afe4ba008423283c9e94f3adf4b3ab831d8c18a0" }, "downloads": -1, "filename": "pytput-0.1.0.tar.gz", "has_sig": false, "md5_digest": "a3a9f81b84a67d5637559e90a842cf28", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 213462, "upload_time": "2019-07-20T20:01:13", "url": "https://files.pythonhosted.org/packages/ce/98/f70924667c73ebe8f674969b9857c5986810644208e9029898c6eda9112b/pytput-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "8fc2fb49ce743181393afef64154cfe9", "sha256": "b6ad09ea8115644129a8ec4c5320e1892e36501b308bcfc68026ec09ed834d5f" }, "downloads": -1, "filename": "pytput-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "8fc2fb49ce743181393afef64154cfe9", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 14101, "upload_time": "2019-07-23T11:34:20", "url": "https://files.pythonhosted.org/packages/d4/21/826c3bd997a000f3cc7e50130f12340b003e350cd53d47ec1d45049db6fe/pytput-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b50ef23384182dedd4cb011c540c564a", "sha256": "d355feefb35e8baca098dfcbd824f3083ff9860786b353a56117afef01d5ad55" }, "downloads": -1, "filename": "pytput-0.1.1.tar.gz", "has_sig": false, "md5_digest": "b50ef23384182dedd4cb011c540c564a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 223825, "upload_time": "2019-07-23T11:34:22", "url": "https://files.pythonhosted.org/packages/90/f2/54587c04aaf35a47670634d16b8e44bdf210aa22c78d9e73cdd3de0cda72/pytput-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "fc0f866008ed06549a71d4bc02c160e4", "sha256": "e4241d6c235bdfba87b9eb54447a48cabcc123c7632b541c3267316d11405ecc" }, "downloads": -1, "filename": "pytput-0.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "fc0f866008ed06549a71d4bc02c160e4", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 14282, "upload_time": "2019-07-23T20:54:02", "url": "https://files.pythonhosted.org/packages/13/c1/625151140f49fba6a9f4c4046d6717aeef4ce30417d8fa8a7368cdc654d5/pytput-0.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a887b7b2566d379eb0e51e58981d9562", "sha256": "c1867b79c8231190bcb6c423375cd349c44467aa77cb034d9e3fc5170deb4824" }, "downloads": -1, "filename": "pytput-0.1.2.tar.gz", "has_sig": false, "md5_digest": "a887b7b2566d379eb0e51e58981d9562", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 223957, "upload_time": "2019-07-23T20:54:04", "url": "https://files.pythonhosted.org/packages/da/db/7435d5dcb16e38c02d5ad2876fc8b4152de07b92808d264f8f3423f7565e/pytput-0.1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "fc0f866008ed06549a71d4bc02c160e4", "sha256": "e4241d6c235bdfba87b9eb54447a48cabcc123c7632b541c3267316d11405ecc" }, "downloads": -1, "filename": "pytput-0.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "fc0f866008ed06549a71d4bc02c160e4", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 14282, "upload_time": "2019-07-23T20:54:02", "url": "https://files.pythonhosted.org/packages/13/c1/625151140f49fba6a9f4c4046d6717aeef4ce30417d8fa8a7368cdc654d5/pytput-0.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a887b7b2566d379eb0e51e58981d9562", "sha256": "c1867b79c8231190bcb6c423375cd349c44467aa77cb034d9e3fc5170deb4824" }, "downloads": -1, "filename": "pytput-0.1.2.tar.gz", "has_sig": false, "md5_digest": "a887b7b2566d379eb0e51e58981d9562", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 223957, "upload_time": "2019-07-23T20:54:04", "url": "https://files.pythonhosted.org/packages/da/db/7435d5dcb16e38c02d5ad2876fc8b4152de07b92808d264f8f3423f7565e/pytput-0.1.2.tar.gz" } ] }