1 unstable release
0.1.0 | Dec 23, 2024 |
---|
#242 in Command-line interface
117 downloads per month
135KB
2.5K
SLoC
Pretty 🌸 Tty
[ Docs.rs | GitHub Pages | Rust Crate | Repository ]
Prettytty is a lightweight and flexible terminal library for Rust that has
only one low-level dependency, i.e., libc
on
Unix and windows-sys
on Windows. Its
API is clean and simple: Open a Connection
to the terminal and share it
across threads as needed. Write Command
s to Output
. Read Query
responses from Input
. Scan::read_token
takes care of low-level UTF-8 and
ANSI escape sequence decoding and Query::parse
turns token payloads into
objects. A cmd
library with 70+ built-in commands covers basic needs and
then some.
Example
Here's how the above mentioned abstractions are used in practice:
use prettytty::{Connection, Query, Scan};
use prettytty::cmd::{MoveToColumn, RequestCursorPosition};
use prettytty::opt::Options;
// Open a terminal connection with 1s timeout.
let tty = Connection::with_options(
Options::builder().timeout(10).build())?;
let pos = {
let (mut input, mut output) = tty.io();
// Move cursor, issue query for position.
output.exec(MoveToColumn(17))?;
output.exec(RequestCursorPosition)?;
// Read and parse response.
let response = input.read_sequence(
RequestCursorPosition.control())?;
RequestCursorPosition.parse(response)?
};
assert_eq!(pos.1, 17);
Copyright 2024 Robert Grimm. The code in this repository has been released as open source under the Apache 2.0 license.
Dependencies
~0–7.5MB
~55K SLoC