Skip to main content

jt_consoleutils/
terminal.rs

1use terminal_size::{Width, terminal_size};
2
3/// Returns the current terminal width in columns, or 80 if it cannot be determined.
4pub fn terminal_width() -> usize {
5   terminal_size().map(|(Width(w), _)| w as usize).unwrap_or(80)
6}
7
8#[cfg(test)]
9mod tests {
10   use super::*;
11
12   #[test]
13   fn terminal_width_returns_positive() {
14      assert!(terminal_width() > 0);
15   }
16}