readchar


Namereadchar JSON
Version 4.2.1 PyPI version JSON
download
home_pageNone
SummaryLibrary to easily read single chars and key strokes
upload_time2024-11-04 18:28:07
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT Licence Copyright (c) 2022 Miguel Angel Garcia Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords characters keystrokes stdin command line
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            [![GitHub Repository](https://img.shields.io/badge/-GitHub-%230D0D0D?logo=github&labelColor=gray)](https://github.com/magmax/python-readchar)
[![Latest PyPi version](https://img.shields.io/pypi/v/readchar.svg)](https://pypi.python.org/pypi/readchar)
[![supported Python versions](https://img.shields.io/pypi/pyversions/readchar)](https://pypi.python.org/pypi/readchar)
[![Project licence](https://img.shields.io/pypi/l/readchar?color=blue)](LICENCE) <br>
[![Automated testing results](https://img.shields.io/github/actions/workflow/status/magmax/python-readchar/run-tests.yaml?branch=master)](https://github.com/magmax/python-readchar/actions/workflows/run-tests.yaml?query=branch%3Amaster)
[![Coveralls results](https://coveralls.io/repos/github/magmax/python-readchar/badge.svg?branch=master)](https://coveralls.io/github/magmax/python-readchar?branch=master)
[![Number of PyPi downloads](https://img.shields.io/pypi/dd/readchar.svg)](https://pypi.python.org/pypi/readchar)

# python-readchar

Library to easily read single chars and keystrokes.

Born as a [python-inquirer](https://github.com/magmax/python-inquirer) requirement.

## Installation

simply install it via `pip`:

```bash
pip install readchar
```

Or download the source code from [PyPi](https://pypi.python.org/pypi/readchar).

## Usage

Simply read a character or keystroke:

```python
import readchar

key = readchar.readkey()
```

React to different kinds of key-presses:

```python
from readchar import readkey, key

while True:
  k = readkey()
  if k == "a":
    # do stuff
  if k == key.DOWN:
    # do stuff
  if k == key.ENTER:
    break
```

## Documentation

There are just two methods:

### `readchar.readchar() -> str`

Reads one character from `stdin`, returning it as a string with length 1. Waits until a
character is available.

As only ASCII characters are actually a single character, you usually want to use the
next function, that also handles longer keys.

### `readchar.readkey() -> str`

Reads the next keystroke from `stdin`, returning it as a string. Waits until a keystroke
is available.

A keystroke can be:

- single characters as returned by `readchar()`. These include:
  - character for normal keys: <kbd>a</kbd>, <kbd>Z</kbd>, <kbd>9</kbd>,...
  - special characters like <kbd>ENTER</kbd>, <kbd>BACKSPACE</kbd>, <kbd>TAB</kbd>,...
  - combinations with <kbd>CTRL</kbd>: <kbd>CTRL</kbd>+<kbd>A</kbd>,...
- keys that are made up of multiple characters:
  - characters for cursors/arrows: <kbd>🡩</kbd>, <kbd>🡪</kbd>, <kbd>🡫</kbd>,
    <kbd>🡨</kbd>
  - navigation keys: <kbd>INSERT</kbd>, <kbd>HOME</kbd>,...
  - function keys: <kbd>F1</kbd> to <kbd>F12</kbd>
  - combinations with <kbd>ALT</kbd>: <kbd>ALT</kbd>+<kbd>A</kbd>,...
  - combinations with <kbd>CTRL</kbd> and <kbd>ALT</kbd>:
    <kbd>CTRL</kbd>+<kbd>ALT</kbd>+<kbd>SUPR</kbd>,...

> **Note** <kbd>CTRL</kbd>+<kbd>C</kbd> will not be returned by `readkey()`, but instead
> raise a `KeyboardInterupt`. If you want to handle it yourself, use `readchar()`.

### `readchar.key` module

This submodule contains a list of available keys to compare against. The constants are
defined depending on your operating system, so it should be fully portable. If a key is
listed here for your platform, `readkey()` can read it, and you can compare against it.

### `readchar.config` class

This static class contains configurations for `readchar`. It holds constants that are
used in other parts of the code as class attributes. You can override/change these to
modify its behaviour. Here is a description of the existing attributes:

<dl>
<dt><code>INTERRUPT_KEYS</code></dt>
<dd>

List of keys that will result in `readkey()` raising a `KeyboardInterrupt`. <br>
*Default:* `[key.CTRL_C]`

</dd>
</dl>

## OS Support

This library actively supports these operating systems:

- Linux
- Windows

Some operating systems are enabled, but not actively tested or supported:

- macOS
- FreeBSD / OpenBSD

Theoretically every Unix based system should work, but they will not be actively tested.
It is also required that somebody provides initial test results before the OS is enabled
and added to the list. Feel free to open a PR for that.

Thank you!

## How to contribute

You have an issue problem or found a bug? You have a great new idea or just want to fix
a typo? Great :+1:. We are happy to accept your issue or pull request, but first, please
read our
[contribution guidelines](https://github.com/magmax/python-readchar/blob/master/CONTRIBUTING.md).
They will also tell you how to write code for this repo and how to properly prepare an
issue or a pull request.

______________________________________________________________________

*Copyright (c) 2014-2022 Miguel Ángel García*

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "readchar",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "Jan Wille <mail@janwille.de>",
    "keywords": "characters, keystrokes, stdin, command line",
    "author": null,
    "author_email": "Miguel \u00c1ngel Garc\u00eda <miguelangel.garcia@gmail.com>, Jan Wille <mail@janwille.de>",
    "download_url": "https://files.pythonhosted.org/packages/dd/f8/8657b8cbb4ebeabfbdf991ac40eca8a1d1bd012011bd44ad1ed10f5cb494/readchar-4.2.1.tar.gz",
    "platform": null,
    "description": "[![GitHub Repository](https://img.shields.io/badge/-GitHub-%230D0D0D?logo=github&labelColor=gray)](https://github.com/magmax/python-readchar)\n[![Latest PyPi version](https://img.shields.io/pypi/v/readchar.svg)](https://pypi.python.org/pypi/readchar)\n[![supported Python versions](https://img.shields.io/pypi/pyversions/readchar)](https://pypi.python.org/pypi/readchar)\n[![Project licence](https://img.shields.io/pypi/l/readchar?color=blue)](LICENCE) <br>\n[![Automated testing results](https://img.shields.io/github/actions/workflow/status/magmax/python-readchar/run-tests.yaml?branch=master)](https://github.com/magmax/python-readchar/actions/workflows/run-tests.yaml?query=branch%3Amaster)\n[![Coveralls results](https://coveralls.io/repos/github/magmax/python-readchar/badge.svg?branch=master)](https://coveralls.io/github/magmax/python-readchar?branch=master)\n[![Number of PyPi downloads](https://img.shields.io/pypi/dd/readchar.svg)](https://pypi.python.org/pypi/readchar)\n\n# python-readchar\n\nLibrary to easily read single chars and keystrokes.\n\nBorn as a [python-inquirer](https://github.com/magmax/python-inquirer) requirement.\n\n## Installation\n\nsimply install it via `pip`:\n\n```bash\npip install readchar\n```\n\nOr download the source code from [PyPi](https://pypi.python.org/pypi/readchar).\n\n## Usage\n\nSimply read a character or keystroke:\n\n```python\nimport readchar\n\nkey = readchar.readkey()\n```\n\nReact to different kinds of key-presses:\n\n```python\nfrom readchar import readkey, key\n\nwhile True:\n  k = readkey()\n  if k == \"a\":\n    # do stuff\n  if k == key.DOWN:\n    # do stuff\n  if k == key.ENTER:\n    break\n```\n\n## Documentation\n\nThere are just two methods:\n\n### `readchar.readchar() -> str`\n\nReads one character from `stdin`, returning it as a string with length 1. Waits until a\ncharacter is available.\n\nAs only ASCII characters are actually a single character, you usually want to use the\nnext function, that also handles longer keys.\n\n### `readchar.readkey() -> str`\n\nReads the next keystroke from `stdin`, returning it as a string. Waits until a keystroke\nis available.\n\nA keystroke can be:\n\n- single characters as returned by `readchar()`. These include:\n  - character for normal keys: <kbd>a</kbd>, <kbd>Z</kbd>, <kbd>9</kbd>,...\n  - special characters like <kbd>ENTER</kbd>, <kbd>BACKSPACE</kbd>, <kbd>TAB</kbd>,...\n  - combinations with <kbd>CTRL</kbd>: <kbd>CTRL</kbd>+<kbd>A</kbd>,...\n- keys that are made up of multiple characters:\n  - characters for cursors/arrows: <kbd>\ud83e\udc69</kbd>, <kbd>\ud83e\udc6a</kbd>, <kbd>\ud83e\udc6b</kbd>,\n    <kbd>\ud83e\udc68</kbd>\n  - navigation keys: <kbd>INSERT</kbd>, <kbd>HOME</kbd>,...\n  - function keys: <kbd>F1</kbd> to <kbd>F12</kbd>\n  - combinations with <kbd>ALT</kbd>: <kbd>ALT</kbd>+<kbd>A</kbd>,...\n  - combinations with <kbd>CTRL</kbd> and <kbd>ALT</kbd>:\n    <kbd>CTRL</kbd>+<kbd>ALT</kbd>+<kbd>SUPR</kbd>,...\n\n> **Note** <kbd>CTRL</kbd>+<kbd>C</kbd> will not be returned by `readkey()`, but instead\n> raise a `KeyboardInterupt`. If you want to handle it yourself, use `readchar()`.\n\n### `readchar.key` module\n\nThis submodule contains a list of available keys to compare against. The constants are\ndefined depending on your operating system, so it should be fully portable. If a key is\nlisted here for your platform, `readkey()` can read it, and you can compare against it.\n\n### `readchar.config` class\n\nThis static class contains configurations for `readchar`. It holds constants that are\nused in other parts of the code as class attributes. You can override/change these to\nmodify its behaviour. Here is a description of the existing attributes:\n\n<dl>\n<dt><code>INTERRUPT_KEYS</code></dt>\n<dd>\n\nList of keys that will result in `readkey()` raising a `KeyboardInterrupt`. <br>\n*Default:* `[key.CTRL_C]`\n\n</dd>\n</dl>\n\n## OS Support\n\nThis library actively supports these operating systems:\n\n- Linux\n- Windows\n\nSome operating systems are enabled, but not actively tested or supported:\n\n- macOS\n- FreeBSD / OpenBSD\n\nTheoretically every Unix based system should work, but they will not be actively tested.\nIt is also required that somebody provides initial test results before the OS is enabled\nand added to the list. Feel free to open a PR for that.\n\nThank you!\n\n## How to contribute\n\nYou have an issue problem or found a bug? You have a great new idea or just want to fix\na typo? Great :+1:. We are happy to accept your issue or pull request, but first, please\nread our\n[contribution guidelines](https://github.com/magmax/python-readchar/blob/master/CONTRIBUTING.md).\nThey will also tell you how to write code for this repo and how to properly prepare an\nissue or a pull request.\n\n______________________________________________________________________\n\n*Copyright (c) 2014-2022 Miguel \u00c1ngel Garc\u00eda*\n",
    "bugtrack_url": null,
    "license": "MIT Licence  Copyright (c) 2022 Miguel Angel Garcia  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Library to easily read single chars and key strokes",
    "version": "4.2.1",
    "project_urls": {
        "Changelog": "https://github.com/magmax/python-readchar/releases",
        "Homepage": "https://pypi.org/project/readchar",
        "Issues": "https://github.com/magmax/python-readchar/issues",
        "Repository": "https://github.com/magmax/python-readchar"
    },
    "split_keywords": [
        "characters",
        " keystrokes",
        " stdin",
        " command line"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a910e4b1e0e5b6b6745c8098c275b69bc9d73e9542d5c7da4f137542b499ed44",
                "md5": "deacc991ada59926e4107dc570ed1003",
                "sha256": "a769305cd3994bb5fa2764aa4073452dc105a4ec39068ffe6efd3c20c60acc77"
            },
            "downloads": -1,
            "filename": "readchar-4.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "deacc991ada59926e4107dc570ed1003",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 9350,
            "upload_time": "2024-11-04T18:28:02",
            "upload_time_iso_8601": "2024-11-04T18:28:02.859763Z",
            "url": "https://files.pythonhosted.org/packages/a9/10/e4b1e0e5b6b6745c8098c275b69bc9d73e9542d5c7da4f137542b499ed44/readchar-4.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ddf88657b8cbb4ebeabfbdf991ac40eca8a1d1bd012011bd44ad1ed10f5cb494",
                "md5": "80d620844bf9dc76424a0bc4d46caf92",
                "sha256": "91ce3faf07688de14d800592951e5575e9c7a3213738ed01d394dcc949b79adb"
            },
            "downloads": -1,
            "filename": "readchar-4.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "80d620844bf9dc76424a0bc4d46caf92",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 9685,
            "upload_time": "2024-11-04T18:28:07",
            "upload_time_iso_8601": "2024-11-04T18:28:07.757862Z",
            "url": "https://files.pythonhosted.org/packages/dd/f8/8657b8cbb4ebeabfbdf991ac40eca8a1d1bd012011bd44ad1ed10f5cb494/readchar-4.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-04 18:28:07",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "magmax",
    "github_project": "python-readchar",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [],
    "lcname": "readchar"
}
        
Elapsed time: 0.53132s