Skip to content

Commit

Permalink
Merge d3f6991 into b7d554c
Browse files Browse the repository at this point in the history
  • Loading branch information
Cube707 committed Aug 16, 2022
2 parents b7d554c + d3f6991 commit 42b249f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
15 changes: 15 additions & 0 deletions README.md
Expand Up @@ -86,6 +86,21 @@ A keystroke can be:
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 class contains configurations for `readchar`. It holds constants that are used in other parts of the code. 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

Expand Down
4 changes: 3 additions & 1 deletion readchar/__init__.py
@@ -1,10 +1,12 @@
"""Library to easily read single chars and key strokes"""

__version__ = "4.0.2-dev0"
__all__ = ["readchar", "readkey", "key"]
__all__ = ["readchar", "readkey", "key", "config"]

from sys import platform

from ._config import config


if platform.startswith(("linux", "darwin", "freebsd")):
from . import _posix_key as key
Expand Down
7 changes: 7 additions & 0 deletions readchar/_config.py
@@ -0,0 +1,7 @@
from typing import List

from . import _base_key as key


class config:
INTERRUPT_KEYS: List[str] = [key.CTRL_C]
4 changes: 3 additions & 1 deletion readchar/_posix_read.py
@@ -1,6 +1,8 @@
import sys
import termios

from ._config import config


# Initially taken from:
# http://code.activestate.com/recipes/134892/
Expand Down Expand Up @@ -31,7 +33,7 @@ def readkey() -> str:

c1 = readchar()

if c1 == "\x03":
if c1 in config.INTERRUPT_KEYS:
raise KeyboardInterrupt

if c1 != "\x1B":
Expand Down
4 changes: 3 additions & 1 deletion readchar/_win_read.py
@@ -1,5 +1,7 @@
import msvcrt

from ._config import config


def readchar() -> str:
"""Reads a single character from the input stream.
Expand All @@ -15,7 +17,7 @@ def readkey() -> str:

ch = readchar()

if ch == "\x03":
if ch in config.INTERRUPT_KEYS:
raise KeyboardInterrupt

# if it is a normal character:
Expand Down

0 comments on commit 42b249f

Please sign in to comment.