Crate term_size [] [src]

System calls for getting the terminal size.

Getting the terminal size is performed using an ioctl command that takes the file handle to the terminal -- which in this case, is stdout -- and populates a structure containing the values.

The size is needed when the user wants the output formatted into columns: the default grid view, or the hybrid grid-details view.

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 :(")
}

Functions

dimensions

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

dimensions_stderr

Query the current processes's error output (stderr) only, in the attempt to dtermine terminal width. If that streams is actually a tty, this function returns its width and height as a number of characters.

dimensions_stdin

Query the current processes's input (stdin) only, in the attempt to dtermine terminal width. If that streams is actually a tty, this function returns its width and height as a number of characters.

dimensions_stdout

Query the current processes's output (stdout) only, in the attempt to dtermine terminal width. If that streams is actually a tty, this function returns its width and height as a number of characters.