No project description provided
Project description
terminable
Python library for cross-platform terminal input.
Install
python3 -m pip install terminable
Usage
import terminable
with terminable.capture_input() as terminal_input:
while True:
returned_value = terminal_input.read()
print(f"Input received: {returned_value}\r")
Sample output:
Input received: KeyEvent(Char(a), KeyModifiers.NONE)
Input received: KeyEvent(Char(s), KeyModifiers.NONE)
Input received: KeyEvent(Char(A), KeyModifiers.SHIFT)
Input received: KeyEvent(Char(S), KeyModifiers.SHIFT)
Input received: KeyEvent(Char(F), KeyModifiers.SHIFT)
Input received: KeyEvent(Key.F1, KeyModifiers.NONE)
Input received: KeyEvent(Key.F3, KeyModifiers.NONE)
Input received: KeyEvent(Key.F2, KeyModifiers.NONE)
Input received: KeyEvent(Char(l), KeyModifiers.CONTROL)
Input received: KeyEvent(Char(k), KeyModifiers.CONTROL)
Input received: KeyEvent(Char(p), KeyModifiers.CONTROL)
Input received: MouseEvent(MouseEventKind.MOVED, None, 54, 20, KeyModifiers.NONE)
Input received: MouseEvent(MouseEventKind.MOVED, None, 53, 20, KeyModifiers.NONE)
Input received: MouseEvent(MouseEventKind.MOVED, None, 52, 20, KeyModifiers.NONE)
Input received: MouseEvent(MouseEventKind.MOVED, None, 51, 20, KeyModifiers.NONE)
Input received: MouseEvent(MouseEventKind.MOVED, None, 54, 19, KeyModifiers.NONE)
Input received: MouseEvent(MouseEventKind.SCROLL_DOWN, None, 54, 19, KeyModifiers.NONE)
Input received: MouseEvent(MouseEventKind.SCROLL_DOWN, None, 54, 19, KeyModifiers.NONE)
Input received: MouseEvent(MouseEventKind.SCROLL_DOWN, None, 54, 19, KeyModifiers.NONE)
Input received: MouseEvent(MouseEventKind.SCROLL_DOWN, None, 54, 19, KeyModifiers.NONE)
Input received: ResizeEvent(104, 31)
Input received: ResizeEvent(100, 31)
Input received: ResizeEvent(98, 31)
Input received: ResizeEvent(95, 31)
Types of input
- Keyboard
- Characters
- Arrow keys
- Function keys
- Enter, Esc, Backspace, etc.
- Modifiers:
CONTROL
,SHIFT
,ALT
, etc.
- Mouse
- Move
- Down
- Up
- Drag
- Terminal resize
Implementation
terminable
is a thin Python wrapper around the excellent crossterm Rust library.
API
capture_input
terminable
has a single function:
def capture_input() -> InputCapture:
...
InputCapture
The InputCapture
object is a context manager object (intended to be used with Python's with
statement).
When the InputCapture
object is created, the terminal is placed into raw mode, such that:
- Input is not automatically echoed
print
calls do not automatically add a carriage return (\r
)- Control sequences are not automatically processed
When the InputCapture
object is destroyed, the terminal exits raw mode.
read
InputCapture
has a single function:
def read(self) -> KeyEvent | MouseEvent | ResizeEvent :
...
read
blocks until input is received.
Ctrl+C
terminable
raises a KeyboardInterrupt
exception on Ctrl+C
.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
terminable-0.1.0.tar.gz
(8.2 kB
view hashes)
Built Distributions
Close
Hashes for terminable-0.1.0-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b57b24e9e6c97fd6ef8e755d1525f1aa21404349c957751bf7ef5d1605989b6 |
|
MD5 | b6e3fc1b7ee03a2364001014ddfabc05 |
|
BLAKE2b-256 | 58b27c2a578d2748e5119df75aac4631b6513c2517305fcabdc9eeee122469d5 |
Close
Hashes for terminable-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29806bbc7c3ebc752970f09f99f1c4427575f4f6454cbf4016cd9df4080a835e |
|
MD5 | 127e857f978b26cbd5033b366a534b48 |
|
BLAKE2b-256 | cf1a652c6c236af933eb9147858edc6c6f31127db9991a000bc45194d7473059 |