Skip to content

Commit 33ae2e8

Browse files
committed
docs: switch from rst to markdown
1 parent 3d89fdf commit 33ae2e8

File tree

3 files changed

+118
-159
lines changed

3 files changed

+118
-159
lines changed

README.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
[![GitHub Repository](https://badges.aleen42.com/src/github.svg)](https://github.com/magmax/python-readchar)
2+
[![Latest PyPI version](https://img.shields.io/pypi/v/readchar.svg)](https://pypi.python.org/pypi/readchar)
3+
[![supported Python versions](https://img.shields.io/pypi/pyversions/readchar)](https://pypi.python.org/pypi/readchar)
4+
[![Project licence](https://img.shields.io/pypi/l/readchar?color=blue)](LICENCE) \
5+
[![Automated testing results](https://github.com/magmax/python-readchar/actions/workflows/run-tests.yaml/badge.svg?branch=master)](https://github.com/magmax/python-readchar/actions/workflows/run-tests.yaml?query=branch%3Amaster)
6+
[![Coveralls results](https://coveralls.io/repos/github/magmax/python-readchar/badge.svg?branch=master)](https://coveralls.io/github/magmax/python-readchar?branch=master)
7+
[![Number of PyPI downloads](https://img.shields.io/pypi/dd/readchar.svg)](https://pypi.python.org/pypi/readchar)
8+
9+
# python-readchar
10+
11+
Library to easily read single chars and keystrokes.
12+
13+
Born as a [python-inquirer](https://github.com/magmax/python-inquirer) requirement.
14+
15+
16+
## Installation
17+
18+
simply install it via `pip`:
19+
20+
```bash
21+
pip install readchar
22+
```
23+
24+
Or download the source code from [PyPi](https://pypi.python.org/pypi/readchar).
25+
26+
27+
## Usage
28+
29+
Simply read a character or keystroke:
30+
31+
```python
32+
import readchar
33+
34+
key = readchar.readkey()
35+
```
36+
37+
React to different kinds of keypresses:
38+
39+
```python
40+
from readchar import readkey, key
41+
42+
while True:
43+
k = readkey()
44+
if k == "a":
45+
# do stuff
46+
if k == key.DOWN:
47+
# do stuff
48+
if k == key.ENTER:
49+
break
50+
```
51+
52+
53+
## API
54+
55+
There are just two methods:
56+
57+
### `readchar() -> str`
58+
59+
Reads one character from `stdin`, returning it as a string with length 1. Waits until a character is available.
60+
61+
As only ASCII characters are actually a single character, you usually want to use the next function, that also handles longer keys.
62+
63+
### `readkey() -> str`
64+
65+
Reads the next keystroke from `stdin`, returning it as a string. Waits
66+
until a keystroke is available.
67+
68+
A keystroke can be:
69+
70+
- single characters as returned by `readchar()`. These include:
71+
- character for normal keys: 'a', 'Z', '9',...
72+
- special characters like 'ENTER', 'BACKSPACE', 'TAB',...
73+
- combinations with 'CTRL': 'CTRL'+'A',...
74+
- keys that are made up of multiple characters:
75+
- characters for cursors/arrows: 🡩, 🡪, 🡫, 🡨
76+
- navigation keys: 'INSERT', 'HOME',...
77+
- function keys: 'F1' to 'F12'
78+
- combinations with 'ALT': 'ALT'+'A',...
79+
- combinations with 'CTRL' and 'ALT': 'CTRL'+'ALT'+'SUPR',...
80+
81+
> **Note**
82+
> 'CTRL'+'C' will not be returned by `readkey()`, but instead raise a `KeyboardInterupt`. If you what to handle it yourself, use `readchar()`.
83+
84+
### `readchar.key` module
85+
86+
This submodule contains a list of available keys to compare against. The constants are defined depending on your operating system, so it should be
87+
fully portable. If a key is listed here for your platform, `readkey()` can read it, and you can compare against it.
88+
89+
90+
## OS Support
91+
92+
This library actively supports these operating systems:
93+
94+
- Linux
95+
- Windows
96+
97+
Some operating systems are enabled, but not actively tested or supported:
98+
99+
- macOS
100+
- FreeBSD
101+
102+
Theoretically every Unix based system should work, but they will not be actively tested. It is also required that somebody provides initial test
103+
results before the OS is enabled and added to the list. Feel free to open a PR for that.
104+
105+
Thank you!
106+
107+
108+
## How to contribute
109+
110+
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
111+
request, but first, please read our [contribution guidelines](https://github.com/magmax/python-readchar/blob/master/CONTRIBUTING.md). They will also
112+
tell you how to write code for this repo and how to properly prepare an issue or a pull request.
113+
114+
-----
115+
116+
*Copyright (c) 2014-2022 Miguel Ángel García*

README.rst

Lines changed: 0 additions & 157 deletions
This file was deleted.

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
name = readchar
33
version = attr: readchar.__version__
44
description = Library to easily read single chars and key strokes
5-
long_description = file: README.rst
6-
long_description_content_type = text/x-rst
5+
long_description = file: README.md
6+
long_description_content_type = text/markdown
77
url = https://github.com/magmax/python-readchar
88
author_email = [email protected]
99
license = MIT

0 commit comments

Comments
 (0)