cx-terminfo is a (nearly) pure Rust library to parse terminfo files. No other Rust dependencies required.
Add this to your 'Cargo.toml':
toml
[dependencies]
cxterminfo = "*"
or
toml
[dependencies]
cxterminfo = { git = "https://github.com/bxinom/cx-terminfo" }
and this to your crate root:
rust
extern crate cxterminfo;
```rust use cxterminfo::terminfo;
fn main() { if Ok(info) = terminfo::from_env() { // do whatever you want } } ```
cx-terminfo got three enums for capabilities (each value has documentation):
cxterminfo::capabilities::BoolCapability // known bool capabilities
cxterminfo::capabilities::NumberCapability // known number capabilities
cxterminfo::capabilities::StringCapability // known string capabilities
Howto get capability values:
```rust use cxterminfo::terminfo; use cxterminfo::capabilities::{BoolCapability, NumberCapability, StringCapability};
fn main() { if Ok(info) = terminfo::fromenv() { println!("{:?}", info.getbool(BoolCapability::AutoLeftMargin)); println!("{:?}", info.getnumber(NumberCapability::MaxColors)); println!("{:?}", info.getstring(StringCapability::Bell)); } } ```
```rust use cxterminfo::terminfo;
fn main() { if Ok(info) = terminfo::fromenv() { println!("{:?}", info.getextbool("AT")); println!("{:?}", info.getextnumber("IDENT")); println!("{:?}", info.getext_string("XM")); } } ```
```rust use cxterminfo::param_string::{evaluate, Param};
fn main() { // Move cursor to location 10, 10 let paramstr = "\x1B[%d;%dH"; if let Ok(movecursor) = evaluate(paramstr, &[Param::Number(10), Param::Number(10)]) { println!("{:?}", movecursor); } } ```
See also terminfo(4) - Section 1-2 for more information about parameterized strings.
To work with responses, use a sscanf implementation.