Skip to main content

get_terminal_width

Function get_terminal_width 

Source
pub fn get_terminal_width() -> Option<u16>
Expand description

Get the terminal width in columns, or a sensible default.

Returns None if stdout is not a terminal (piped output). Returns the width in character columns when available. Falls back to 100 columns if width cannot be determined.

§Examples

let width = get_terminal_width();
// When not a TTY (doctest), returns None; unwrap_or default ≥ 80
assert!(width.unwrap_or(100) >= 80);