4 releases
new 0.2.2 | Feb 2, 2025 |
---|---|
0.2.1 | Feb 1, 2025 |
0.2.0 | Jan 31, 2025 |
0.1.0 | Dec 23, 2024 |
#214 in Command-line interface
328 downloads per month
Used in prettypretty
155KB
3K
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 80+ built-in commands covers basic needs and
then some. Commands generally are zero-sized. That is, unless they require
string arguments or are designed for dynamic state (and hence prefixed with
Dyn
for dynamic).
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::with_log())?;
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);
Release History
v0.2.2 (2025-02-01)
Fix link to docs.rs.
v0.2.1 (2025-02-01)
- Fix the
fuse!
macro. - Update both
fuse!
andfuse_sgr!
to generate commands that are consistent with all of prettytty's commands other thanDynLink
andDynSetWindowTitle
and hence implement theCopy
,Clone
,Debug
,PartialEq
, andEq
traits. - Update
SetForeground8
,SetBackground8
, and theirDyn
versions to generate shorter ANSI escape sequences for the first 16 colors, which are the 8 ANSI colors and their bright variants.
v0.2 (2025-01-31)
Add zero-sized generic versions for commands that set colors or move cursor.
Keep previous, argument-based versions with Dyn
prefix. Rename other commands
with runtime arguments to also use Dyn
prefix.
Rename sgr!
macro for combining several Sgr
commands into one command to
fuse_sgr!
and introduce the more general fuse!
macro for combining
arbitrary commands into one command.
Add Rust version of progress bar to illustrate API differences from Python version.
v0.1 (2024-12-23)
Initial release.
Copyright 2024-2025 Robert Grimm. The code in this repository has been released as open source under the Apache 2.0 license.
Dependencies
~0–7.5MB
~53K SLoC