cxterminfo

Crates.iocxterminfo
lib.rscxterminfo
version0.2.0
sourcesrc
created_at2021-08-06 17:20:53.417963
updated_at2021-08-06 17:20:53.417963
descriptionTerminfo parser
homepage
repositoryhttps://github.com/BxNiom/cx-terminfo
max_upload_size
id432516
size60,360
BxNiom (BxNiom)

documentation

README

cx-terminfo

WTFPL

cx-terminfo is a (nearly) pure Rust library to parse terminfo files. No other Rust dependencies required.

Usage

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;

Examples

Load default terminfo database

use cxterminfo::terminfo;

fn main() {
    if Ok(info) = terminfo::from_env() {
        // do whatever you want
    }
}

Standard capabilities

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));
    }
}

Extended capabilities

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"));
    }
}

Parameterized strings

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.

Terminal responses

To work with responses, use a sscanf implementation.

License

WTFPL

Commit count: 7

cargo fmt