Debian Codegraph @

debian/rust-vendor/terminal_size/src/lib.rs

raw
1 //! A simple utility for getting the size of a terminal.
2 //!
3 //! Works on Linux, macOS, Windows, and illumos.
4 //!
5 //! This crate requires a minimum Rust version of 1.71.0 (2023-07-13).
6 //!
7 //! # Example
8 //!
9 //! ```
10 //! use terminal_size::{Width, Height, terminal_size};
11 //!
12 //! let size = terminal_size();
13 //! if let Some((Width(w), Height(h))) = size {
14 //! println!("Your terminal is {} cols wide and {} lines tall", w, h);
15 //! } else {
16 //! println!("Unable to get terminal size");
17 //! }
18 //! ```
19 //!
20
21 #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
22 pub struct Width(pub u16);
23 #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
24 pub struct Height(pub u16);
25
26 #[cfg(unix)]
27 mod unix;
28 #[cfg(unix)]
29 #[allow(deprecated)]
30 pub use crate::unix::{terminal_size, terminal_size_of, terminal_size_using_fd};
31
32 #[cfg(windows)]
33 mod windows;
34 #[cfg(windows)]
35 #[allow(deprecated)]
36 pub use crate::windows::{terminal_size, terminal_size_of, terminal_size_using_handle};
37
38 #[cfg(not(any(unix, windows)))]
39 pub fn terminal_size() -> Option<(Width, Height)> {
40 None
41 }