0.2.1 |
|
---|---|
0.2.0 |
|
0.1.1 |
|
#17 in #vte
81KB
2K
SLoC
Status
Still early but we can already extract most of the sequences. Device input has handy shortcuts for extracting some sense from the madness of ANSI keyboard and mouse.
While termit-ansi is part of a higher termit take over plot, this little fellow is meant to be usefull also on iny embedded devices where you would not go into tokio and async processing luxury.
Goals: [x] Portable. Since we touch no IO and only depend on core. [x] Be no_std by default - there's no allocator needed, only depending on core. [x] Handle both device and host sequences with the same approach. [x] Comprehensive device input coverage of user keys and mouse events with easy to use API. [ ] Easy to use API for host output, similar to device input. [ ] Well covered with tests, hard and stable API. [x] Nightly Rust, no special features. [x] Stable Rust, no special features.
Installation
Add this to your Cargo.toml
:
[dependencies]
termit-ansi = "0"
Note that the API is still unstable. Please use the latest release.
Usage
Look at the examples folder, specifically vt.rs and ansi.rs
You can either work with the parser which takes care of the stream
for you: AnsiParser
, AnsiDeviceParser
, AnsiHostParser
.
That's the easy termit ride.
For more control, you can employ the state machines directly:
AnsiMachine
, SequenceMachine
, Utf8Machine
, and give handle
the stream yourself.
Parsers
You'll initiate the parser with it's internal buffer. That's important because since there is no allocation, the parser would not be able to make it dynamically. It would have to use a fixed size one that would fit selected few.
You'll also need to implement a handler for the specific parser. It's not too tough. One method will do.
Then call parser.parse(handler, input)
with any new data coming in.
When your parsing is done, call parser.close()
and inspect the remaining data.
The parsers sometimes pass references to data in their buffers as part of the
handler call. This is to avoid allocation. You're either fine with that,
or need to copy the &str
and &[u8]
bits into some allocated space,
including forming new structures to hold that. The later is the task of
termit-io
which will abstract from the ANSI madness and present some solid model.