Function viuer::terminal_size [−][src]
pub fn terminal_size() -> (u16, u16)
Expand description
Try to get the terminal size. If unsuccessful, fallback to a default (80x24).
Uses crossterm::terminal::size.
Example
The example below prints “img.jpg” with dimensions 80x40 in the center of the terminal.
use viuer::{Config, print_from_file, terminal_size};
let (term_width, term_height) = terminal_size();
// Set desired image dimensions
let width = 80;
let height = 40;
let config = Config {
x: (term_width - width) / 2,
y: (term_height - height) as i16 / 2,
width: Some(width as u32),
height: Some(height as u32),
..Default::default()
};
print_from_file("img.jpg", &config).expect("Image printing failed.");