{ "info": { "author": "Jessy Williams", "author_email": "jessy@jessywilliams.com", "bugtrack_url": null, "classifiers": [], "description": "[![pypi](https://img.shields.io/pypi/v/teletype.svg?style=for-the-badge)](https://pypi.python.org/pypi/teletype)\n[![licence](https://img.shields.io/github/license/jkwill87/teletype.svg?style=for-the-badge)](https://en.wikipedia.org/wiki/MIT_License)\n[![code style black](https://img.shields.io/badge/Code%20Style-Black-black.svg?style=for-the-badge)](https://github.com/ambv/black)\n\n\n# teletype\n\n**teletype** is a high-level cross platform tty library compatible with Python 2.7 and 3+. It provides a consistent interface between the terminal and cmd.exe by building on top of [terminfo](https://invisible-island.net/ncurses/terminfo.src.html) and [msvcrt](https://msdn.microsoft.com/en-us/library/abx4dbyh.aspx) and has no dependencies.\n\n\n# Installation\n\n`$ pip install teletype`\n\n\n# I/O Utilities (teletype.io)\n\n## Reading Key Strokes\n\nYou can read keystrokes from stdin using `get_key`. Regular keys get returned as a string with a single character, e.g. `\"a\"`, `\"1\"`, `\"&\"`, etc., while special keys and key combinations are returned as a string description, e.g. `\"space\"`, `\"f12\"`, `\"page-up\"`, `\"ctrl-c\"`, etc. A listing of the supported key combinations are listed in the [`codes`](https://github.com/jkwill87/teletype/blob/master/teletype/codes/common.py) module.\n\n```python\nfrom teletype.io import get_key\n\nprint(\"Delete C:/ Drive? [y/n]\")\nselection = \"\"\nwhile selection.lower() not in (\"y\", \"n\"):\n selection = get_key()\n if selection in (\"ctrl-c\", \"ctrl-z\", \"escape\"):\n selection = \"n\"\nif selection == \"y\":\n print(\"Deleting C:/ drive...\")\n delete_c_drive()\nelse:\n print(\"Leaving C:/ drive alone\")\n```\n\n## Styling Output\n\nYou can style strings with COLOURS and effects using `style_format`. Styles can be passed in either as a space delimited string or in a collection (e.g. a tuple, set, list, etc.). The passed `text` string is then wrapped in the appropriate ASCII escape sequences and returned. When `print`ed the appropriate styles will be applied.\n\nAlternatively you can you just pass these same parameters to `style_print` and accomplish this in one fell swoop. `style_print` takes the same parameters as the regular print function and can be used in place. In python3 you can even import style_print as print and use it in place. In order to pull this compatibility off for python2, the `style` argument must be specified explitly when calling, however, e.g. `style_print(\"yolo\", style=\"yellow\")`.\n\nLastly, you can use `strip_format` to clear a string of any escape sequences that have been previously applied.\n\n```python\nfrom teletype.io import style_format, style_print, strip_format\n\n\n# All of these will do the same thing, that is print the message in red and bold\nprint(style_format(\"I want to stand out!\", \"bold red\"))\nprint(style_format(\"I want to stand out!\", (\"red\", \"bold\")))\nstyle_print(\"I want to stand out!\", style=[\"red\", \"bold\"])\n\n\n# Styles are cleared afterwards so everything else gets printed normally\nprint(\"I want to be boring\")\n\n\n# If for whatever reason you want to unstyle text, thats a thing too\ntext = style_format(\"I don't actually want too be styled\", (\"red\", \"bold\"))\nprint(strip_format(text))\n```\n\n## Cursor manipulation\n\nThe package includes quite a few helper functions to move the CURSOR around the screen. These include `erase_lines`, `erase_screen`, `hide_cursor`, `show_cursor`, and `move_cursor`; all of which are fairly self explanitory. The only word of caution is to remember to reset CURSOR visibility as its state will persist after the python interpreter has exited.\n\n\n# Components (teletype.components)\n\nThe package also includes components, higher level UI classes that are composed from the I/O functions and can be easily incorporated to any CLI application.\n\n## SelectOne\n\n```python\nIn [1]: from teletype.components import SelectOne\n ...:\n ...: picker = SelectOne(choices=[\"dog\", \"bird\", \"cat\", \"monkey\", \"gorilla\"])\n ...: print(\"Your Favourite Animal?\")\n ...: choice = picker.prompt()\n ...: print(\"Your choice: \" + choice)\n```\n\n```\nYour Favourite Animal?\n \u2771 dog\n bird\n cat\n monkey\n gorilla\nYour choice: dog\n```\n\n## SelectMany\n\n```python\nIn [2]: from teletype.components import SelectMany\n ...:\n ...: picker = SelectMany(choices=[\"dog\", \"bird\", \"cat\", \"monkey\", \"gorilla\"])\n ...: print(\"Your Favourite Animals?\")\n ...: choices = picker.prompt()\n ...: print(\"Your choices: \" + \", \".join(choices))\n```\n\n```\nYour Favourite Animals?\n\u2771\u25cf dog\n \u25cb bird\n \u25cb cat\n \u25cb monkey\n \u25cb gorilla\nYour choices: dog\n```\n\n## ProgressBar\n\n```python\nIn [3]: from time import sleep\n ...: from teletype.components import ProgressBar\n ...:\n ...: iterations = 15\n ...:\n ...: def iterable():\n ...: for _ in range(iterations):\n ...: sleep(0.2)\n ...: yield\n ...:\n ...: ProgressBar(\"Progress Bar\").process(iterable(), iterations)\n```\n\n```\nProgress Bar: 15/15\u2590\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u258c100%\n```\n\n## ChoiceHelper\n\nAlthough not a component in and of itself, `ChoiceHelper` can help you wrap your objects to make full use of components like `SelectOne`, `SelectMany`, or `SelectApproval`. This is completely optional-- normally these just use the string representations of objects for display, e.g. just printing options which are strings or calling their underlying `__str__` methods.\n\n### Seperate Values from Labels\n\nSometimes this isn't an option or you might want to seperate the label of an object from its value. `ChoiceHelper` lets you specifiy these fields explicitly. You can apply styles, too.\n\n```python\nIn [4]: from teletype.components import SelectOne, ChoiceHelper\n ...:\n ...: choices = [\n ...: ChoiceHelper([\"corgi\", \"greyhound\", \"bulldog\"], label=\"dog\", style=\"blue\"),\n ...: ChoiceHelper([\"siamese\", \"chartreux\", \"ragdoll\"], label=\"cat\", style=\"red\"),\n ...: ChoiceHelper([\"zebra\", \"beta\", \"gold\"], \"fish\", style=\"green\")\n ...: ]\n ...:\n ...: print(\"favourite pet\")\n ...: pet = SelectOne(choices).prompt()\n ...:\n ...: print(\"favourite breed\")\n ...: breed = SelectOne(pet).prompt()\n```\n\n```\nfavourite pet\n \u2771 dog\n cat\n fish\n\nfavourite breed\n \u2771 corgi\n greyhound\n bulldog\n```\n\n### Mnemonics\n\nAnother cool thing that `ChoiceHelper`s let you do is use mneumonics. These can be specified either using a single character, in which case they are underlined, or as a single character wrapped in square brackets, in which case they will be indicated using square brackets (e.g. for compatibility with dumb terminals).\n\nThis is used under the hood for `SelectApproval` to quickly select yes by pressing `y` and no by pressing `n`.\n\n## Styling Components (teletype.components.config)\n\nYou can set component styles using `io.style_format`.\n\n```python\nfrom teletype.io import style_format, style_print\nfrom teletype.components import ProgressBar, SelectMany\n\nstyle = \"red bold\"\narrow = io.style_format(CHARS_DEFAULT[\"arrow\"], style)\nchoices = [\"dogs\", \"cats\", \"fish\"]\n\nio.style_print(\"\\nSelect One\", style=style)\nSelectOne(choices, arrow=arrow).prompt()\n```\n\nYou can also change character sets using `set_char(key, value)` where value is the unicode character you want to use and key is one of:\n\n- `arrow`\n- `block`\n- `left-edge`\n- `right-edge`\n- `selected`\n- `unselected`\n\n\n# License\n\nMIT. See license.txt for details.\n\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/jkwill87/teletype", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "teletype", "package_url": "https://pypi.org/project/teletype/", "platform": "", "project_url": "https://pypi.org/project/teletype/", "project_urls": { "Homepage": "https://github.com/jkwill87/teletype" }, "release_url": "https://pypi.org/project/teletype/1.0.4/", "requires_dist": null, "requires_python": "", "summary": "A high-level cross platform tty library", "version": "1.0.4" }, "last_serial": 5932862, "releases": { "0.2.2": [ { "comment_text": "", "digests": { "md5": "cfb4569aeb14b2639b5ab06c46e9036b", "sha256": "2b33a1f082bcbd01be7dd5b4a5b13b1ffb28463aeebc36ee5b21925cfdd4734a" }, "downloads": -1, "filename": "teletype-0.2.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "cfb4569aeb14b2639b5ab06c46e9036b", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 12223, "upload_time": "2019-04-26T03:45:48", "url": "https://files.pythonhosted.org/packages/f8/00/53d9bb8dfc85df16200606f56666c69805b1e10e9c7de7fe537cc46fc754/teletype-0.2.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "76a46a85698782f8c156260ec1c97052", "sha256": "d1e34ea0152ffeeb4dc33579b027a2660bb58698c1b6a5dc622207fcfbe9746e" }, "downloads": -1, "filename": "teletype-0.2.2.tar.gz", "has_sig": false, "md5_digest": "76a46a85698782f8c156260ec1c97052", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10474, "upload_time": "2019-04-26T03:42:42", "url": "https://files.pythonhosted.org/packages/3f/95/3c04fc086826dc042e134dd26372e69ad037edec1ae4e09bd93c7e11e67c/teletype-0.2.2.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "aefdf016767e7023aac164ccd41f6a9e", "sha256": "29b0329ed105b4c6e23206990cfba3c4346582ed33968e6c418c270e1b4216f6" }, "downloads": -1, "filename": "teletype-0.3.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "aefdf016767e7023aac164ccd41f6a9e", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 10899, "upload_time": "2019-05-22T19:03:00", "url": "https://files.pythonhosted.org/packages/98/e1/06077ec0eedfc28023fea825022166549c44a90b8e6f456649962b2b8fd3/teletype-0.3.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "4b89072732cf4d1a1b25f2a69532f7eb", "sha256": "75bdadcbe8d0b436b1b5dac84286db297e08a2b285855ec9e78de03e746ee4f9" }, "downloads": -1, "filename": "teletype-0.3.1.tar.gz", "has_sig": false, "md5_digest": "4b89072732cf4d1a1b25f2a69532f7eb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10479, "upload_time": "2019-05-22T19:03:02", "url": "https://files.pythonhosted.org/packages/93/6b/33f55733266275012ced267e0ad3b53afb26c288ababde773bc8dc0a4b4c/teletype-0.3.1.tar.gz" } ], "1.0.0": [ { "comment_text": "", "digests": { "md5": "e18ba68a762e338f67cf0cd274d771db", "sha256": "9f9895b1988c73cad94308f0894f286d49e8c0767c2fc7a126e4a4a3de47e3d2" }, "downloads": -1, "filename": "teletype-1.0.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "e18ba68a762e338f67cf0cd274d771db", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 13157, "upload_time": "2019-06-22T20:27:40", "url": "https://files.pythonhosted.org/packages/2c/9a/a2c4a43ba755a9af4066ea4644e4328498bb551815125279696129fcf92c/teletype-1.0.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8e05d31c533e2780cb78919cf88cbf52", "sha256": "5be4d921f9bb30d515af666497826ff7669bb6cf428acc32a00b50b7ca42d2ce" }, "downloads": -1, "filename": "teletype-1.0.0.tar.gz", "has_sig": false, "md5_digest": "8e05d31c533e2780cb78919cf88cbf52", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13174, "upload_time": "2019-06-22T20:27:41", "url": "https://files.pythonhosted.org/packages/b2/1b/5c62c150ca73b42917fa7ba029cc2dcf852172d840ad4dc3885c61cddba4/teletype-1.0.0.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "9a3c9a026120207ecfb985fb9d9f5182", "sha256": "8e9a87a651e60b3f10930b108dc318c03abd8496741fa0426216fdbeb0596d7e" }, "downloads": -1, "filename": "teletype-1.0.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "9a3c9a026120207ecfb985fb9d9f5182", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 13431, "upload_time": "2019-09-18T03:11:37", "url": "https://files.pythonhosted.org/packages/6f/ff/887e3c489fc7a50f45807e5adde8cdd97cb6ecc44dfd3b1eb2f842cc1127/teletype-1.0.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "01105e510165ef3cca2217e7c6828a02", "sha256": "f76e160719edaeaa4f8ff5437d3681275da9959fab315df03f1e3d6b32c9557b" }, "downloads": -1, "filename": "teletype-1.0.2.tar.gz", "has_sig": false, "md5_digest": "01105e510165ef3cca2217e7c6828a02", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14767, "upload_time": "2019-09-18T03:11:39", "url": "https://files.pythonhosted.org/packages/eb/c3/31e34f74069233f629f2304445fdf71b57f6efe1156a528a80f14321e20e/teletype-1.0.2.tar.gz" } ], "1.0.3": [ { "comment_text": "", "digests": { "md5": "90fb11e3372c4b4f2e380da9f0b8b33e", "sha256": "8ed9fd274df8397185244f8023fbf31c83f2e0878d59072714877d44edd55dba" }, "downloads": -1, "filename": "teletype-1.0.3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "90fb11e3372c4b4f2e380da9f0b8b33e", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 13429, "upload_time": "2019-09-18T03:38:40", "url": "https://files.pythonhosted.org/packages/fb/36/d6dbeb4fb985f82b69a7a3451d3f9aad52912e9b7a51190f7b518a8d9624/teletype-1.0.3-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "34da211d77690a38217b7ef067638dfb", "sha256": "5a805cb72fda5a8494aa83cf1381721d23145231d3de9c524849784a51e38baa" }, "downloads": -1, "filename": "teletype-1.0.3.tar.gz", "has_sig": false, "md5_digest": "34da211d77690a38217b7ef067638dfb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14761, "upload_time": "2019-09-18T03:38:42", "url": "https://files.pythonhosted.org/packages/df/3f/fdc8da69106e222009186473f30b3a0d4dbe80d9047d6957aa460928f4e7/teletype-1.0.3.tar.gz" } ], "1.0.4": [ { "comment_text": "", "digests": { "md5": "f97ea0a2d7fbda64098df32f256384c1", "sha256": "22abab5a2d77abc7d78ff3b1b0db3af3b77d6cf263090ec26d7aeff887f0ef33" }, "downloads": -1, "filename": "teletype-1.0.4-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "f97ea0a2d7fbda64098df32f256384c1", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 13437, "upload_time": "2019-10-05T19:03:05", "url": "https://files.pythonhosted.org/packages/31/ce/b5ad4a8dcc5b0d94c69399b085fd512fc199be5f555627e1368381f8135d/teletype-1.0.4-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "06579e42527f650d6398d4878cbfdba4", "sha256": "b4432cceb3dcdc14bf253ea2ed89b1237ec6860a6428d674a01691679e58151d" }, "downloads": -1, "filename": "teletype-1.0.4.tar.gz", "has_sig": false, "md5_digest": "06579e42527f650d6398d4878cbfdba4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14779, "upload_time": "2019-10-05T19:03:07", "url": "https://files.pythonhosted.org/packages/7f/9d/91222889ecf831e003f7eef5f3ebe81c35f3335357e13c1ea1d070c9768b/teletype-1.0.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "f97ea0a2d7fbda64098df32f256384c1", "sha256": "22abab5a2d77abc7d78ff3b1b0db3af3b77d6cf263090ec26d7aeff887f0ef33" }, "downloads": -1, "filename": "teletype-1.0.4-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "f97ea0a2d7fbda64098df32f256384c1", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 13437, "upload_time": "2019-10-05T19:03:05", "url": "https://files.pythonhosted.org/packages/31/ce/b5ad4a8dcc5b0d94c69399b085fd512fc199be5f555627e1368381f8135d/teletype-1.0.4-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "06579e42527f650d6398d4878cbfdba4", "sha256": "b4432cceb3dcdc14bf253ea2ed89b1237ec6860a6428d674a01691679e58151d" }, "downloads": -1, "filename": "teletype-1.0.4.tar.gz", "has_sig": false, "md5_digest": "06579e42527f650d6398d4878cbfdba4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14779, "upload_time": "2019-10-05T19:03:07", "url": "https://files.pythonhosted.org/packages/7f/9d/91222889ecf831e003f7eef5f3ebe81c35f3335357e13c1ea1d070c9768b/teletype-1.0.4.tar.gz" } ] }