[][src]Function term_size::dimensions

pub fn dimensions() -> Option<(usize, usize)>

Query the current processes's output (stdout), input (stdin), and error (stderr) in that order, in the attempt to determine terminal width. If one of those streams is actually a tty, this function returns its width and height as a number of characters.

Errors

If all of the streams are not ttys or return any errors this function will return None.

Example

To get the dimensions of your terminal window, simply use the following:

if let Some((w, h)) = term_size::dimensions() {
    println!("Width: {}\nHeight: {}", w, h);
} else {
    println!("Unable to get term size :(")
}