about summary refs log tree commit diff stats
path: root/crates/termsize/src/lib.rs
blob: 69e7b784edd52d106560079319796d4d18389a54 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#![deny(missing_docs)]
// yt - A fully featured command line YouTube client
//
// Copyright (C) 2025 softprops <d.tangren@gmail.com>
// SPDX-License-Identifier: MIT
//
// This file is part of Yt.
//
// You should have received a copy of the License along with this program.
// If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.

//! Termsize is a tiny crate that provides a simple
//! interface for retrieving the current
//! [terminal interface](http://www.manpagez.com/man/4/tty/) size
//!
//! ```rust
//! extern crate termsize;
//!
//! termsize::get().map(|size| println!("rows {} cols {}", size.rows, size.cols));
//! ```

/// Container for number of rows and columns
#[derive(Debug, Clone, Copy)]
pub struct Size {
    /// number of rows
    pub rows: u16,
    /// number of columns
    pub cols: u16,
}

#[cfg(unix)]
#[path = "nix.rs"]
mod imp;

#[cfg(windows)]
#[path = "win.rs"]
mod imp;

#[cfg(not(any(unix, windows)))]
#[path = "other.rs"]
mod imp;

pub use imp::get;

#[cfg(test)]
mod tests {
    use super::get;
    #[test]
    fn test_get() {
        assert!(get().is_some());
    }
}