terminput
A library to abstract over various backends that provide input events, such as key presses and mouse clicks. This was mainly created as a common interface to the terminal backends that Ratatui supports.
Many TUI libraries want to support input from multiple backends, but mapping each backend's input structure into a common interface can be tedious. This library aims to provide a uniform interface to these types.
Additionally, we supply methods for parsing and encoding ANSI escape sequences for events.
Usage
Use try_into to convert to and from terminput's event types.
use read;
use io;
use Event;
use ;
Event Matching
Some helpers for matching on events are included. See the
match_event example.
Backends
The following backends are currently supported via separate integration crates:
crossterm-terminput-crosstermtermion-terminput-termiontermwiz-terminput-termwizegui-terminput-egui
The Event struct
provided by this library is an attempt to create a superset of all supported
backend functionality that TUI apps may be interested in.
The following table shows the matrix of supported features:
| crossterm | termion | termwiz | egui | |
|---|---|---|---|---|
| key press | ✓ | ✓ | ✓ | ✓ |
| key release/repeat | ✓ | ✓ | ||
| mouse down | ✓ | ✓ | ✓ | ✓ |
| mouse up | ✓ | ✓ | ✓ | |
| mouse move | ✓ | ✓ | ✓ | |
| mouse drag | ✓ | ✓ | ||
| focus | ✓ | ✓ | ||
| paste | ✓ | ✓ | ✓ | |
| resize | ✓ | ✓ |
Parsing
Use the
Event::parse_from
method to parse an ANSI-encoded sequence of bytes into an event struct. This can
be helpful for usage with
SSH
or other situations where you need to read raw input from something other than a
normal TTY device.
The input parser used here was extracted from crossterm's implementation.
use Event;
Encoding
Input structs can also be encoded into ANSI escape sequences using
Event::encode.
This can be useful if you're
controlling a child pty and
need to send it some encoded input.
use ;
let event = Key;
let mut buf = ;
// Legacy encoding
let written = event.encode;
if let Ok = written
// Kitty encoding
let mut buf = ;
let written = event.encode;
if let Ok = written