Crates.io | terminfo |
lib.rs | terminfo |
version | 0.9.0 |
source | src |
created_at | 2016-12-25 14:06:42.91506 |
updated_at | 2024-05-08 13:44:46.919814 |
description | Terminal information. |
homepage | |
repository | https://github.com/meh/rust-terminfo |
max_upload_size | |
id | 7767 |
size | 177,898 |
Terminal capabilities with type-safe getters.
use std::io;
use terminfo::{capability as cap, Database};
fn main() {
let info = Database::from_env().unwrap();
if let Some(cap::MaxColors(n)) = info.get::<cap::MaxColors>() {
println!("The terminal supports {} colors.", n);
} else {
println!("The terminal does not support colors, what year is this?");
}
if let Some(flash) = info.get::<cap::FlashScreen>() {
flash.expand().to(io::stdout()).unwrap();
} else {
println!("FLASH GORDON!");
}
info.get::<cap::SetAForeground>().unwrap().expand().color(2).to(io::stdout()).unwrap();
info.get::<cap::SetABackground>().unwrap().expand().color(4).to(io::stdout()).unwrap();
println!("SUP");
info.get::<cap::ExitAttributeMode>().unwrap().expand().to(io::stdout()).unwrap();
}
For all terminals but windows consoles, this library depends on a non-hashed (for now) terminfo database being present. For example, on Debian derivitives, you should depend on ncurses-term; on Arch Linux, you depend on ncurses; and on MinGW, you should depend on mingw32-terminfo.
Unfortunately, if you're using a non-windows console on Windows (e.g. MinGW, Cygwin, Git Bash), you'll need to set the TERMINFO environment variable to point to the directory containing the terminfo database.