pub struct Database { /* private fields */ }
Expand description
A capability database.
Implementations§
source§impl Database
impl Database
sourcepub fn from_env() -> Result<Self>
pub fn from_env() -> Result<Self>
Load a database from the current environment.
Examples found in repository?
examples/set_attributes.rs (line 5)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
fn main() {
let info = Database::from_env().unwrap();
if let Some(set_attributes) = info.get::<cap::SetAttributes>() {
let clear = info.get::<cap::ExitAttributeMode>().unwrap();
set_attributes.expand().bold(true).underline(true).to(io::stdout()).unwrap();
println!("bold and underline");
clear.expand().to(io::stdout()).unwrap();
} else {
println!("The terminal does not support mass-setting attributes");
}
}
More examples
examples/simple.rs (line 5)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
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();
}
sourcepub fn from_buffer<T: AsRef<[u8]>>(buffer: T) -> Result<Self>
pub fn from_buffer<T: AsRef<[u8]>>(buffer: T) -> Result<Self>
Load a database from a buffer.
sourcepub fn description(&self) -> &str
pub fn description(&self) -> &str
The terminal description.
sourcepub fn get<'a, C: Capability<'a>>(&'a self) -> Option<C>
pub fn get<'a, C: Capability<'a>>(&'a self) -> Option<C>
Get a capability.
§Example
use terminfo::{Database, capability as cap};
let info = Database::from_env().unwrap();
let colors: i32 = info.get::<cap::MaxColors>().unwrap().into();
Examples found in repository?
examples/set_attributes.rs (line 7)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
fn main() {
let info = Database::from_env().unwrap();
if let Some(set_attributes) = info.get::<cap::SetAttributes>() {
let clear = info.get::<cap::ExitAttributeMode>().unwrap();
set_attributes.expand().bold(true).underline(true).to(io::stdout()).unwrap();
println!("bold and underline");
clear.expand().to(io::stdout()).unwrap();
} else {
println!("The terminal does not support mass-setting attributes");
}
}
More examples
examples/simple.rs (line 7)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
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();
}
Trait Implementations§
source§impl PartialEq for Database
impl PartialEq for Database
impl Eq for Database
impl StructuralPartialEq for Database
Auto Trait Implementations§
impl Freeze for Database
impl RefUnwindSafe for Database
impl Send for Database
impl Sync for Database
impl Unpin for Database
impl UnwindSafe for Database
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more