Struct Desc

Source
pub struct Desc { /* private fields */ }
Expand description

The names and capabilities that make up a terminal description.

Predefined capabilities are read by indexing a Desc object with a Boolean, Number, or String capability name. For example, desc[bw] returns a bool, desc[cols] returns a u16, and &desc[setaf] returns a &[u8]. User-defined capabilities are queried using the get_*_ext() methods.

An absent capability will be false, 0xffff, or an empty slice, for booleans, numbers, and strings respectively.

The desc! macro provides syntax for Desc literals.

§Examples

Read the description for xterm-256color and look up the rs1 capability:

use tinf::Desc;
use tinf::cap::rs1;

let mut file = Desc::file("xterm-256color")?;
let desc = Desc::parse(&mut file)?;
assert_eq!(&desc[rs1], b"\x1bc\x1b]104\x07");

Implementations§

Source§

impl Desc

Source

pub fn file(term_name: &str) -> Result<File, DescError>

Finds and opens the compiled terminfo description for the terminal named by term_name.

This assumes that the local terminfo database uses a directory tree format for storing compiled descriptions, and it searches in these directories:

  1. The directory named by the TERMINFO environment variable.
  2. $HOME/.terminfo
  3. The list of directories named by the TERMINFO_DIRS environment variable (with empty entries replaced by /usr/share/terminfo).
  4. /etc/terminfo
  5. /lib/terminfo
  6. /usr/share/terminfo

For each directory, file checks for a description named term_name in a subdirectory named by the first letter of term_name as a character or hex representation, for example /x/xterm or /78/xterm. (Note that if term_name has more than one path component, only the last one is used).

#Errors

This returns an error if file could not find and open a description for term_name, or if term_name is invalid.

Source

pub fn parse(r: &mut dyn Read) -> Result<Desc, DescError>

Creates a Desc from a compiled terminfo description.

§Errors

This returns an error if the input is not a valid terminfo description.

Source

pub fn current() -> &'static Desc

The description for the terminal type from the TERM environment variable, or the “dumb terminal” description if TERM is empty.

Examples found in repository?
examples/dumpinfo.rs (line 6)
5fn main() {
6    let desc = Desc::current();
7    let names = desc.names();
8    if names.len() > 0 {
9        println!("{}", names[0]);
10    }
11    for b in cap::Boolean::iter() {
12        if desc[b] {
13            println!("{}", b.short_name());
14        }
15    }
16    for b in desc.bool_exts() {
17        if desc.get_bool_ext(b) {
18            println!("* {}", b.name());
19        }
20    }
21    for n in cap::Number::iter() {
22        if desc[n] != 0xffff {
23            println!("{}#{}", n.short_name(), desc[n]);
24        }
25    }
26    for n in desc.num_exts() {
27        if desc.get_num_ext(n) != 0xffff {
28            println!("* {}#{}", n.name(), desc.get_num_ext(n));
29        }
30    }
31    for s in cap::String::iter() {
32        if &desc[s] != b"" {
33            println!("{}={}", s.short_name(), show(&desc[s]));
34        }
35    }
36    for s in desc.str_exts() {
37        if desc.get_str_ext(s) != b"" {
38            println!("* {}={}", s.name(), show(desc.get_str_ext(s)));
39        }
40    }
41}
Source

pub fn names(&self) -> &[String]

The terminal’s names.

Examples found in repository?
examples/dumpinfo.rs (line 7)
5fn main() {
6    let desc = Desc::current();
7    let names = desc.names();
8    if names.len() > 0 {
9        println!("{}", names[0]);
10    }
11    for b in cap::Boolean::iter() {
12        if desc[b] {
13            println!("{}", b.short_name());
14        }
15    }
16    for b in desc.bool_exts() {
17        if desc.get_bool_ext(b) {
18            println!("* {}", b.name());
19        }
20    }
21    for n in cap::Number::iter() {
22        if desc[n] != 0xffff {
23            println!("{}#{}", n.short_name(), desc[n]);
24        }
25    }
26    for n in desc.num_exts() {
27        if desc.get_num_ext(n) != 0xffff {
28            println!("* {}#{}", n.name(), desc.get_num_ext(n));
29        }
30    }
31    for s in cap::String::iter() {
32        if &desc[s] != b"" {
33            println!("{}={}", s.short_name(), show(&desc[s]));
34        }
35    }
36    for s in desc.str_exts() {
37        if desc.get_str_ext(s) != b"" {
38            println!("* {}={}", s.name(), show(desc.get_str_ext(s)));
39        }
40    }
41}
Source

pub fn get_bool_ext(&self, name: &UserDef) -> bool

Query a user-defined boolean capability.

If the capability is absent, returns false.

Examples found in repository?
examples/dumpinfo.rs (line 17)
5fn main() {
6    let desc = Desc::current();
7    let names = desc.names();
8    if names.len() > 0 {
9        println!("{}", names[0]);
10    }
11    for b in cap::Boolean::iter() {
12        if desc[b] {
13            println!("{}", b.short_name());
14        }
15    }
16    for b in desc.bool_exts() {
17        if desc.get_bool_ext(b) {
18            println!("* {}", b.name());
19        }
20    }
21    for n in cap::Number::iter() {
22        if desc[n] != 0xffff {
23            println!("{}#{}", n.short_name(), desc[n]);
24        }
25    }
26    for n in desc.num_exts() {
27        if desc.get_num_ext(n) != 0xffff {
28            println!("* {}#{}", n.name(), desc.get_num_ext(n));
29        }
30    }
31    for s in cap::String::iter() {
32        if &desc[s] != b"" {
33            println!("{}={}", s.short_name(), show(&desc[s]));
34        }
35    }
36    for s in desc.str_exts() {
37        if desc.get_str_ext(s) != b"" {
38            println!("* {}={}", s.name(), show(desc.get_str_ext(s)));
39        }
40    }
41}
Source

pub fn bool_exts(&self) -> Vec<&UserDef>

List the names of any user-defined boolean capabilities.

Examples found in repository?
examples/dumpinfo.rs (line 16)
5fn main() {
6    let desc = Desc::current();
7    let names = desc.names();
8    if names.len() > 0 {
9        println!("{}", names[0]);
10    }
11    for b in cap::Boolean::iter() {
12        if desc[b] {
13            println!("{}", b.short_name());
14        }
15    }
16    for b in desc.bool_exts() {
17        if desc.get_bool_ext(b) {
18            println!("* {}", b.name());
19        }
20    }
21    for n in cap::Number::iter() {
22        if desc[n] != 0xffff {
23            println!("{}#{}", n.short_name(), desc[n]);
24        }
25    }
26    for n in desc.num_exts() {
27        if desc.get_num_ext(n) != 0xffff {
28            println!("* {}#{}", n.name(), desc.get_num_ext(n));
29        }
30    }
31    for s in cap::String::iter() {
32        if &desc[s] != b"" {
33            println!("{}={}", s.short_name(), show(&desc[s]));
34        }
35    }
36    for s in desc.str_exts() {
37        if desc.get_str_ext(s) != b"" {
38            println!("* {}={}", s.name(), show(desc.get_str_ext(s)));
39        }
40    }
41}
Source

pub fn get_num_ext(&self, name: &UserDef) -> u16

Query a user-defined numeric capability.

If the capability is absent, returns 0xffff.

Examples found in repository?
examples/dumpinfo.rs (line 27)
5fn main() {
6    let desc = Desc::current();
7    let names = desc.names();
8    if names.len() > 0 {
9        println!("{}", names[0]);
10    }
11    for b in cap::Boolean::iter() {
12        if desc[b] {
13            println!("{}", b.short_name());
14        }
15    }
16    for b in desc.bool_exts() {
17        if desc.get_bool_ext(b) {
18            println!("* {}", b.name());
19        }
20    }
21    for n in cap::Number::iter() {
22        if desc[n] != 0xffff {
23            println!("{}#{}", n.short_name(), desc[n]);
24        }
25    }
26    for n in desc.num_exts() {
27        if desc.get_num_ext(n) != 0xffff {
28            println!("* {}#{}", n.name(), desc.get_num_ext(n));
29        }
30    }
31    for s in cap::String::iter() {
32        if &desc[s] != b"" {
33            println!("{}={}", s.short_name(), show(&desc[s]));
34        }
35    }
36    for s in desc.str_exts() {
37        if desc.get_str_ext(s) != b"" {
38            println!("* {}={}", s.name(), show(desc.get_str_ext(s)));
39        }
40    }
41}
Source

pub fn num_exts(&self) -> Vec<&UserDef>

List the names of any user-defined numeric capabilities.

Examples found in repository?
examples/dumpinfo.rs (line 26)
5fn main() {
6    let desc = Desc::current();
7    let names = desc.names();
8    if names.len() > 0 {
9        println!("{}", names[0]);
10    }
11    for b in cap::Boolean::iter() {
12        if desc[b] {
13            println!("{}", b.short_name());
14        }
15    }
16    for b in desc.bool_exts() {
17        if desc.get_bool_ext(b) {
18            println!("* {}", b.name());
19        }
20    }
21    for n in cap::Number::iter() {
22        if desc[n] != 0xffff {
23            println!("{}#{}", n.short_name(), desc[n]);
24        }
25    }
26    for n in desc.num_exts() {
27        if desc.get_num_ext(n) != 0xffff {
28            println!("* {}#{}", n.name(), desc.get_num_ext(n));
29        }
30    }
31    for s in cap::String::iter() {
32        if &desc[s] != b"" {
33            println!("{}={}", s.short_name(), show(&desc[s]));
34        }
35    }
36    for s in desc.str_exts() {
37        if desc.get_str_ext(s) != b"" {
38            println!("* {}={}", s.name(), show(desc.get_str_ext(s)));
39        }
40    }
41}
Source

pub fn get_str_ext(&self, name: &UserDef) -> &[u8]

Query a user-defined string capability.

If the capability is absent, returns an empty slice.

Examples found in repository?
examples/dumpinfo.rs (line 37)
5fn main() {
6    let desc = Desc::current();
7    let names = desc.names();
8    if names.len() > 0 {
9        println!("{}", names[0]);
10    }
11    for b in cap::Boolean::iter() {
12        if desc[b] {
13            println!("{}", b.short_name());
14        }
15    }
16    for b in desc.bool_exts() {
17        if desc.get_bool_ext(b) {
18            println!("* {}", b.name());
19        }
20    }
21    for n in cap::Number::iter() {
22        if desc[n] != 0xffff {
23            println!("{}#{}", n.short_name(), desc[n]);
24        }
25    }
26    for n in desc.num_exts() {
27        if desc.get_num_ext(n) != 0xffff {
28            println!("* {}#{}", n.name(), desc.get_num_ext(n));
29        }
30    }
31    for s in cap::String::iter() {
32        if &desc[s] != b"" {
33            println!("{}={}", s.short_name(), show(&desc[s]));
34        }
35    }
36    for s in desc.str_exts() {
37        if desc.get_str_ext(s) != b"" {
38            println!("* {}={}", s.name(), show(desc.get_str_ext(s)));
39        }
40    }
41}
Source

pub fn str_exts(&self) -> Vec<&UserDef>

List the names of any user-defined string capabilities.

Examples found in repository?
examples/dumpinfo.rs (line 36)
5fn main() {
6    let desc = Desc::current();
7    let names = desc.names();
8    if names.len() > 0 {
9        println!("{}", names[0]);
10    }
11    for b in cap::Boolean::iter() {
12        if desc[b] {
13            println!("{}", b.short_name());
14        }
15    }
16    for b in desc.bool_exts() {
17        if desc.get_bool_ext(b) {
18            println!("* {}", b.name());
19        }
20    }
21    for n in cap::Number::iter() {
22        if desc[n] != 0xffff {
23            println!("{}#{}", n.short_name(), desc[n]);
24        }
25    }
26    for n in desc.num_exts() {
27        if desc.get_num_ext(n) != 0xffff {
28            println!("* {}#{}", n.name(), desc.get_num_ext(n));
29        }
30    }
31    for s in cap::String::iter() {
32        if &desc[s] != b"" {
33            println!("{}={}", s.short_name(), show(&desc[s]));
34        }
35    }
36    for s in desc.str_exts() {
37        if desc.get_str_ext(s) != b"" {
38            println!("* {}={}", s.name(), show(desc.get_str_ext(s)));
39        }
40    }
41}

Trait Implementations§

Source§

impl Clone for Desc

Source§

fn clone(&self) -> Desc

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Desc

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Index<Boolean> for Desc

Source§

fn index(&self, idx: Boolean) -> &bool

The value of the boolean capability named by index.

Source§

type Output = bool

The returned type after indexing.
Source§

impl Index<Number> for Desc

Source§

fn index(&self, idx: Number) -> &u16

The value of the numeric capability named by index.

Source§

type Output = u16

The returned type after indexing.
Source§

impl Index<String> for Desc

Source§

fn index(&self, idx: String) -> &[u8]

The value of the string capability named by index.

Source§

type Output = [u8]

The returned type after indexing.

Auto Trait Implementations§

§

impl Freeze for Desc

§

impl RefUnwindSafe for Desc

§

impl Send for Desc

§

impl Sync for Desc

§

impl Unpin for Desc

§

impl UnwindSafe for Desc

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.