Crates.io | cxterminfo |
lib.rs | cxterminfo |
version | 0.2.0 |
source | src |
created_at | 2021-08-06 17:20:53.417963 |
updated_at | 2021-08-06 17:20:53.417963 |
description | Terminfo parser |
homepage | |
repository | https://github.com/BxNiom/cx-terminfo |
max_upload_size | |
id | 432516 |
size | 60,360 |
cx-terminfo is a (nearly) pure Rust library to parse terminfo files. No other Rust dependencies required.
Add this to your 'Cargo.toml':
[dependencies]
cxterminfo = "*"
or
[dependencies]
cxterminfo = { git = "https://github.com/bxinom/cx-terminfo" }
and this to your crate root:
extern crate cxterminfo;
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:
use cxterminfo::terminfo;
use cxterminfo::capabilities::{BoolCapability, NumberCapability, StringCapability};
fn main() {
if Ok(info) = terminfo::from_env() {
println!("{:?}", info.get_bool(BoolCapability::AutoLeftMargin));
println!("{:?}", info.get_number(NumberCapability::MaxColors));
println!("{:?}", info.get_string(StringCapability::Bell));
}
}
use cxterminfo::terminfo;
fn main() {
if Ok(info) = terminfo::from_env() {
println!("{:?}", info.get_ext_bool("AT"));
println!("{:?}", info.get_ext_number("IDENT"));
println!("{:?}", info.get_ext_string("XM"));
}
}
use cxterminfo::param_string::{evaluate, Param};
fn main() {
// Move cursor to location 10, 10
let param_str = "\x1B[%d;%dH";
if let Ok(move_cursor) = evaluate(param_str, &[Param::Number(10), Param::Number(10)]) {
println!("{:?}", move_cursor);
}
}
See also terminfo(4) - Section 1-2 for more information about parameterized strings.
To work with responses, use a sscanf implementation.